File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Skip validation when form not submitted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Skip validation when form not submitted" Watch "Skip validation when form not submitted" New topic
Author

Skip validation when form not submitted

r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
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

Joined: Aug 01, 2007
Posts: 485

which struts version you were using?


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Struts 1.2.7
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

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?


Have Fun with Java
little,little.. little by little makes a lot..
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
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

Joined: Jan 30, 2011
Posts: 329

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

Joined: Apr 10, 2012
Posts: 17
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

Joined: Apr 10, 2012
Posts: 17
Anybody?
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Vertet, Could you post the action class method that you are using?
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
The action is quite irrelevant because it is prevented from being executed by the validator. Anyway it is almost empty:

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
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..


Thanks
Vipul Kumar
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
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)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Skip validation when form not submitted
 
Similar Threads
How Do You Use Struts Validator For Non Required Field?
Struts Validator Framework:1 action class, 1 form, different fields validation
which is best, stuts validator or javascript
DynaValidatorForm - Double fields are never null!
How to perform validation conditionally ?