• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Forms (in request scope!)

 
Nicolas Zeitlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. Let me get straight to the point.
I've got a JSF page with 3 �s, each one of them with their own submit . Being in request scope, there's Backing Bean construction information being passed in hidden elements - i.e.


Now, my problem is obvious: Having 3 forms, I need to have one hidden input for each one of them, so that it's value is submitted to the request parameter map. But the id's of each one of these hidden elements has to be different, because of DOM standards (2 elements cannot share the same name).

So I've got 3 forms, with 3 hidden inputs, all of them used to pass on to the Backing Bean the (e.g.) userId. Only in the Backing Bean, I don't know anymore what's the element id with the userId (could be any one of them 3).

And that's my problem: Am I approaching this all wrong, or is there some magic keyword/method/Class I'm forgetting?

Thank you all.
 
Adam Mazurek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to specify the id attribute for these hidden fields? When you specify them like: id="formId:hiddenId" then they should have unique names.
 
Nicolas Zeitlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adam. Thanks for your reply.
I can indeed give them different id's. But since these hidden elements are used by the backing bean constructor, then its code would end up something like this:


In case anyone reading this is wondering why, I've got multiple forms because I need selective validation (i.e. each form has different input's as required="true" and each submit should consider only that form's prerequisites).

Thanks again.
Nicolas Zeitlin
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each submit does consider only that form's prerequisites. The JSF form is built on HTML FORM, and if you have multiple HTML forms on a page, only the fields in that form are submitted - the other forms are ignored.

You can share a bean with multiple forms or have a discrete bean for each form on the page, whichever works best for you. Or combine the two, using complex field references.
 
Nicolas Zeitlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim, and thanks for your interest.

I reread my post and I think I wasn't clear. With prerequisites I meant those tags that had required=true. I.e.


You see, I've got diferent forms, and it'd make no sense that each one of them should have all it's required attributes filled out when submitting either one. I want these field to be mandatory when submitting the form they're in.

Let me know if you think I'm going through this the wrong way.
Thanks again.
Nicolas Zeitlin
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm. I'm not sure about the need for hidden fields, since you can determine which form did the submit simply by using different action methods for each form. Unless you just need to pass something from the app the the client and back again due to scope issues.

The id attribute is used in JSF to permit elements to refer to other elements on the page, which is one reason why it has to be unique (that and fundamental XML restrictions).

I shouldn't think that the "required" attributes for other forms would be checked (or even checkable), since, as I said, the form is basically submitted without respect to the other forms. However, if JSF is throwing some extra context in, I could see it happening. What happens when you try the easy approach and just code it that way?

If there is some cross-form validation going on, I'd say that you'll need a listener inserted into the submit process to sort things out.
 
Nicolas Zeitlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim!
You're right, it's because of scope issues. And just like you, I had expected the "required" validation to happen only for the submitted form. But nope, that's not what happens: indeed, every form in the JSF page is validated. For what I read, this is because JSF design is usually thought of as one-form-per-page.

Anyway, this is not something I can do (1 form/page), and by now I'm even considering not using the "required" attribute.

What do you mean with 'listener'? Do you see that somehow an action listener might help solving this problem?
Thanks again!!
Nicolas Zeitlin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!