3 Replies Latest reply on Nov 7, 2007 6:22 AM by Jonas Buechel

    After updating to 2.0.0.GA uiComponent.findComponent(string)

    Jonas Buechel Novice

      When i deploy the application with the new Seam 2.0.0.GA jar files the method

      UIComponent comparedUIComponent = uiComponent.findComponent(comparedFieldId);

      returns null. When i deploy it with 2.0.0.BETA1 the component is found..
      I don't have any idea why this behavior occurs as it's not seam code..!?

      @Name("equalsFieldValidator")
      @BypassInterceptors
      @Validator(id = "com.frox.fwc.validator.equalsFieldValidator")
      public class EqualsFieldValidator implements javax.faces.validator.Validator {
      
       public final static String ATTRIBUTE_COMPARED_COMPONENT_ID = "comparedFieldId";
      
       /*
       * (non-Javadoc)
       *
       * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext,
       * javax.faces.component.UIComponent, java.lang.Object)
       */
       @Override
       public void validate(FacesContext facesContext, UIComponent uiComponent, Object value)
       throws ValidatorException {
      
       String fieldValue = (String) value;
       UIComponent equalInputField = this.getComparedComponent(uiComponent);
      
       Object equalValue = ((UIInput) equalInputField).getValue();
      
       if (!fieldValue.equals(equalValue))
       throw new ValidatorException(FacesMessages.createFacesMessage(FacesMessage.SEVERITY_ERROR,
       "com.frox.fwc.validator.equalsField", ""));
       }
      
       public UIComponent getComparedComponent(UIComponent uiComponent) {
      
       String comparedFieldId = (String) uiComponent.getAttributes().get(
       ATTRIBUTE_COMPARED_COMPONENT_ID);
       if (comparedFieldId == null)
       throw new IllegalStateException(
       "Attribut equalComponentId must be set. ");
      
       UIComponent comparedUIComponent = uiComponent.findComponent(comparedFieldId);
       if (comparedUIComponent == null)
       throw new IllegalStateException("UIComponent with id " + comparedFieldId
       + " not found.");
      
       return comparedUIComponent;
       }
      }
      


      <f:validator validatorId="com.frox.fwc.validator.equalsFieldValidator" />
       <f:attribute name="comparedFieldId" value="user_label_new_password" />
       <s:validate />


      Any help would be great!

        • 1. Re: After updating to 2.0.0.GA uiComponent.findComponent(str
          Jonas Buechel Novice

          The cause for this behavior is the s:decorate tag generates different clientIds of its children:

          This is the xhtml code:

          ...
           <h:form id="missionForm">
           <s:decorate template="#{theme.inputSecretHorizontal}">
           <ui:param name="fwcLabelMessageKey" value="user_label_new_password" />
           <ui:param name="fwcInputProperty" value="#{user.newPassword}" />
           <ui:param name="fwcInputRequired" value="true" />
           </s:decorate>
          
           <s:decorate template="#{theme.inputSecretHorizontal}">
           <ui:param name="fwcLabelMessageKey" value="user_label_verify_password" />
           <ui:param name="fwcInputProperty" value="#{user.verifyPassword}" />
           <ui:param name="fwcInputRequired" value="true" />
           <ui:define name="fwcInputValidator">
           <f:validator validatorId="com.frox.fwc.validator.equalsFieldValidator" />
           <f:attribute name="comparedFieldId" value="user_label_new_password" />
           <s:validate />
           </ui:define>
           </s:decorate>
          
          ...


          Before (2.0.0.BETA1) the clientId of the HtmlInputSecret component was generated as:
          [1]= HtmlInputSecret (id=4867)
           _values= Object[35] (id=4869)
           accesskey= null
           alt= null
           attributes= UIComponentBase$AttributesMap (id=4870)
           autocomplete= null
           bindings= HashMap<K,V> (id=4872)
           children= null
           clientId= "missionForm:user_label_new_password"
           converter= null
           converterMessage= null
           converterMessageSet= false
           dir= null
           disabled= false
           disabled_set= false
           facets= null
           id= "user_label_new_password"
           immediate= false
          ...
          

          Now (2.0.0.GA):
          [1]= HtmlInputSecret (id=330)
           _values= Object[35] (id=5112)
           accesskey= null
           alt= null
           attributes= UIComponentBase$AttributesMap (id=5113)
           autocomplete= null
           bindings= HashMap<K,V> (id=5114)
           children= null
           clientId= "missionForm:j_id55:user_label_new_password"
           converter= null
           converterMessage= null
           converterMessageSet= false
           dir= null
           disabled= false
           disabled_set= false
           facets= null
           id= "user_label_new_password"
           immediate= false
           immediateSet= false
           isUIComponentBase= false
           isUIComponentBaseIsSet= false
           label= null
           lang= null
          


          Hope this helps some orthers doing the migration..

          • 2. Re: After updating to 2.0.0.GA uiComponent.findComponent(str
            Saeed Iqbal Novice

            So how did you get around it in the java code?

            • 3. Re: After updating to 2.0.0.GA uiComponent.findComponent(str
              Jonas Buechel Novice

              Sorry, i missed giving that information.

              I replaced:

              UIComponent comparedUIComponent = uiComponent.findComponent(comparedFieldId);


              with:
              UIComponent comparedUIComponent = FacesContext.getCurrentInstance().getViewRoot()
               .findComponent(comparedFieldId);