-
FEATURED COMPONENTS
First time here? Check out the FAQ!
My doubt is not at all related to ZK but i feel this is good place for me to get reply soon.
Scenario :
Assume ,Assign or De Assign multiple roles to single employee by checking or un checking check boxes with single save button.when user clicks on save button if new roles assigned those will be inserted ,if roles De assigned those records will be deleted from table.
we can do it by two ways
1)when users clicks on save button first delete all records related to employee Id then insert all
2)first fetch list of assigned roles before change (A), select list of assigned roles after changes(B) .Take all roles in loop and check two list for insert or delete .if role Id is in A and not in B then insert.if role Id in B not in A delete .
In the first scenario we have to delete all and again insert all even we assigned or De assign a single role ,like in second scenario we have iterate through all roles list size and every time we have compare for each role Id to check whether it is in two lists A and B
Question :
In these two ways which is faster ,suggestible and professional
Hi ommpavan,
I assume you can already achieve this but are only looking for a general opinion on the best practice. I have previously used the first way of clearing all employee related roles and re-inserting latest assignments. Then again this was well abstracted by Hinernate @OneToMany mapping. Once setup your roles should be available as a collection within your Employee entity. when you get Emplyee entity from database you get all previously assigned roles in a collection. After assigning/un-assigning roles you can clear the original collection of roles, assign a new one and persist. Hibernate would take care of efficiency of inserting/deletion of newly assigned/un-assigned roles for you and you need not bother to do it in your application code yourself.
Let us know if you need more help on this.
I'll pick the first approach if the requirement is simple, this action is not a frequently happened action and there are not too many roles for single user.
the different between this two impl at UI part is: if you picked the first approach, every time you click the save btn, you need to re-render the entire UserRoleGrid, so if you have some "view state" that need to be maintained such as current page index, selecteItem or opened Detail of a Row, then first solution will gives you headache to re-council the UI state.
I'll suggest you pick the first one if there's no such view state problem that I mentioned (because the impl of the first solution is simple), and waiting for using the second solution if new requirements break the original assumptions.
Asked: 2011-08-17 01:49:50 +0800
Seen: 910 times
Last updated: Aug 24 '11