You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Behrang Saeedzadeh <be...@gmail.com> on 2006/12/26 12:15:10 UTC
A use-case implementation question
Hi,
Suppose that I have a use case in which I have to develop a UI with JSF, and
without Seam or Shale, for the following task:
We have a bunch of roles and positions. Each position may have one or more
roles. Design a UI for assigning roles to a selected position. Use a
selectManyListBox for selecting the roles to be assigned to the user.
The roles and positions are stored in a backend database and their count
might change over time.
Ideally, I would use a request-soped bean with such an interface to implement
my case:
public interface IRoleAssignmentBean {
setSelectedPosition(Position aPosition);
Position getSelectedPosition();
List<Role> getCurrentAssignedRoles(); // fetches from DB
List<SelectItem> getAllRoleItems(); // fetches from DB
void assignedRolesChanged(ValueChangeEvent vce); // updates the DB
}
The getCurrentAssignedRoles and getAllRoleItems fetch the items from database.
getCurrentAssignedRoles, for example, has an implementation like this;
List<Role> getCurrentAssignedRoles() {
if (getSelectedPosition == null) {
throw new RuntimeException("blah blah");
}
if (currentAssignedRoles == null) {
currentAssignedRoles =
roleDao.findCurrentAssignedRoles(getSelectedPosition());
}
return currentAssignedRoles;
}
(Question: how would you implement this getter?)
Then in my JSF page, I would like to have:
<h:selectOneCheckBox value="#{RoleAssignmentBean.currentAssignedRoles}"
valueChangeListener="#{RoleAssignmentBean.assignedRolesChanged}">
<f:selectItems value="#{RoleAssignmentBean.allRoleItems}" />
</h:selectOneCheckBox>
But this ain't gonna work as I don't have the setCurrentAssignedRoles method.
I can add the setter to my bean, but then this makes the currentAssignedRoles
property ambiguos: sometimes it contains the roles that are currently stored
in the database, sometimes it contains the roles submitted by the user.
I could use a custom component like this:
<custom:selectOneCheckBox
value="#{RoleAssignmentBean.currentAssignedRoles}"
submittedValue="#{RoleAssignmentBean.submittedAssignedRoles}"
valueChangeListener="#{RoleAssignmentBean.assignedRolesChanged}">
<f:selectItems value="#{RoleAssignmentBean.allRoleItems}" />
</custom:selectOneCheckBox>
And add another property, namely submittedAssignedRoles, to
disanbiguate the case.
But I think that there should be something that I don't know. I mean this is a
very common use case and it should be possible to implement it by using the
standard components, and at the same time with a clean and well-designed
backing bean.
If my approach is not correct, could someone give me some advice on
what the correct approach would be?
Regards,
Behi
--
"Science is a differential equation. Religion is a boundary condition"
- Alan Turing
Behrang Saeedzadeh
http://www.jroller.com/page/behrangsa
http://my.opera.com/behrangsa