开发者

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

开发者 https://www.devze.com 2023-03-12 04:16 出处:网络
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 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" xml开发者_如何学Pythonns: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?


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.


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


You can create a list of items and fill it by values you want to browse in your backing bean. Put the <h:form> tag in <ui:repeat> tag like this:

<ui:repeat var="item" value="#{backingBean.items}">
   <h:form>
    Put here the content of your form
   </h:form>
</ui:repeat>
<p:commandButton value="Submit" action="desired action"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消