You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Tangney <jo...@jdtangney.com> on 2003/08/15 00:10:16 UTC
Re: Trouble with validation of nested properties
-indexedListProperty?
Thanks, Yansheng.
I am not sure I understand. I tried
<field property="allUsers" indexedListProperty="allUsers"
depends="required,email">
<arg0 key="userListForm.allUsers.email"/>
</field>
Is that what you meant? It does the same thing (empty JavaScript.) I don't
understand how your solution is *supposed* to work. I want to validate the
email field of every Info object in the allUsers collection.
Did I misunderstand your suggestion?
Thanks!
--johnt
in article 000001c36279$30b74d70$7202a8c0@stbedm.silvacom.com, Yansheng Lin
at yansheng.lin@isogis.com wrote on 8/14/03 8:31 AM:
>
> I can see one spot that could lead to problem.
>
> In your iterate, the var name is "allUsers". However, in your
> validation.xml,
> the field property is "email". The name of the iteration var has to be the
> same as the property name of the array in the form.
>
> Hope this works.
>
> - Yansheng
>
> -----Original Message-----
> From: John Tangney [mailto:johnt@jdtangney.com]
> Sent: August 13, 2003 5:22 PM
> To: struts-user@jakarta.apache.org
> Subject: Trouble with validation of nested properties -indexedListProperty?
>
>
> Hi all,
>
> I have memorized the docs, scoured the archives, googled 'till my eyes were
> crossed, experimented at great length, but have not been able to solve this
> riddle.
>
> I have a JSP that looks like this:
>
> <nested:iterate property="allUsers">
> <tr>
> <td><nested:text property="userName"/></td>
> <td><nested:text property="email"/></td>
> </tr>
> </nested:iterate>
>
>
> My form bean has
>
> public List getAllUsers() {
> return this.allUsers;
> }
>
> Which returns a collection of...
>
> public static class Info { // an inner class of the form bean, FWIW
> private String email;
> private String userName;
>
> public void setEmail(String string) {
> email = string;
> }
>
> public String getEmail() {
> return email;
> }
> ...
> }
>
> Everything's great - works perfectly; does what I want. It's a pattern I use
> all over the place, on several projects.
>
> Next, I want to add validation:
>
> In the JSP I add <html:javascript formName="userListForm"/> in the head. My
> form bean now extends ValidatorForm.
>
> In my validation.xml I add:
>
> <form name="userListForm">
> <field property="email" indexedListProperty="allUsers"
> depends="required,email">
> <arg0 key="userListForm.allUsers.email"/>
> </field>
> </form>
>
>
> *** The validation doesn't work.***
>
> I am more concerned about client-side validation, so let's look at that:
>
> The generated JavaScript looks like this:
> <!-- Begin
>
> var bCancel = false;
>
> function validateUserListForm(form) {
> if (bCancel)
> return true;
> else
> return validateRequired(form) && validateEmail(form);
> }
>
> function required () {
> }
>
> function email () {
> }
>
> This tells me that my struts-config-*.xml is correct, but that validator is
> unable to generate the correct code based on what I said in my
> validation.xml.
>
> Can some kind soul please help me correct my validation.xml? I have tried
> using indexedProperty, which causes the two JavaScript functions to be
> generated, but with incorrect values. I have tried rewriting the whole thing
> using <logic:iterate> but that gets me into a mess of other changes.
>
> Please, please, can someone help?
>
> Thanks
> --johnt
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
writing an actionform for nested indexed properties
Posted by Cameron Hickey <ca...@panoramatos.com>.
I am trying to write an actionform which will properly handle an array
of indexed properties which look like this:
ip[0].itemPropertys[0].itemPropertyId
ip[0].itemPropertys[0].value
ip[1].itemPropertys[0].itemPropertyId
ip[1].itemPropertys[0].value
etc...
In my Action form, what getters and setters do I need?
This is what I have so far:
public List getIp() { return ip;}
public void setIp(List ipList) {ip = ipList;}
public List getItemPropertys(int idx) {return (List) ip.get(idx); }
public void setItemPropertys(int idx,ItemProperty ipe)
{ip.set(idx,ipe);}
public ItemProperty getItemProperty(int idx, List ipl) {return
(ItemProperty) ipl.get(idx);}
public void setItemProperty(int idx,List ipl, ItemProperty tip)
{ipl.set(idx,tip);}
public String getValue(ItemProperty tip) {return tip.getValue();}
public void setValue(String s, ItemProperty tip) {tip.setValue(s);}
public int getItemPropertyId(ItemProperty tip) {return
tip.getItemPropertyId();}
public void setItemPropertyId(int i, ItemProperty tip)
{tip.setItemPropertyId(i);}
but when I try to submit the form, I get this error:
<ERROR>
java.lang.NullPointerException
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
ils.java:497)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
ils.java:410)
at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUti
ls.java:729)
at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.jav
a:780)
at
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:793)
at
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)
</ERROR>
which I assume is coming from the fact that I don't have all the right
getters and setters available, since it must be trying to call one that
does not exist (thus the null pointer).
Is this right?
Should I have other getters and setters?
THANKS FOR ANY HELP!!
Cameron
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org