wood burning stoves 2.0*
The moose likes JSF and the fly likes validating a form being submitted by 2 actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "validating a form being submitted by 2 actions" Watch "validating a form being submitted by 2 actions" New topic

validating a form being submitted by 2 actions

Marlon Tong

Joined: Jul 14, 2009
Posts: 6
Hi guys,

I have a page with form elements that are submitted through 2 different actions that are in the same Controller. My problem is that I need it to validation differently depending on which action was triggered. One action should have every form element mandatory, while in the other, only 2 of the form elements would be mandatory.

Is there a way to implement this in JSF?

viswanath yadav

Joined: May 25, 2009
Posts: 15
Can you post the code and give me the problem clearly ?
Marlon Tong

Joined: Jul 14, 2009
Posts: 6
here it is, forgive the messy codes (i didn't write them)

there's 2 h:commandButtons near the bottom of the code that trigger different actions. right now, both validate the same way since they submit the same form (all except the comments are mandatory). what i need is that if the second button ("Validate") is triggered, only the 2 t:inputFileUpload are mandatory, all else should be ignored in the validation process.

Gerbrand van Dieijen
Ranch Hand

Joined: Nov 28, 2008
Posts: 30
Creating two forms would probably be the easiest solution, and be less error-prone. Another way would be making all the fields optionally (required='false') except the inputFileUpload. Of course then the fields are optionally for the other button as well, but then you could manually check if the mandatory field are filled in, in the action method itself. Latter solution s a bit dirty, but might be appropriate.
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

The simplest solution I have is to check which action is invoked and depending on that all the validations will be done. So in this case you will not be sung custom validations.

You have to write validation methods yourself.

Making a new Form just for this seems to be a bad idea.. The functionality can be easily done in backingBean as we have some limitation which is stopping us from using JSF provided validators.

My Blog SCJP 5 SCWCD 5
Marlon Tong

Joined: Jul 14, 2009
Posts: 6
Hi guys,

Right now the solution I implemented was having all the validations done by the action. I find it dirty since we don't get to use the Validation phase of JSF and have all the validation done in the action.

Hoping to find a neater solution to the problem, if there's any. For now, the solution implemented works.

Thanks for the suggestions
I agree. Here's the link: http://aspose.com/file-tools
subject: validating a form being submitted by 2 actions
Similar Threads
Custom JSF2.0 ExceptionHandler
using inheritance in struts
intermediate submit and validation of a form
problem with struts2...
JSF Vs JavaScript