Re: [appfuse-user] Nested form validation (again!)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [appfuse-user] Nested form validation (again!)

Matt Raible-3
I'm usually able to provide better help based on error messages,
rather than looking at code.  If the client-side validation isn't
working - does the server-side validation work?

Matt

On 6/28/05, Andrew Czerwinski <[hidden email]> wrote:

> Hi All,
>
> BTW Matt, appfuse is a great piece of kit to start developing persistent
> applications - would have taken me months to get all the managers etc
> written if doing it manually!
>
> Anyway, the problem I'm having is that even though my nested forms are
> generating the correct client side validation code, the actual field
> names are not being passed to them (mainly because they're on the nested
> form)
>
> So when the validation runs you get the following dynamically created
> validation in the signup.jsp (did view source on page)
>
> <script type="text/javascript">
>
>      var bCancel = false;
>
>     function validateSignupUserForm(form) {
>
>         if (bCancel)
>       return true;
>         else
>  var formValidationResult;
>        formValidationResult = validateRequired(form) &&
> validateEmail(form) && validateMask(form) && validateTwoFields(form);
>      return (formValidationResult == 1);
>    }
>
>     function signupUserForm_required () {
>      this.a0 = new Array("userForm.username", "'' is a required field.",
> new Function ("varName", " return this[varName];"));
>      this.a1 = new Array("userForm.password", "'' is a required field.",
> new Function ("varName", "this.secondProperty='confirmPassword';  return
> this[varName];"));
>      this.a2 = new Array("userForm.confirmPassword", "'' is a required
> field.", new Function ("varName", " return this[varName];"));
>      this.a3 = new Array("userForm.passwordHint", "'' is a required
> field.", new Function ("varName", " return this[varName];"));
>      this.a4 = new Array("addressBookForm.entryStreetAddress", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a5 = new Array("addressBookForm.entryPostcode", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a6 = new Array("addressBookForm.entryCity", "'' is a required
> field.", new Function ("varName", " return this[varName];"));
>      this.a7 = new Array("addressBookForm.appUserForm.username", "'' is
> a required field.", new Function ("varName", " return this[varName];"));
>      this.a8 = new Array("addressBookForm.appUserForm.password", "'' is
> a required field.", new Function ("varName",
> "this.secondProperty='confirmPassword';  return this[varName];"));
>      this.a9 = new Array("addressBookForm.appUserForm.confirmPassword",
> "'' is a required field.", new Function ("varName", " return
> this[varName];"));
>      this.a10 = new Array("addressBookForm.appUserForm.passwordHint",
> "'' is a required field.", new Function ("varName", " return
> this[varName];"));
>      this.a11 = new Array("customerForm.customersTitle", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a12 = new Array("customerForm.customersGender", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a13 = new Array("customerForm.customersFirstname", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a14 = new Array("customerForm.customersLastname", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a15 = new Array("customerForm.customersEmailAddress", "'' is a
> required field.", new Function ("varName",
> "this.secondProperty='customersConfirmEmailAddress';  return
> this[varName];"));
>      this.a16 = new Array("customerForm.customersConfirmEmailAddress",
> "'' is a required field.", new Function ("varName", " return
> this[varName];"));
>      this.a17 = new Array("customerForm.customersTelephone", "'' is a
> required field.", new Function ("varName",
> "this.mask=/^\\(?(\\d{3})\\)?[-| ]?(\\d{3})[-| ]?(\\d{4})$/;  return
> this[varName];"));
>      this.a18 = new Array("customerForm.customersNewsletter", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>      this.a19 = new Array("customerForm.customersEmails", "'' is a
> required field.", new Function ("varName", " return this[varName];"));
>     }
>
>     function signupUserForm_email () {
>      this.a0 = new Array("customerForm.customersEmailAddress", "'' is an
> invalid e-mail address.", new Function ("varName",
> "this.secondProperty='customersConfirmEmailAddress';  return
> this[varName];"));
>     }
>
>     function signupUserForm_mask () {
>      this.a0 = new Array("customerForm.customersTelephone", "'' is an
> invalid phone number.", new Function ("varName",
> "this.mask=/^\\(?(\\d{3})\\)?[-| ]?(\\d{3})[-| ]?(\\d{4})$/;  return
> this[varName];"));
>     }
>
>     function signupUserForm_twofields () {
>      this.a0 = new Array("userForm.password", "The '' field has to have
> the same value as the 'Confirm Password' field.", new Function
> ("varName", "this.secondProperty='confirmPassword';  return
> this[varName];"));
>      this.a1 = new Array("addressBookForm.appUserForm.password", "The ''
> field has to have the same value as the 'Confirm Password' field.", new
> Function ("varName", "this.secondProperty='confirmPassword';  return
> this[varName];"));
>      this.a2 = new Array("customerForm.customersEmailAddress", "The ''
> field has to have the same value as the '' field.", new Function
> ("varName", "this.secondProperty='customersConfirmEmailAddress';  return
> this[varName];"));
>     }
>
>
> </script>
>
> Below is a snippet of the signup.jsp
>
> <%@ include file="/common/taglibs.jsp"%>
>
> <title><fmt:message key="signup.title"/></title>
> <content tag="heading"><fmt:message key="signup.heading"/></content>
> <body id="signup"/>
>
> <fmt:message key="signup.message"/>
>
> <div class="separator"></div>
>
> <html:form action="/signup" focus="userForm.username"
> styleId="signupUserForm"
>     onsubmit="return validateSignupUserForm(this)">
>
> <table>
>     <tr>
>         <th>
>             <sklep:label key="userForm.username"/>
>         </th>
>         <td>
>             <html:text property="userForm.username"
> styleId="userForm.username"/>
>             <html:errors property="userForm.username"/>
>         </td>
>     </tr>
>
>     <tr>
>         <th>
>             <sklep:label key="userForm.password"/>
>         </th>
>         <td>
>             <html:password property="userForm.password"
> styleId="userForm.password" redisplay="true"/>
>             <html:errors property="userForm.password"/>
>         </td>
>     </tr>
> ......
> </html:form>
>
> <html:javascript formName="signupUserForm" cdata="false"
>       dynamicJavascript="true" staticJavascript="false"/> <script
> type="text/javascript"
>       src="<c:url value="/scripts/validator.jsp"/>"></script>
>
> And my SignupUserForm.java
>
> package uk.co.polishfood.webapp.form;
>
> import javax.servlet.http.HttpServletRequest;
>
> import org.apache.struts.action.ActionMapping;
>
> /**
>  *
>  * @struts.form name="signupUserForm"
>  */
> public class SignupUserForm
>     extends    BaseForm
>     implements java.io.Serializable
> {
>     private UserForm appUser = new UserForm();
>
>     private CustomerForm customer = new CustomerForm();
>
>     private AddressBookForm addressBook = new AddressBookForm();
>
>     /** Default empty constructor. */
>     public SignupUserForm() {}
>
> // User
>     public UserForm getUserForm()
>     {
>         return this.appUser;
>     }
>
>    /**
>     * @struts.validator
>     */
>     public void setUserForm( UserForm appUser )
>     {
>         this.appUser = appUser;
>     }
>
>     /**
>      *  Getter/Setter pair so BeanUtil.copyProperties(dest, orig) will
> work
>      *  Any properties modified in the web tier should use the
> get/setAppUserForm
>      *  methods.
>      */
>     public uk.co.polishfood.model.User getUser() throws Exception
>     {
>         return (uk.co.polishfood.model.User)
> uk.co.polishfood.util.ConvertUtil.convert(this.appUser);
>     }
>
>     public void setUser(uk.co.polishfood.model.User appUser) throws
> Exception
>     {
>         setUserForm((UserForm)
> uk.co.polishfood.util.ConvertUtil.convert(appUser));
>     }
>
> // Address Book
>     public AddressBookForm getAddressBookForm()
>     {
>         return this.addressBook;
>     }
>
>    /**
>     * @struts.validator
>     */
>     public void setAddressBookForm( AddressBookForm addressBook )
>     {
>         this.addressBook = addressBook;
>     }
>
>     /**
>      *  Getter/Setter pair so BeanUtil.copyProperties(dest, orig) will
> work
>      *  Any properties modified in the web tier should use the
> get/setAddressBookForm
>      *  methods.
>      */
>     public uk.co.polishfood.model.AddressBook getAddressBook() throws
> Exception
>     {
>         return (uk.co.polishfood.model.AddressBook)
> uk.co.polishfood.util.ConvertUtil.convert(this.addressBook);
>     }
>
>     public void setAddressBook(uk.co.polishfood.model.AddressBook
> addressBook) throws Exception
>     {
>         setAddressBookForm((AddressBookForm)
> uk.co.polishfood.util.ConvertUtil.convert(addressBook));
>     }
>
> // Customer
>     public CustomerForm getCustomerForm()
>     {
>         return this.customer;
>     }
>
>    /**
>     * @struts.validator
>     */
>     public void setCustomerForm( CustomerForm customer )
>     {
>         this.customer = customer;
>     }
>
>     /**
>      *  Getter/Setter pair so BeanUtil.copyProperties(dest, orig) will
> work
>      *  Any properties modified in the web tier should use the
> get/setCustomerForm
>      *  methods.
>      */
>     public uk.co.polishfood.model.Customer getCustomer() throws
> Exception
>     {
>         return (uk.co.polishfood.model.Customer)
> uk.co.polishfood.util.ConvertUtil.convert(this.customer);
>     }
>
>     public void setCustomer(uk.co.polishfood.model.Customer customer)
> throws Exception
>     {
>         setCustomerForm((CustomerForm)
> uk.co.polishfood.util.ConvertUtil.convert(customer));
>     }
>
>     /**
>      * @see
> org.apache.struts.action.ActionForm#reset(org.apache.struts.action.Actio
> nMapping,
>      *
> javax.servlet.http.HttpServletRequest)
>      */
>     public void reset(ActionMapping mapping, HttpServletRequest request)
> {
>         // reset any boolean data types to false
>
>     }
>
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...