struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hugh111111 <hughroa...@yahoo.co.uk>
Subject Re: Validation of indexed properties
Date Fri, 26 Feb 2010 17:14:54 GMT

Sorry Cielpa, my mistake. 
Turns out there is such a thing as a DynaValidatorActionForm. Shows how much
I know.

Hugh



hugh111111 wrote:
> 
> Hi Cielpa,
> 
> 'Invalid property' would suggest that your form does not contain the
> property searchList. It is difficult to tell without a bit of background
> and seeing some code. Can you explain what you are doing and show me your
> struts-config.xml file.
> 
> By the way, your form should be declared as a DynaValidatorForm. There is
> no such thing as a DynaValidatorActionForm. 
> 
> For example..
> 
> <form-bean name="myForm"
> type="org.apache.struts.action.DynaValidatorForm">
>     <form-property name="searchList" type="java.util.ArrayList"/> 
> </form-bean>
> 
> 
> 
> Hugh
> 
> 
> 
> 
> Cielpa wrote:
>> 
>> Hey,
>> 
>> I have a similar problem with DynaValidatorActionForm.
>> It says that invalid property when i have a ArrayList in the
>> <form-property name="searchList" type="java.util.ArrayList"/> in the
>> <form-bean declaration.
>> 
>> Any idea?
>>  Thanks and your help is appreciated.
>> Silpa
>> 
>> hugh111111 wrote:
>>> 
>>> I've got a problem relating to the validation of indexed properties in
>>> Struts 1.1
>>> I get the following error message when I try to access an ArrayList of
>>> students in my DynaValidatorForm
>>> 
>>> root cause 
>>> 
>>> java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
>>> java.util.ArrayList.RangeCheck(Unknown Source)
>>> java.util.ArrayList.get(Unknown Source)
>>> org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:298)
>>> 
>>> 
>>> 
>>> Here is some background to the problem...
>>> 
>>> In my session I have an ArrayList called studentsList of objects of type
>>> experiment.mybeans.Student. A Student object has getter and setter
>>> methods for id, year and gradeAverage.
>>> 
>>> In my students.jsp I create a table by iterating through my student
>>> objects like this...
>>> 
>>> <c:forEach var="students" items="${sessionScope.group.studentsList}" >
>>>   <tr><td><html:text indexed="true" name="students" property="id"/></td>
>>>   <td><html:text indexed="true" name="students" property="year"/></td>
>>>   <td><html:text indexed="true" name="students"
>>> property="gradeAverage"/></td></tr>
>>> </c:forEach>
>>> 
>>> As you can see the table contains empty text boxes and I would like to
>>> validate these have been filled in, so in struts-config.xml I create my
>>> dynavalidatorform as follows...
>>> 
>>> <form-bean name="studentsForm"
>>> type="org.apache.struts.validator.DynaValidatorForm" >
>>>     <form-property name="students" type="java.util.ArrayList" />
>>> </form-bean>
>>> 
>>> And in validation.xml I place my validation rules...
>>> 
>>> <form name="studentsForm"> 
>>>    <field property="id" indexedListProperty="students"
>>> depends="required">
>>>      <arg0 key="error.studentid.required"/>
>>>     </field>
>>>    <field property="year" indexedListProperty="students"
>>> depends="required">
>>>      <arg0 key="error.studentyear.required"/>
>>>     </field>
>>>    <field  property="gradeAverage" indexedListProperty="students"
>>> depends="required">
>>>      <arg0 key="error.studentgrade.required"/>
>>>     </field>
>>> </form>
>>> 
>>> Now here is where things start to go a bit pear-shaped
>>> 
>>> I have read somewhere online that I need to populate the form ArrayList
>>> before I get to my jsp page. So I have created an action class called
>>> PreStudentsAction.java which takes the student ArrayList out of the
>>> session and assigns it to the student ArrayList in the form before
>>> forwarding to the students.jsp page...
>>> 
>>> public class PreStudentsAction extends Action{
>>> 	
>>> 	public ActionForward execute(ActionMapping mapping,
>>> 			 ActionForm form,
>>> 			 HttpServletRequest request,
>>> 			 HttpServletResponse response)
>>> 			 throws Exception
>>> 	{
>>> 	
>>> 	DynaValidatorForm myForm = (DynaValidatorForm)form;
>>> 	Group group = (Group)request.getSession().getAttribute("group");
>>> 	ArrayList<Student> students = group.getStudentsList();
>>> 	
>>> 	myForm.set("students", students);	
>>> 	return (mapping.findForward("success"));
>>> 	}
>>> 
>>> }
>>> 
>>> 
>>> Finally when I run my application my table is displayed but when I fill
>>> in the table and press submit I get the IndexOutOfBounds error. It
>>> appears to me that the student ArrayList in the form remains empty and
>>> that my Action class was unsuccessful in populating the form's
>>> ArrayList.
>>> 
>>> Can anybody see what I'm doing wrong?
>>> 
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Validation-of-indexed-properties-tp27493794p27720956.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message