• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

validation annotation in struts-2

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my jsp,I have button...

On click of it I am generating a form with 2 textfields,1select ,OK,Cancel buttons...On OK,Cancel the form dissappears and this is since have enclosed all this in <div> tag....





in Action class...



But the problem is I am unable to validate these text fields in the div tag...what could be the reason? As seen above,I have declared variables with the same name as in div tag in my action class still the problem persists... How does the framework appproach something like this?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's being sent to the server on submit? Have you checked the actual request?
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not submitting anything as you could see, it's input type="button" !!!
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you have a form that's not submitting anything? That makes no sense.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's like this...

I have a table with 3 fields...I have "add" button below the table...

on click off Add i show up a form with 3 fields with OK,Cancal buttons...

On 'OK' I am just setting the 3 values entered in that form onto the table row...

I need to validate this form when there is a case the user clicks 'OK' without entering anyting... Hope it's clear now...


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not clear. If the form is being submitted, it'll be validated: that's why I asked what's actually being sent from the browser to the server.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the form is being submitted an AJax call is being made with the URL containing the 3 values in the form to Action class.From there the values are added to the DB.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the problem is that they're not being validated? What makes you say that?
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried adding the form without entering any values in the fields and it's setting null values to the table row instead of validating with the message I had put in the first message of this thread...what could be the reason??
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you trying to display the validation messages?
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like this...



They would be displayed just below the field . i.e if it is skipped it would display the message in the annotation like "conceptName Field is Required" as shown above...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I mean how are you trying to display the errors to the user.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a text below the field that is to be validated.... ie I have 3 fields one below the other.
I entered last 2 fields and 1st is empty then, on button click for form ,a message should be displayed below the 1st field saying that is empty...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not understanding what I'm asking: you don't have anything to display any error messages.

If this is an Ajax submission you need to do that manually. How are you doing it?
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

you don't have anything to display any error messages.






In the above one 'message' parameter is my error message... It gets displayed below the field attached to that...

Yes it is an Ajax submission.what should be done thn?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're saying you *want* it to be displayed below each submission, because right now, it's not.

You'd need to return an object containing any validation messages--they're available in the response JSP, but since you're doing all the Ajax/JavaScript outside of the Struts 2 framework you'd have to build up that object in some way. You haven't even said how you're doing the Ajax submission.

Why not take a look at how "stock" Struts 2 does its validation, learn where the error messages are stored, and figure out how to craft an Ajax response containing those messages?
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but since you're doing all the Ajax/JavaScript outside of the Struts 2 framework you'd have to build up that object in some way. You haven't even said how you're doing the Ajax submission.



My Ajax call is in my jsp which in struts-2 framework.

You haven't even said how you're doing the Ajax submission.



As described earlier, I have a button 'add' on click produces a form(which is to be validated) containing 3 fields with buttons 'OK' and "Cancel".
On click of 'OK' button this form is submitted using an Ajax call and the 3 values are added to the DB and also to the table on the UI and the form is then hidden.


Why not take a look at how "stock" Struts 2 does its validation, learn where the error messages are stored, and figure out how to craft an Ajax response containing those messages?



------> Any links for this? I have never heard "stock" struts-2 ...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With WHAT are you making your Ajax call? Magic? Dojo? jQuery? Prototype?

"Stock" Struts 2 means default Struts 2. Struts 2 has Ajax validation built in. You're not using it. So you have to tell us how you are doing it, otherwise I don't see how anybody can help.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

With WHAT are you making your Ajax call?



Iam not using any Javascript framework... I am making the call in a normal Javascript function.

Struts 2 has Ajax validation built in



I would check this one out...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so in your "normal" JavaScript function, you'd have to deal with the data returned by the Ajax submit. And in your action's result, you'd have to craft a meaningful response. Since you want error messages to be associated with fields, it'd probably be easiest to return a JSON object containing field names mapped to their associated errors. Then in your Ajax response method you'd need to display the error messages near their associated fields.

All that would be a *lot* easier if you'd use a JavaScript framework.
 
reply
    Bookmark Topic Watch Topic
  • New Topic