7 Replies Latest reply on Feb 26, 2016 7:55 AM by auston

    listShuttle Error "has invalid value expression"

    tiger86

      Hi

      i have some problem with listShuttle

      i get this error messages

      listShuttle Component mainform:j_id36 has invalid value expression

      when i click on the command button to submit, i am not able to fetch the target value of listShuttle

      actually it didn't call the method it stop to that error

       

      configureStep.xhtml:

      ConfigureStep.java

      public class ConfigureStep extends Step<ConfigureSettingsWizard> {
      
           /* Initial */
           private ConfigurationSettings configurationSettings;
           /* Statistics Live Settings */
           private int period;
           /* Prohibited Professions Settings */
           private List<MySelectItem> prohibitedProfessionsListItem = new ArrayList<MySelectItem>();
           private List<MySelectItem> nonProhibitedProfessionsListItem = new ArrayList<MySelectItem>();
      
           public ConfigureStep(ConfigureSettingsWizard wizard) {
                super(wizard, "form_configure_settings_title");
           }
      
           public void onConfigurationSettings() {
                try {
                     ConfigureSettingsHelper helper = new ConfigureSettingsHelper();
                     if (configurationSettings.equals(ConfigurationSettings.STATISTICS_LIVE_SETTINGS)) {
                          String periodStr = helper.getLiveStatisticsPeriod(Login.getLoggedInUser());
                          if (periodStr != null && !periodStr.equals("")) {
                               period = Integer.parseInt(periodStr);
                          }
                     } else if (configurationSettings.equals(ConfigurationSettings.PROHIBITED_PROFESSIONS_SETTINGS)) {
                          // List of prohibited Profession Codes
                          List<String> prohibitedProfessionCodes = helper.getProhibitedProfessionsList(Login.getLoggedInUser());
                          CodeManagementHelper codeManagementHelper = MasterDataHelper.init();
                          Map<String, String> professions = null;
                          // Map of professions
                          professions = codeManagementHelper.getAllMaleProfession();
                          if (prohibitedProfessionCodes != null) {
                               for (String prohibitedProfessionCode : prohibitedProfessionCodes) {
                                    prohibitedProfessionsListItem.add(new MySelectItem(prohibitedProfessionCode, professions
                                              .get(prohibitedProfessionCode)));
                                    professions.remove(prohibitedProfessionCode);
                               }
                          }
                          if (professions != null) {
                               for (String profession : professions.keySet()) {
                                    nonProhibitedProfessionsListItem.add(new MySelectItem(profession, professions.get(profession)));
                               }
                          }
                     }
                } catch (RPSException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
           }
      
           public ConfigurationSettings getConfigurationSettings() {
                return configurationSettings;
           }
      
           public void setConfigurationSettings(ConfigurationSettings configurationSettings) {
                this.configurationSettings = configurationSettings;
           }
      
           public int getPeriod() {
                return period;
           }
      
           public void setPeriod(int period) {
                this.period = period;
           }
      
           public List<MySelectItem> getProhibitedProfessionsListItem() {
                return prohibitedProfessionsListItem;
           }
      
           public void setProhibitedProfessionsListItem(List<MySelectItem> prohibitedProfessionsListItem) {
                this.prohibitedProfessionsListItem = prohibitedProfessionsListItem;
           }
      
           public List<MySelectItem> getNonProhibitedProfessionsListItem() {
                return nonProhibitedProfessionsListItem;
           }
      
           public void setNonProhibitedProfessionsListItem(List<MySelectItem> nonProhibitedProfessionsListItem) {
                this.nonProhibitedProfessionsListItem = nonProhibitedProfessionsListItem;
           }
      }
      

      ListConverter.java

       

      public class ListConverter implements Converter {
      
           public ListConverter() {
           }
      
           public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
                if (value != null && !value.equals("") && value.contains(":")) {
                     String[] values = value.split(":");
                     String id = values[0].trim();
                     // System.out.println(id);
                     String name = values[1].trim();
                     // System.out.println(name);
      
                     return new MySelectItem(id, name);
                }
                return new MySelectItem();
           }
      
           public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
                if (arg2 != null) {
                     return arg2.toString();
                }
                return null;
           }
      }
      

      MySelectItem.java

      public class MySelectItem implements Serializable {
      
           /** The Constant serialVersionUID. */
           private static final long serialVersionUID = 1L;
      
           /** The value. */
           private String value;
      
           /** The label. */
           private String label;
      
           /** The display order. */
           private int displayOrder;
      
           /**
            * Instantiates a new list item.
            */
           public MySelectItem() {
                super();
           }
      
           /**
            * Instantiates a new list item.
            * 
            * @param value
            *            the value
            */
           public MySelectItem(String value) {
                super();
                this.value = value;
           }
      
           /**
            * Instantiates a new list item.
            * 
            * @param value
            *            the value
            * @param label
            *            the label
            */
           public MySelectItem(String value, String label) {
                super();
                this.value = value;
                this.label = label;
           }
      
           /**
            * Gets the value.
            * 
            * @return the value
            */
           public String getValue() {
                return value;
           }
      
           /**
            * Sets the value.
            * 
            * @param value
            *            the new value
            */
           public void setValue(String value) {
                this.value = value;
           }
      
           /**
            * Gets the label.
            * 
            * @return the label
            */
           public String getLabel() {
                return label;
           }
      
           /**
            * Sets the label.
            * 
            * @param label
            *            the new label
            */
           public void setLabel(String label) {
                this.label = label;
           }
      
           /**
            * @return the displayOrder
            */
           public int getDisplayOrder() {
                return displayOrder;
           }
      
           /**
            * @param displayOrder
            *            the displayOrder to set
            */
           public void setDisplayOrder(int displayOrder) {
                this.displayOrder = displayOrder;
           }
      
           /*
            * (non-Javadoc)
            * 
            * @see java.lang.Object#hashCode()
            */
           @Override
           public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + displayOrder;
                result = prime * result + ((label == null) ? 0 : label.hashCode());
                result = prime * result + ((value == null) ? 0 : value.hashCode());
                return result;
           }
      
           /**
            * Equals.
            * 
            * @param obj
            *            the obj
            * 
            * @return true, if equals
            * 
            * @see java.lang.Object#equals(java.lang.Object)
            */
           @Override
           public boolean equals(Object obj) {
                if (this == obj)
                     return true;
                if (obj == null)
                     return false;
                if (getClass() != obj.getClass())
                     return false;
                final MySelectItem other = (MySelectItem) obj;
                if (label == null) {
                     if (other.label != null)
                          return false;
                } else if (!this.label.equals(other.label))
                     return false;
                if (value == null) {
                     if (other.value != null)
                          return false;
                } else if (!this.value.equals(other.value))
                     return false;
                return true;
           }
      
           /**
            * To string.
            * 
            * @return the string
            * 
            * @author
            */
           public String toString() {
                StringBuffer buffer = new StringBuffer();
                buffer.append(value);
                buffer.append(":");
                buffer.append(label);
                return buffer.toString();
           }
      }
      
        • 1. Re: listShuttle Error "has invalid value expression"
          keithdmoore94

          Can you provide your xhtml?  It is missing above.  Also, did try removing the converter altogether and just let the default entity converter be used?

          • 2. Re: listShuttle Error "has invalid value expression"
            tiger86
            <ui:composition
            template="/WEB-INF/fragments/wizardTemplate.xhtml">
            <ui:define name="wizardSettings">
            <c:set var="wizardNavigation" value="#{configureSettingsWizard}"/>
            <c:set var="configureStep" value="#{wizardNavigation.stepMap['ConfigureStep']}"/>
            </ui:define>
            <a4j:keepAlive beanName="configureStep"/>
            <ui:define name="title">
            <h:outputText value="form_configure_settings_title" escape="false"/>
            </ui:define>
            <ui:define name="content">
            <h2><h:outputText value="#{msg.form_rpbyvisa_initial_title}"/></h2>
            <rps:select label="${msg.form_configure_settings_title}" backingBean="#{configureStep}" property="configurationSettings" items="${masterdata.configurationSettings}" required="true">
            <a4j:support event="onchange" reRender="configurePanel" action="#{configureStep.onConfigurationSettings}" ajaxSingle="true" />
            </rps:select>
            <br />
            <a4j:outputPanel id="configurePanel">
            <ui:fragment rendered="${'STATISTICS_LIVE_SETTINGS' eq configureStep.configurationSettings}">
            <h2><h:outputText value="#{msg.form_configure_settings_statistics_live_settings}"/></h2>
            <rps:inputText label="${msg.form_configure_settings_period}" backingBean="#{configureStep}" property="period" />
            </ui:fragment>
            <ui:fragment rendered="${'PROHIBITED_PROFESSIONS_SETTINGS' eq configureStep.configurationSettings}">
            <h2><h:outputText value="#{msg.form_configure_settings_prohibited_professions_Settings}"/></h2>
                   <rich:listShuttle sourceValue="#{configureStep.nonProhibitedProfessionsListItem}"
                       targetValue="#{configureStep.prohibitedProfessionsListItem}"
                       orderControlsVisible="false" fastOrderControlsVisible="false"
                       showButtonLabels="false" var="profession" converter="ListConverter"
                       sourceCaptionLabel="${msg.form_configure_settings_non_prohibited_professions}"
                       targetCaptionLabel="${msg.form_configure_settings_prohibited_professions}">
                                 <rich:column>
                                    <h:outputText value="#{profession.label}" />

             

                 </rich:column>

                   </rich:listShuttle>
            </ui:fragment>
            </a4j:outputPanel>
            </ui:define>
            </ui:composition>

            Hi Keith

            this is xhtml

             

             

            <ui:composition
             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:c="http://java.sun.com/jstl/core"
             xmlns:a4j="http://richfaces.org/a4j"
             xmlns:rich="http://richfaces.org/rich"
             xmlns:rps="http://www.rps.xxx.com/core"
             template="/WEB-INF/fragments/wizardTemplate.xhtml">
            
             <ui:define name="wizardSettings">
             <c:set var="wizardNavigation" value="#{configureSettingsWizard}"/>
             <c:set var="configureStep" value="#{wizardNavigation.stepMap['ConfigureStep']}"/>
             </ui:define>
             <a4j:keepAlive beanName="configureStep"/>
            
             <ui:define name="title">
             <h:outputText value="form_configure_settings_title" escape="false"/>
             </ui:define>
            
             <ui:define name="content">
             <h2><h:outputText value="#{msg.form_rpbyvisa_initial_title}"/></h2>
             <rps:select label="${msg.form_configure_settings_title}" backingBean="#{configureStep}" property="configurationSettings" items="${masterdata.configurationSettings}" required="true">
             <a4j:support event="onchange" reRender="configurePanel" action="#{configureStep.onConfigurationSettings}" ajaxSingle="true" />
             </rps:select>
             <br />
             <a4j:outputPanel id="configurePanel">
             <ui:fragment rendered="${'STATISTICS_LIVE_SETTINGS' eq configureStep.configurationSettings}">
             <h2><h:outputText value="#{msg.form_configure_settings_statistics_live_settings}"/></h2>
             <rps:inputText label="${msg.form_configure_settings_period}" backingBean="#{configureStep}" property="period" />
             </ui:fragment>
             <ui:fragment rendered="${'PROHIBITED_PROFESSIONS_SETTINGS' eq configureStep.configurationSettings}">
             <h2><h:outputText value="#{msg.form_configure_settings_prohibited_professions_Settings}"/></h2>
                     <rich:listShuttle sourceValue="#{configureStep.nonProhibitedProfessionsListItem}"
                         targetValue="#{configureStep.prohibitedProfessionsListItem}"
                         orderControlsVisible="false" fastOrderControlsVisible="false"
                         showButtonLabels="false" var="profession" converter="ListConverter"
                         sourceCaptionLabel="${msg.form_configure_settings_non_prohibited_professions}"
                         targetCaptionLabel="${msg.form_configure_settings_prohibited_professions}">
                             <rich:column>
                                    <h:outputText value="#{profession.label}" />
                             </rich:column>
                     </rich:listShuttle>
             </ui:fragment>
             </a4j:outputPanel>
             </ui:define>
            </ui:composition>
            
            
            

             

            and i try not use the converter but it didn't work

            thx for your helping

            • 3. Re: listShuttle Error "has invalid value expression"
              tiger86

              Hay all

              help plz

              • 4. Re: listShuttle Error "has invalid value expression"
                ilya_shaikovsky

                check your converter in debug(If the objects converted back and forth are really similar). If you have invalid value expression - the problem definitelly lies there.

                • 5. Re: listShuttle Error "has invalid value expression"
                  auston

                  The problem on the equals, rewrite, avoid use == to compare objects, for this use always obj.equals().

                  Is a good thing always start your equals like this above:

                  public boolean equals(Object obj) {
                      if ((this == null && obj != null)  || (this != null && obj == null)){
                          return false;
                      } else if (this == null && obj == null){
                           return true;
                      } else if (getClass() != obj.getClass()) {
                          return false;
                      } else if (this.getId().equals( ((MyClass)obj).getId())){
                           return true;
                      }
                  //... others checks
                  }
                  
                  • 6. Re: listShuttle Error "has invalid value expression"
                    michpetrov

                    auston that's not a very good implementation, for one it looks like it will end up in an infinite recursion loop. You are also replying to a 5-year old thread where the equals method does not seem to be the issue in the first place.

                    • 7. Re: listShuttle Error "has invalid value expression"
                      auston

                      Thanks Michal, i fixed de sample code for equals in previous post. I replied this old post cause i pass for same problem and not found solution in the web. Debbuging into listshuttle component source, i discovery that it use the equals of class type putted in control value property to validate your current value. if the equals fail then this exception "has invalid value expression" is throw. Finaly, the source of this problem is the wrong implementation of equals.