1 Reply Latest reply on Apr 16, 2009 7:25 AM by Brendan Farragher

    Possible to use SelectOneListbox to refresh PickList data?

    Brendan Farragher Newbie

      Hi. I am trying to do the reverse of the what the picklist example does on the livedemo site. I want to make a selection on a selectonelistbox and have a picklist (left and right sides of it) change it's data on the UI everytime I make a selection.

      I have tried many variations with no luck. Do I need an a4j tag on the picklist to be able to refresh (reRender) it on the UI or something?? Tags and relevant code below. I just included the code snippets that load the lists instead of the entire valuechangelistener method body.

      Thank you for your time.

      Tags:

      <div id="ApplicationRolePickListSection" class="ApplicationRolePickListSection">
      
      <p>Please choose an application for this user and assign user roles</p>
      
      <h:panelGrid styleClass="ApplicationRolePickListGrid" columns="2"
       xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich">
      
      <h:outputText styleClass="ApplicationRolePickListHeadings" value="Choose Application"/>
      
      <h:outputText styleClass="ApplicationRolePickListHeadings" value="Assign Roles"/>
      
      <h:selectOneListbox id="applicationSelectionList" styleClass="ApplicationSelectionList" value="#{applicationRoleManager.selectedApplication}" size="8"
      onchange="submit()"
      valueChangeListener="#applicationRoleManager.loadRoleComponentsForApplicationSelection}"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:s="http://jboss.com/products/seam/taglib"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.ajax4jsf.org/rich">
      <f:selectItems id="applicationList" value="#{applicationRoleManager.applications}"/>
      </h:selectOneListbox>
      
      <rich:pickList id="rolePicklist" styleClass="RolePicklist"
      value="#{applicationRoleManager.assignedRoles}"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:s="http://jboss.com/products/seam/taglib"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.ajax4jsf.org/rich">
      <f:selectItems id="assignedRoles" value="#{applicationRoleManager.availableRoles}"/>
      </rich:pickList>
      
      </h:panelGrid>
      
      </div>
      


      Code:

      @Out(required=false)
      private List<SelectItem> availableRoles;
      
      @Out(required=false)
      private List<String> assignedRoles;
      
      ...
      
      for(SsoRole ssoRole:applicationRoleList)
      {
      availableRoles.add(new SelectItem(ssoRole.getRoleId().toString(), ssoRole.getName()));
      }
      
      ...
      
      for(SsoRole ssoRole:userRoleList)
      {
      logger.debug("*** LOADING ASSIGNED ROLE ID " + ssoRole.getRoleId().toString());
      
      assignedRoles.add(new String(ssoRole.getRoleId().toString()));
      }
      
      ...
      


        • 1. Re: Possible to use SelectOneListbox to refresh PickList dat
          Brendan Farragher Newbie

          Just some additional information - if I hard code some values to initialize availableRoles and assignedRoles, then the lists are displayed correctly in the pickList the first time that the page loads. But when I make a selection from the selectonelistbox, the valuechangelistener method fires, loads the two lists with data from the DB, but the picklist is not refreshed with the new data on the UI. In fact, the picklist data gets wiped out in the assignedRoles list. If I select a different item from the applications list, the data gets wiped out in the availableRoles list...

          I am using Seam v2.1, which I believe has RichFaces 3.2.2 packaged with it (according to MANIFEST.MF)

          Any insight on how to do this would be greatly appreciated.

          Thanks again.