Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Skip validation when form not submitted

 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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?
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which struts version you were using?
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 1.2.7
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Anybody?
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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:

 
vipul bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • 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
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic