Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Some Help Regarding the Validation -- Struts2

 
Arun Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nanimonai
 
Jeff Hill
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,
Could you post your ActionClass-validation.xml descriptor?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic