aspose file tools*
The moose likes JSF and the fly likes How to avoid 2nd form submission in case the First one is submitted and vice versa? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to avoid 2nd form submission in case the First one is submitted and vice versa?" Watch "How to avoid 2nd form submission in case the First one is submitted and vice versa?" New topic
Author

How to avoid 2nd form submission in case the First one is submitted and vice versa?

Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41
Hi,

I have a JSP a page that have two JSF form(<h:form>)
The 1st one has some input fields and a submit button
The 2nd one has some drop down.


When I tried to submit the 1st form, the 2nd one also gets submitted along with it and vice versa.
I was thinking to use <iframe> for each from. But, the <iframe> concept is not in JSF.

What I can do to avoid this performance issue?
Please, suggest me.

Regards
Gautam

Ravi Iyer
Ranch Hand

Joined: Oct 24, 2010
Posts: 49
Is there a specific reason you need two forms on the page?
Can't you have a single form and a corresponding bean instead and based on the data submitted, decide how to process the response in the corresponding server side method?
Multiple forms on a single page is usually not a very desirable design, unless you are doing that for a very specific reason.

Rgds


~ Ravi Iyer, SCEA
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
Ravi Iyer wrote:Multiple forms on a single page is usually not a very desirable design, unless you are doing that for a very specific reason.
I was not aware of that. Why is it so? I have had many occasions when I have used multiple forms on one html page without problems and have never attempted to make just one single form to accomplish everything. So why are multiple forms considered bad design? Can you give us an example where it causes problems?

Gautam Ry: Could you show us your code? Maybe we can see what the problem is. One thing that comes to mind immediately is that you can not nest the forms i.e. it is not allowed to have a form inside a form. So are your forms separeted as they should be?
Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41

Thanks for your response.

My code is below
JSP


Backing Bean



Regards
Gautam
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
I can see why it is hard to debug this code

If I understand the code correctly you do not use normal ways to send these forms. The first form has a commandButton but it only callls javascript method openSearchDtls() and since we do not know what this method does we have no way of knowing what happens next. And it comes to mind that since JSF does not know beforehand where it is going to send that form (as it normally would) thats why you have this problem.

Your second form has a commandButton but it is hidden so I guess it too is not used to send the form the normal way. And I do not see how the form is sent at all but that may be because I do not know how the tags you use (I am not familiar with the IBM taglibs at all) work behind the scenes (do they send the form using ajax or what?).

Sorry I can not help you more here
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16236
    
  21

That does not make sense. JSF forms are built on HTML forms and HTML forms are containers for submit data. You can only submit one form per request and ONLY the controls on that form are submitted - the other forms (if any) on the page do not participate. The only exception to that rule is when user-supplied JavaScript code dynamically modifies what controls are in the form prior to submit in order to "piggyback" information. So form2's data should NOT be submitted when you click a commandButton or commandLink on form1 and vice versa.

Two observations, however:

1. I've seen a lot of trouble ensue when people attach JavaScript to submit buttons for anything creative. I prefer to limit my onsubmit code to basic stuff like "Are you sure?" queries that control whether the submit gets done or not, rather than active client-side logic. Plus, if people have JavaScript turned off, you can end up with total chaos. The problem gets even worse when working with advanced JSF frameworks which may be inserting JavaScript of their own unless you take the proper precautions.

2. Almost never is it a good idea to use JSTL on a JSF View. And, if you scan some of the pleas for help people have made in this forum, you might even get the impression that JSTL is more trouble than it's worth when mixed with JSF.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to avoid 2nd form submission in case the First one is submitted and vice versa?