aspose file tools*
The moose likes Struts and the fly likes Handling error messages (Struts2 jquery ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Handling error messages (Struts2 jquery )" Watch "Handling error messages (Struts2 jquery )" New topic
Author

Handling error messages (Struts2 jquery )

James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
Hi All,

I have a StudentAction class and 2 methods within it.
1. Login
2. Enroll

From browser I want to call these methods using jquery post method. like below



Now I want to validate name and password fields. If they are invalid I need to send back custom message.
Same activity I need to do even for Enroll method (validating fields).

Now my query is how can i send validation message to browser and also how to retrieve the same at browser end.
can we have different validation interceptors for different methods in the action class?

Please let me know if any one is having solution.

Thanks
Peter
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

James Peter wrote:

Since you are using struts2Jquery, there is no need to write JQuery code to call an action class. I hope this link would be helpful.


A.A.Anbarasu
James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
Hi Thanks for reply.

In my webpage I want to call action method without using a submit button. Scenario is like below.

1. I am having a form with action url set to enroll a student. Within a form i have student name,age etc. and also a search panel where user can enter his new userid. There is a submit button also to submit the form.

2. user key in userid in a text field and press "Check availability" button. This button is not a submit button. So I am using a button click event and in the function I am calling availability method in StudentAction class. I am using JQuery for this (Please let me know if there is a good approach). I do not prefer to put form within a form.

3. Example provided in the given link is like below


but I need to use regular expressions to validate user input. How can i achieve this in the above method of validation? Please let me know.


Thanks
Peter

Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

@2. Writing the JQuery code to call an action is fine. But you can have any number of submit (JQuery or Struts2) buttons that calls different actions. So Writing the JQuery code to call an action is extra work.
@3. Example given in the link is using annotated version. regex validation is supported in annotated, using an xmlversions too . Also you can validate by overriding the validate ().
James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
Hi,

Could you provide me any resource or example which illustrates your below point.

you can have any number of submit (JQuery or Struts2) buttons that calls different actions.

Thanks in advance

Peter
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

You can use the 'href' attribute of JQuery submit button. Unfortunately i don't have/know any resource/example as of now. You may try code.google.com/p/struts2-jquery link.
James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
Hi,

Thanks for help.


Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

You are Welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Handling error messages (Struts2 jquery )