4 Replies Latest reply on Dec 11, 2008 8:04 AM by ramki dirisala

    listshuttle has invalid value expression

    ramki dirisala Novice

      hi,
      <rich:listShuttle> component throwing the following errors

      listshuttle has invalid value expression .

      i am using List of CodeValueDTO's as source to the list.

        • 1. Re: listshuttle has invalid value expression
          Ilya Shaikovsky Master

          have you read our limitations in guide for the objects used by list shuttle?

          • 2. Re: listshuttle has invalid value expression
            ramki dirisala Novice

            hi,
            thanks for quick reply. i haven't read the quide. can you please tell me is it posible to use objects for list shuttle.

            • 3. Re: listshuttle has invalid value expression
              Ilya Shaikovsky Master

              yes. but you shoud define converter for your objects and properly override equals and hashCode methods.

              • 4. Re: listshuttle has invalid value expression
                ramki dirisala Novice

                hi,
                i included converter for my objects. below is my code

                dto classs
                ========
                public class CodeValueDTO implements Serializable
                {
                /**
                * serialVersionUID
                */
                private static final long serialVersionUID = 1L;

                private String codeValue;

                private String codeDescription;

                /**
                * getter for codevalue
                * @return String the codeValue
                */
                public String getCodeValue ( )
                {
                return codeValue;
                }

                /**
                * setter for code value
                * @param codeValue the codeValue to set
                */
                public void setCodeValue ( String codeValue )
                {
                this.codeValue = codeValue;
                }

                /**
                * getter for codeDescription
                * @return String the codeDescription
                */
                public String getCodeDescription ( )
                {
                return codeDescription;
                }

                /**
                * setter for codeDescription
                * @param codeDescription the codeDescription to set
                */
                public void setCodeDescription ( String codeDescription )
                {
                this.codeDescription = codeDescription;
                }

                /**
                * Default constructor
                * @param codeValue
                * @param codeDescription
                */
                public CodeValueDTO ( String codeValue, String codeDescription )
                {
                super();
                this.codeValue = codeValue;
                this.codeDescription = codeDescription;
                }

                @Override
                public int hashCode ( )
                {
                final int prime = 31;
                int result = 1;
                result =
                prime * result
                + ((codeDescription == null) ? 0 : codeDescription.hashCode());
                result =
                prime * result + ((codeValue == null) ? 0 : codeValue.hashCode());
                return result;
                }

                @Override
                public boolean equals ( Object obj )
                {
                if ( this == obj )
                return true;
                if ( obj == null )
                return false;
                if ( getClass() != obj.getClass() )
                return false;
                final CodeValueDTO other = ( CodeValueDTO ) obj;
                if ( codeDescription == null )
                {
                if ( other.codeDescription != null )
                return false;
                }
                else if ( !codeDescription.equals( other.codeDescription ) )
                return false;
                if ( codeValue == null )
                {
                if ( other.codeValue != null )
                return false;
                }
                else if ( !codeValue.equals( other.codeValue ) )
                return false;
                return true;
                }
                }
                converter class
                ==========
                public class ListShuttleOptionItemConverter implements Converter
                {
                public Object getAsObject ( FacesContext context, UIComponent component,
                String value )
                {
                int index = value.indexOf( ':' );
                return new CodeValueDTO( value.substring( 0, index ), value
                .substring( index + 1 ) );
                }
                public String getAsString ( FacesContext context, UIComponent component,
                Object value )
                {

                if(value==null)
                return "";

                CodeValueDTO optionItem = ( CodeValueDTO ) value;
                return optionItem.getCodeValue() + ":" + optionItem.getCodeDescription();
                }

                }
                <html xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:c="http://sourceforge.net/projects/jsf-comp">
                <f:view>

                <h:form>
                <a4j:outputPanel ajaxRendered="true">
                <h:messages />
                </a4j:outputPanel>



                <rich:listShuttle
                sourceValue="#{demo.sourceList1}"
                targetValue="#{demo.sourceList2}"
                id="listshuttle"
                var="item"
                converter="#{converter}">

                <rich:column width="18">
                <h:outputText value="#{item.codeValue}"/>
                </rich:column>
                <rich:column>
                <h:outputText value="#{item.codeDescription}"/>
                </rich:column>

                </rich:listShuttle>

                <a4j:commandButton value="List 1" action="#{demo.sourceList2}"
                reRender="listshuttle" />
                <a4j:commandButton value="ok" action="#{demo.ok}"></a4j:commandButton>
                </h:form>
                </f:view>


                ================
                public class Demo implements Cloneable
                {
                private List sourceList1 = new ArrayList();

                private List sourceList2 = new ArrayList();

                public void Demo()
                {

                }

                public void ok()
                {
                System.out.println("testing target list values");
                }

                public Collection getSourceList1 ( )
                {
                if(sourceList1.size()==0)
                {
                for ( int i = 0; i < 2; i++ )
                {
                sourceList1.add(new CodeValueDTO( "Code" + i, "Value" + i ));
                }
                }

                return sourceList1;
                }

                public void setSourceList1 ( List sourceList1 )
                {
                this.sourceList1 = sourceList1;
                }

                public void sourceList2 ( )
                {
                for ( int i = 0; i < 2; i++ )
                {
                sourceList1.add(new CodeValueDTO( "Code_new" + i, "Value_new" + i ));
                }
                }

                public void setSourceList2 ( List sourceList2 )
                {
                this.sourceList2 = sourceList2;
                }

                public Collection getSourceList2 ( )
                {
                return sourceList2;
                }

                }

                please validate above code. am i doing anything wrong.