• 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

Skip validation when form not submitted

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

how would you, using struts, create a form with validation (using the validator framework) and skip this validation when the form would be accessed without being submitted.

So let's say I have a form with 1 required field under /MyForm.do:

1. call /MyForm.do
2. empty form shows
3. user enters the data & submits the form to /MyForm.do
4. validator framework checks whether the required field has a value
5. if yes, action is executed

How would you do this in struts?
 
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which struts version you were using?
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 1.2.7
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

r vertet wrote:skip this validation when the form would be accessed without being submitted


What do you mean by this? The steps you have mentioned in this post is how it works out normally, what is that we need to do differently?
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shankar Tanikella wrote:

r vertet wrote:skip this validation when the form would be accessed without being submitted


What do you mean by this? The steps you have mentioned in this post is how it works out normally, what is that we need to do differently?



No, if I add some validation to a form (like required field) then when I access the form the first time (that is, without a submit) the validation fires and shows a message like 'Field X is required'.
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

r vertet wrote:(that is, without a submit) the validation fires and shows a message like 'Field X is required'

No, This should not happen. Struts provide javascript and server side validation, which one are you exactly talking about? Do you get a javascript alert? If yes, post your JSP code here.
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is pure server-side validation.

The following code shows an error-message when I first access the form via /TilesDemo.do:



Maybe the solution for my problem is in the "Multi Page Forms"?
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody?
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vertet, Could you post the action class method that you are using?
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The action is quite irrelevant because it is prevented from being executed by the validator. Anyway it is almost empty:

 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
server-side validate(ActionMapping mapping, HttpServletRequest request) in your scenario won't execute..

Because you did not specify validate="true" attribute in the action tag.

check your action tag once..
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vipul bondugula wrote:server-side validate(ActionMapping mapping, HttpServletRequest request) in your scenario won't execute..

Because you did not specify validate="true" attribute in the action tag.

check your action tag once..



validate="true" is the default, besides validation is firing. That is NOT the problem (please read the thread before you reply)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic