• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error handling JSF Form Divisions

 
Ramesh Kumar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have different divisions in my JSF page like (Patient Info one divison, Surgery info one division). Both divisions are there on the same form. I want to validate only one division at a time while sumbit.

What I mean is
1) Validate Pation Info Section only when user clicks save on patient Info
2) Validate Surgery Info only when user clicks save on Surgery Info

Now it is showing errors related to both sections.

Please help me.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should place each form in its own h:form.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF forms are built on the HTML FORM infrastructure and therefore subject to the same basic rules. In HTML, each FORM is considered individually. When you click on the form's submit button, only data defined within that form is transmitted to the server - consequently, server-side validation is only possible for the items within that form.

In other words, not only is the behavior you're describing the default behavior, you don't even have a choice. That's how it's going to behave. And, correspondingly, if someone clicks a submit button on one form that responds with a new page, data entered in other forms on the original page will be discarded when the old page is replaced with the new page.

These days you can alter that sort of behavior by using client-side logic such as JavaScript/AJAX. Not only can you explicitly code JavaScript to peek outside forms, some of the new JSF tag libraries generate their own outside-peeking code. What they actually do is modify the DOM structure of the submit in order to include data that wasn't in the original DOM representation of the HTML form. Of course, the server has to be expecting this sort of behavior, but that's usually not hard to allow for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!