File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Need Some Help Regarding the Validation -- Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need Some Help Regarding the Validation -- Struts2" Watch "Need Some Help Regarding the Validation -- Struts2" New topic
Author

Need Some Help Regarding the Validation -- Struts2

Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
I am new to struts2 and I am confused as to which validation framework to be used.


I have a page where I show number of users in the tabular form like.


FIRST NAME1, LAST NAME1 , EMAIL1
FIRST NAME2, LAST NAME2 , EMAIL2

each one of which could be modified and saved, the save works in one go and updates all the records or creates new. I do not have any issue with the data save or display.




I am using struts library to display it on the page.


<s:iterator value="contacts" status="stat">


<tr>
<td><s:textfield name="contacts[%{#stat.index}].firstName" label="FIRST NAME" /></td>

<td><s:textfield name="contacts[%{#stat.index}].lastName" label="LAST NAME" /></td>

<td><s:textfield name="contacts[%{#stat.index}].email" label="email" /></td>
</tr>

<tr> .... </tr> <!-- one row for every record -->
<tr> .... </tr>




</s:iterator>




I am setting the contacts collection in the action class as below.

private List<Contact> contacts

Please assume the usual getter and setters.




I want to validate that the email id that is entered is valid email, or for that matter phone number entered for every individual user is numeric.


It seems to me that I won't be able to use the field validation in this case rather than I will have to use the generic validation. Although I will prefer the first one.


Please advise.
Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
I am unable to get one standard framework to handle the problem at hand.


Any suggetion will be welcome, however high level it is.



Thanking in advance.
Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
I could do this by creating a mehtod named

validate + <save method name >

in the action class

and using something like this in that method

addFieldError("contacts[" + i + "].officeNumber", "this is not a valid number");

This helped me a lil bit, but editor sidestpped the validation here too

http://faq.javaranch.com/java/IndexedProperties
Trinh HUy Minh
Greenhorn

Joined: Sep 01, 2008
Posts: 1
nanimonai
Jeff Hill
Greenhorn

Joined: Aug 24, 2008
Posts: 11
Arun,
Could you post your ActionClass-validation.xml descriptor?
 
Don't get me started about those stupid light bulbs.
 
subject: Need Some Help Regarding the Validation -- Struts2
 
Similar Threads
struts2 tag ?
STRUTS2 Tabbed interface problem with Tiles tag in IE6
JSF Datatable equivalent in Struts2
substitute for DynaActionForm in struts2
How to get Iterating value in a list of VO struts2