Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple forms in one page with JSF 2.0?

I try to use multiple forms with JSF 2.0 in one page. I use PrimeFaces 3.0M1 and trying to build an application with tabs and one form per tab.

I've got a page like the following:

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"                 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:fn="http://java.sun.com/jsp/jstl/functions" 
xmlns:p="http://primefaces.prime.com.tr/ui">

<div>
<p:tabView>
<p:tab title="Form1">
<h:form id="form1">
    <p:inputText id="txtInput" value="#{bean1.inputText}" />
    <p:commandButton title="Submit" value="Submit" actionListener="#{controller1.submitValues}">
</h:form>
</p:tab>
<p:tab title="Form2">
<h:form id="form2">
    <p:inputText id="txtInput2" value="#{bean2.inputText}" />
    <p:commandButton title="Submit" value="Submit" actionListener="#{controller2.submitValues}">
</h:form>
</p:tab>
</p:tabView>
</div>  
</html>

If I click on the submit button in tab 1, everything works like excpected. But, if I click on the button at the second tab, the command will not be executed in controller2.

What is the problem here? If I bind the execution command of button2 to button1 the command in controller2 is executed correctly, so I can exclude that there is a problem in the backing beans.

How can I solve this?

like image 929
flash Avatar asked Jun 09 '11 10:06

flash


2 Answers

The Primefaces wizard and tabview components must be enclosed by a single form.

There is no reason that you cannot have multiple Submit buttons within a tabview or wizard like this. Your confusion on this is likely because you concerned about the other properties of your managed bean that do not appear in the currently viewing tab.

like image 56
maple_shaft Avatar answered Nov 07 '22 19:11

maple_shaft


I think you can go for specifying "process" attribute of a button

try this. change your <h:form> tag and replace it with <h:panelGrid> and give their ID's as form1 and form2 and and change your 2 buttons like this

<p:commandButton title="Submit" value="Submit" actionListener="#controller1.submitValues}" process="@this,form1">

<p:commandButton title="Submit" value="Submit" actionListener="#controller2.submitValues}" process="@this,form2">

this will work. :) update me with your result

like image 26
amFroz Avatar answered Nov 07 '22 18:11

amFroz