• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Some Help Regarding the Validation -- Struts2

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nanimonai
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arun,
Could you post your ActionClass-validation.xml descriptor?
 
reply
    Bookmark Topic Watch Topic
  • New Topic