2 Replies Latest reply on Feb 4, 2009 12:16 PM by archana rao

    List Shuttle - How to capture the updated list

    archana rao Newbie

      Hi,

      I am using ListShuttle in my project. When ever I copy the items from SourceList to TargetLlist or whene ever I move the items with in the targetlist I don't see sourceValue or targetValue getting updated with the updated values. Has anybody using the ListShuttle component? If so could you please let me know how to capture the updated items?

      thank you
      Archana

        • 1. Re: List Shuttle - How to capture the updated list
          Ilya Shaikovsky Master

          This case - fully implemented at richfaces online demo. Link in my signature, and there is also link to sources of the demo.

          • 2. Re: List Shuttle - How to capture the updated list
            archana rao Newbie

            Hi,

            I have implemented my code almost in the same way as the example code. When ever I press 'Ok' button it should print me the updated targetHostNameList and sourceHostNameList. But it always prints the inital list. I am not sure what am I missing in my code? Here is my xhtml code

            <td align="left">
             <rich:listShuttle id="hostNameListId"
             binding="#{ListShuttleBean.hostNameShuttleList}"
             converter="#{ListShuttleBean.convert}"
             sourceValue="#{ListShuttleBean.sourceHostNameList}"
             targetValue="#{ListShuttleBean.targetHostNameList}"
             sourceCaptionLabel="Available Hosts"
             targetCaptionLabel="Active Hosts"
             var="items">
             <rich:column>
             <h:outputText value="#{items.actualName}">
             </h:outputText>
             </rich:column>
             </rich:listShuttle>
             </td>
             <a4j:commandButton value="OK" immediate="true"
             action="#{PitcherQueues.printUpdatedList}" />
            


            I have implemented my ListShuttleBean in the following way

            public class ListShuttleBean{
             private List<HostName> sourceHostNameList = new ArrayList<HostName>();
             private List<HostName> targetSouceNameList = new ArrayList<HostName>();
             private HtmlListShuttle hostNameShuttleList = new HtmlListShuttle();
            
            public ListShuttleBean() {
             HostName host1 = new HostName();
             host1.setName("TargetTest1");
             host1.setActualName("TargetTest1");
             targetSouceNameList .add(host1);
             HostName host2 = new HostName();
             host2.setName("TargetTest2");
             host2.setActualName("TargetTest2");
             targetSouceNameList .add(host2);
             HostName host3 = new HostName();
             host3.setName("TargetTest3");
             host3.setActualName("TargetTest13);
             targetSouceNameList .add(host3);
            
             HostName sourcehost1 = new HostName();
             sourcehost1.setName("SourceTest1");
             sourcehost1.setActualName("SourceTest1");
             sourceHostNameList .add(sourcehost1);
             HostName sourcehost2= new HostName();
             sourcehost2.setName("SourceTest2");
             sourcehost2.setActualName("SourceTest2");
             sourceHostNameList.add(sourcehost2);
             HostName sourcehost3= new HostName();
             sourcehost2.setName("SourceTest3");
             sourcehost2.setActualName("SourceTest3");
             sourceHostNameList.add(sourcehost3);
            }
            
            public void setTargetHostNameList(List<HostName> targetHostNameList){
             this.targetHostNameList = targetHostNameList;
            }
            
            public List<HostName> getTargetHostNameList() {
             return targetHostNameList;
            }
            
            public void setSourceHostNameList(List<HostName> sourceHostNameList){
             this.sourceHostNameList = sourceHostNameList;
            }
            
            public List<HostName> getSourceHostNameList() {
             return sourceHostNameList;
            }
            
            public HtmlListShuttle getHostNameShuttleList() {
             return hostNameShuttleList;
            }
            
            public void setHostNameShuttleList(HtmlListShuttle hostNameShuttleList) {
             this.hostNameShuttleList = hostNameShuttleList;
            }
            
            public void printUpdatedList(){
             log.debug("TaregtHostNameList SIZE = " + targetHostNameList.size());
             for(HostName host : targetHostNameList){
             log.debug("Target HostName = " + host.getName());
             }
             log.debug("SourceHostNameList SIZE = " + sourceHostNameList.size());
             for(HostName host : this.sourceHostNameList){
             log.debug("Source HostName = " + host.getName());
             }
            
            }
            
            public Converter getConvert() {
             return new Converter() {
             public Object getAsObject(FacesContext ontext, UIComponent component, String value){
             if(value.isEmpy()){
             return null;
             }
             int index = value.indexOf(":");
             HostName hostName;
             try {
             hostName = new HostName();
             hostName.setName(value.substring(0, index));
             hostName.setActualName(value.substring(index+1, value.length()));
             }catch (Exception e) {
             System.out.println("INSIDE EXCEPTION");
             return null;
             }
            
             return hostName;
             }
             public String getAsString(FacesContext context, UIComponent component, Object value) {
             return value.toString();
             }
            
             };
            
            }


            Here is my HostName object

            
            public class HostName{
            
             private String name;
             private String actualName;
            
             public HostName() {
            
             }
            
             public String getName(){
             return name;
             }
            
             public void setName(String name) {
             this.name = name;
             }
            
             public String getActualName(){
             return actualName;
             }
            
             public void setActualHostName(String actualName) {
             this.actualName = actualName;
             }
            
             public int hashCode() {
             final int prime = 31;
             int result = 1;
             result = prime * result + ((name == null) ? 0 : name.hashCode());
             return result;
             }
            
             public boolean equals(Object obj) {
             if(this == obj)
             return true;
             if(obj == null)
             return false;
             if(getClass() != obj.getClass())
             return false;
             final HostName other = (HostName) obj;
             if(name == null) {
             if(other.name != null)
             return false;
             }else if(!name.equals(other.name))
             return false;
             if(actualName == null){
             if(other.actualName != null)
             return false;
             }else if(!actualName.equals(other.actualName))
             return false;
            
             return true;
             }