Hi,
Not tested it but it'll be similar to;
TestBean
public class TestBean {
private List<Role> allAvailableRoles;
private List<Role> deviceRoles = new ArrayList<Role>();
String[] selectedRoles;
String[] selectedDeviceRoles;
public List<Role> getAllAvailableRoles(){
return (List<Role>) deviceManager.getUserRoles();
}
public List<Role> getDeviceRoles() {
return deviceRoles;
}
public String[] getSelectedRoles() {
return selectedRoles;
}
public void setSelectedRoles(String[] selectedRoles) {
this.selectedRoles = selectedRoles;
}
public String[] getSelectedDeviceRoles() {
return selectedDeviceRoles;
}
public void setSelectedDeviceRoles(String[] selectedDeviceRoles) {
this.selectedDeviceRoles = selectedDeviceRoles;
}
public String addRole() {
deviceRoles.addAll( selectedRoles );
return null;
}
public String removeRole() {
deviceRoles.removeAll(selectedDeviceRoles);
}
}
Page Fragment;
. . . .
<h:panelGrid columns="4" style="">
<h:outputText value="User Roles" />
<h:selectManyListbox id="userRoles" value="#{test.selectedRoles}">
<t:selectItems value="#{test.allAvailableRoles}"
var="availableRole" itemLabel="#{availabeRole.name}" itemValue="#{
availableRole.id}"/>
</h:selectManyListbox>
<h:commandButton value="Add" action="#{test.addRole
}"></h:commandButton>
<h:commandButton value="Remove" action="#{test.removeRole
}"></h:commandButton>
<h:outputLabel value="Device Roles" />
<h:selectManyListbox>
<t:selectItems value="#{test.deviceRoles}"
var="deviceRole" itemLabel="#{deviceRole.name}" itemValue="#{deviceRole.id
}"/>
</h:selectManyListbox>
</h:panelGrid>
</ajax:outputPanel>
. . . .
Note: t:selectItems is only available Tomahawk snapshots, not released yet.
On 1/13/07, bansi <[EMAIL PROTECTED]> wrote:
I am using JSF (MyFaces 1.1.1) component h:selectManyListBox along with
Ajax4Jsf to add/remove user Roles.
I have created page called page.jsp as follows (need help in filling the
code):
. . . .
<h:panelGrid columns="4" style="">
<h:outputText value="User Roles" />
<h:selectManyListbox id="userRoles" value="#{test.selectedRoles
}">
<f:selectItems value="#{test.allAvailableRoles}"
/>
</h:selectManyListbox>
<h:commandButton value="Add"></h:commandButton>
<h:commandButton value="Remove"></h:commandButton>
<h:outputLabel value="Device Roles" />
<h:selectManyListbox>
</h:selectManyListbox>
</h:panelGrid>
</ajax:outputPanel>
. . . .
It uses managed bean called TestBean.java
public class TestBean {
private List<SelectItem> allAvailableRoles;
String[] selectedRoles;
public List getAllAvailableRoles(){
logger.info(" *** In getAllAvailableRoles Backing Bean*** ");
System.out.println(" *** In getAllAvailableRoles Backing Bean***
");
allAvailableRoles = new ArrayList<SelectItem>();
List<Role> allRoles = new ArrayList<Role>();
allRoles = ( List ) deviceManager.getUserRoles(); //call to
business layer
to retrieve user roles from database
//System.out.println("Role Size"+allRoles.size());
//Iterate All Roles to create a SelectItem and add it to the list that
will
fill the SelectManyListbox
for ( Role role : allRoles ){
SelectItem item = new
SelectItem();
item.setValue( ""+role.getId() );
item.setLabel( role.getName() );
allAvailableRoles.add( item );
}
selectedRoles = (String[])selectedRoles.toArray();
return allAvailableRoles;
}
public String[] getSelectedRoles() {
return selectedRoles;
}
public void setSelectedRoles(String[] selectedRoles) {
this.selectedRoles = selectedRoles;
}
}
I need help with the following:
1) The Layout of JSP page has to render
User Roles (h:selectManyListBox), Add and Remove Buttons, Device
Roles
(h:selectManyListBox) in a single colums. I am using <h:PanelGrid
columns=4> . But i wanna Remove button to display in next row of Add
button
2) I am looking for sample code for adding functionality to Add/Remove
Buttons.
The Add button adds the selected user roles to Device Roles whereas Remove
button removes the selected user roles from Device Roles to User Roles
Thanks for your time in advance
Regards
Bansi
--
View this message in context:
http://www.nabble.com/selectManyListBox-to-add-remove-user-Roles-tf2969171.html#a8308794
Sent from the MyFaces - Users mailing list archive at Nabble.com.