This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes validwhen using indexedListProperty throwing NulPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validwhen using indexedListProperty throwing NulPointerException" Watch "validwhen using indexedListProperty throwing NulPointerException" New topic
Author

validwhen using indexedListProperty throwing NulPointerException

K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
I am trying to validate fields in a table. When one field is present, I need to ensure that the other fields in that row are present. Here is my jsp:
<logic:notEmpty name="myForm" property="beanList">
<table class="basic-table">
<TR class="blue-med-table">
<th><bean:message key="label.testcasename" /></th>
<th><bean:message key="label.duration" /></th>
</TR>
<logic:iterate name="myForm" property="beanList"
id="beanList" indexId="i">
<%if (i.intValue()%2 == 0){%>
<tr>
<%}else{%>
</tr>
<tr class="even">
<%}%>
<TD><html:hidden name="beanList" property="testCaseOID"
indexed="true" /> <html:text name="beanList" property="testCase"
size="30" maxlength="128" onchange="trimString(this)"
indexed="true" /></TD>
<TD><html:text name="beanList" property="duration" size="3"
maxlength="3" onchange="trimString(this)" indexed="true" /></TD>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>

Here is my validation:

<field property="testCase" indexedListProperty="beanList" depends="validwhen">
<arg0 key="Test Case" resource="false"/>
<var>
<var-name>test</var-name>
<var-value>((editButton == null) or ((beanList[].testCaseOID == null) or (*this* != null)))</var-value>
</var>
</field>

And here is the exception I get when I try to load the page:

java.lang.NullPointerException
at org.apache.commons.validator.Field.getIndexedProperty(Field.java:796)
at org.apache.commons.validator.Field.validate(Field.java:891)
at org.apache.commons.validator.Form.validate(Form.java:174)
at org.apache.commons.validator.Validator.validate(Validator.java:367)
at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:110)

I'm using this exactly the way the struts validator web site instructs. Please help me figure out what is wrong!
K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
Never mind, i figured it out. The validation was happening whe the page loaded, and the list had not yet been initialized. I made a separate action mapping for loading the page, and it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validwhen using indexedListProperty throwing NulPointerException