• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Handling error messages (Struts2 jquery )

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
James Peter
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for help.


 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Welcome
 
money grubbing section goes here:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!