• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validating a form being submitted by 2 actions

 
Marlon Tong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,
Marlon
 
viswanath yadav
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code and give me the problem clearly ?
 
Marlon Tong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marlon Tong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic