9 Replies Latest reply on Jun 3, 2008 1:41 PM by nathandennis

    Richfaces, Validation, actionParam

    nathandennis

      having trouble submitting a form and passing actionparam with the same commandLink if i am preforming validation on the fields in 3.2. any direction would be greatly appreciated.

       <s:div rendered="#{joinAction.tabsw ==1}" styleClass="jointabpanel1">
       <a:form submitMode="ajax">
       <a:jsFunction name="reRenderJoinPanel"
       reRender="joinpanel"
       eventsQueue="joinQueue"
       ajaxSingle="true">
       <a:actionparam name="tabsw" value="2" assignTo="#{joinAction.tabsw}"/>
       <s:conversationId/>
       </a:jsFunction>
       <div class="joinContent">
       <p>Create your login by entering the information below and select <b>next</b>. Your password must be between 6 and 15 characters long.</p>
      
       <div>
       <div class="prop">
       <span class="jointabLabels">
       <h:outputText value="Email:"/>
       <s:span styleClass="required">*</s:span>
       </span>
       <span class="value #{invalid?'errors':''}">
       <h:inputText id="emailid"
       required="true"
       value="#{joinAction.emailaddress}">
       <f:validator validatorId="emailValidator"/>
       <s:validate/>
       <a:support event="onblur" eventsQueue="joinQueue"
       reRender="emailDecoration" ajaxSingle="true"/>
       </h:inputText>
       </span>
       <span class="error">
       <rich:message id="emailError" for="emailid" styleClass=" errors ">
      
       <f:facet name="passedMarker" >
       <h:graphicImage value="/img/passed.gif" rendered="#{not empty joinAction.emailaddress}"/>
       </f:facet>
      
       <f:facet name="errorMarker">
       <h:graphicImage value="/img/error.gif" />
       </f:facet>
       <f:facet name="infoMarker">
       <h:graphicImage value="/img/error.gif" />
       </f:facet>
       </rich:message>
       </span>
       </div>
       <div style="width:100%; padding-left:0px;" align="left">
      
       <s:decorate id="firstDecoration" template="../layout/joinedit.xhtml">
       <ui:define name="label">first name:</ui:define>
       <span>
       <h:inputText id="firstnameid"
       required="true"
       value="#{joinAction.firstname}">
       <a:support event="onblur" eventsQueue="joinQueue"
       reRender="firstDecoration" ajaxSingle="true"/>
       </h:inputText>
       </span>
       </s:decorate>
      
       <s:decorate id="lastDecoration" template="../layout/joinedit.xhtml">
       <ui:define name="label">last name:</ui:define>
       <h:inputText id="lastnameid"
       required="true"
       value="#{joinAction.lastname}">
       <a:support event="onblur" eventsQueue="joinQueue"
       reRender="lastDecoration" ajaxSingle="true"/>
       </h:inputText>
       </s:decorate>
      
       </div>
       <div class="prop">
       <span class="jointabLabels #{invalid?'errors':''}">
       password:
       <s:span styleClass="required">*</s:span>
       </span>
       <span class="value #{invalid?'errors':''}">
       <h:inputSecret id="passwdid"
       required="true"
       value="#{joinAction.passwd}">
       <s:validate/>
       <a:support event="onblur" eventsQueue="joinQueue"
       reRender="passwdError" ajaxSingle="true"/>
       </h:inputSecret>
       </span>
       <span class="error">
       <rich:message id="passwdError" for="passwdid" styleClass="errors">
       <f:facet name="passedMarker">
       <h:graphicImage value="/img/passed.gif" rendered="#{not empty joinAction.passwd}"/>
       </f:facet>
       <f:facet name="infoMarker">
       <h:graphicImage value="/img/error.gif" />
       </f:facet>
       <f:facet name="errorMarker">
       <h:graphicImage value="/img/error.gif" />
       </f:facet>
       </rich:message>
       </span>
       </div>
       <div class="prop">
       <span class="jointabLabels #{invalid?'errors':''}">
       <h:outputText value="retype password:"/>
       <s:span styleClass="required">*</s:span>
       </span>
       <span class="value #{invalid?'errors':''}">
       <h:inputSecret id="repasswdid"
       required="true"
       value="#{joinAction.repasswd}">
       <f:validator validatorId="passwordValidator"/>
       <s:validate/>
       <a:support event="onblur" eventsQueue="joinQueue"
       reRender="repasswdError" ajaxSingle="true"/>
       </h:inputSecret>
       </span>
       <span class="error">
       <rich:message id="repasswdError" for="repasswdid" styleClass="errors">
       <f:facet name="passedMarker">
       <h:graphicImage value="/img/passed.gif" rendered="#{not empty joinAction.repasswd}"/>
       </f:facet>
       <f:facet name="infoMarker">
       <h:graphicImage value="/img/error.gif" />
       </f:facet>
       <f:facet name="errorMarker">
       <h:graphicImage value="/img/error.gif"/>
       </f:facet>
       </rich:message>
       </span>
       </div>
       <div class="prop">
       <span class="jointabLabels">
       <h:outputText value="Email Sign Up:"/>
       </span>
       <span class="value">
       <h:selectBooleanCheckbox value="#{joinAction.emailsignup}">
       <a:support event="onclick"/>
       </h:selectBooleanCheckbox>
       </span>
       </div>
       <div class="prop" style="width:500px;top:290px;position:absolute;">
       <p>
       <h:outputText value="Please send me Managing Memories emails with special offers and information."/>
       </p>
      
       <p class="next">
       <a:commandLink ajaxSingle="false" reRender="joinpanel" eventsQueue="joinQueue"
       name="joinlogintab">
       <img src="../img/images/nextBtn.png" border="0"/>
       <s:conversationId/>
       <a:actionparam noEscape="true" name="panelid" value="2" assignTo="#{joinAction.tabsw}"/>
      
       </a:commandLink>
       </p>
       </div>
       </div>
      
      
       </div>
       </a:form>
       </s:div>
      


      the gist is,, i have a stateful backing bean and multiple custom validators. the issue is if i allow validation on the individual fields, the actionparam isnt passed. on other panels using the same code.. if i leave off the validation it works fine. is this a limitation of richfaces?

      ive already looked at the wizard stuff in the demo.. .there are issues with structuring it like that because client wanted multiple ways to get to each page.


        • 1. Re: Richfaces, Validation, actionParam
          nathandennis

          i should probably also add,, that all field except the actionparam are submitted

          • 2. Re: Richfaces, Validation, actionParam
            nathandennis

            apparently this has to do with the custom validation that i am using. this works when it is being validated against either JSF required... or a hibernate validation rule..
            take a look at at this custom validator. im probably not a familiar with the various phases that the ajax request is going through before the form is submitted.
            two validators in this for both are constructed similarly.

            package com.dcg.action.validators;
            
            import java.io.Serializable;
            
            import javax.faces.application.FacesMessage;
            import javax.faces.component.UIComponent;
            import javax.faces.validator.ValidatorException;
            
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Transactional;
            import org.jboss.seam.annotations.faces.Validator;
            
            import com.dcg.action.user.JoinLocal;
            
            
            @Name("passwordValidator")
            @Validator
            @Transactional
            public class PasswordValidator implements javax.faces.validator.Validator, Serializable{
             /**
             * @author nbd
             * 05/30/08
             * Password Validator
             */
             private static final long serialVersionUID = 1L;
            
             @In(required=true)
             JoinLocal joinAction;
            
             public void validate(javax.faces.context.FacesContext facesContext, UIComponent component, Object value)
             throws ValidatorException {
            
             String retype = (String) value;
             if(!(joinAction.getPasswd() == null)){
             if(!joinAction.getPasswd().equals(retype)){
             throw new ValidatorException(new FacesMessage("Passwords do not match."));
             }
            
             }
             }
            }


            • 3. Re: Richfaces, Validation, actionParam
              ilya_shaikovsky

              1) remove ajaxSubmit="true" from the form.

              B.t.w. If you mean that param should be aplied even if validation fails?

              • 4. Re: Richfaces, Validation, actionParam
                nathandennis

                tried that already.. submitMode="ajax" got there out of an act of desperation.

                the param should only be applied if the form is submitted. my understanding of actionParam was, it is submitted as any other field in the form after validation.


                but like i said before. the actionParam is submitting correctly when only validating against org.hibernate.validator. or the client side jsf required. the problem only arises when using
                <f:validator validatorId="passwordValidator"/> or some other custom validator.


                here is the other validator that is being used.

                @Name("emailValidator")
                @Validator
                @Transactional
                public class EmailValidator implements javax.faces.validator.Validator, Serializable{
                 /**
                 * @author nbd
                 * 05/30/08
                 * Email validator
                 */
                 private static final long serialVersionUID = 1L;
                
                 @In
                 EntityManager entityManager;
                
                
                 public void validate(javax.faces.context.FacesContext facesContext, UIComponent component, Object value)
                 throws ValidatorException {
                
                 String emailaddress = (String) value;
                 String emailRegEx = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
                
                // Compile and get a reference to a Pattern object.
                 Pattern pattern = Pattern.compile(emailRegEx);
                // Get a matcher object - we cover this next.
                 Matcher matcher = pattern.matcher(emailaddress);
                 if(!matcher.find()){
                 throw new ValidatorException(new FacesMessage("Email address is not valid."));
                 } else {
                 try {
                 Userlogin cc1 = (Userlogin)
                 entityManager.createQuery("from Userlogin where userid = :emailaddress")
                 .setParameter("emailaddress", emailaddress).getSingleResult();
                 if (cc1 != null ) {
                 throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Account already exist. Please login to make changes.", null));
                 }
                 } catch (NoResultException nre) {
                 // that's fine - this name is unique.
                 }
                 }
                
                
                
                
                 }
                
                }


                • 5. Re: Richfaces, Validation, actionParam
                  nathandennis

                  i lied... IT ISNT THE CUSTOM VALIDATION breaking it. the actionparam will not submit if

                  h:selectBooleanCheckbox value="#{joinAction.emailsignup}">
                   </h:selectBooleanCheckbox>
                  

                  is in the form.

                  any clue on a work around or what is causing this? 100% the checkbox is the problem and this is probably a bug.

                  • 6. Re: Richfaces, Validation, actionParam
                    nathandennis

                    it looks like the param is making to the request string with the check box

                    AJAXREQUEST=_viewRoot&j_id82%3Aemailid=foo%40foo.com&j_id82%3AfirstDecoration%3Afirstnameid=foofirst
                    
                    &j_id82%3AlastDecoration%3Alastnameid=foolast&j_id82%3Apasswdid=password&j_id82%3Arepasswdid=password
                    
                    &j_id82%3Aj_id142=on&j_id82=j_id82&autoScroll=&javax.faces.ViewState=j_id17&panelid=2&j_id82%3Aj_id146
                    
                    =j_id82%3Aj_id146&cid=21&


                    this without works fine..
                    AJAXREQUEST=_viewRoot&j_id82%3Aemailid=foo%40foo.com&j_id82%3AfirstDecoration%3Afirstnameid=nas&j_id82
                    
                    %3AlastDecoration%3Alastnameid=nasd&j_id82%3Apasswdid=password&j_id82%3Arepasswdid=password&j_id82=j_id82
                    
                    &autoScroll=&javax.faces.ViewState=j_id18&panelid=2&j_id82%3Aj_id144=j_id82%3Aj_id144&cid=22&
                    


                    • 7. Re: Richfaces, Validation, actionParam
                      nathandennis

                      this is so quirky...

                      on my session bean i used boolean for the value in the setter.

                      public void setEmailsignup(boolean emailsignup){
                       this.emailsignup = emailsignup;
                      }
                      

                      the POS didnt like that for some reason.
                      i switched it to Boolean and the junk started working.
                      public void setEmailsignup(Boolean emailsignup){
                       this.emailsignup = emailsignup;
                      }
                      



                      keep in mind that this field would submit to the bean perfectly initially. the only problem was the action param not submitting. what a waste of a weekend.

                      • 8. Re: Richfaces, Validation, actionParam
                        ilya_shaikovsky

                        so your checkBox breaks conversion/validation so no params applied. There are nothing about Rich Faces functionality.

                        In a such cases - always place rich:messages somewhere on the page to check if the request was processed successfully.

                        • 9. Re: Richfaces, Validation, actionParam
                          nathandennis

                          yes,,, that is what im saying... when checkBox passed to a boolean field the param on the commandLink isnt applied. all other fields on the form are submitted. when passed to a Boolean field the param is applied on form submission.