Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用JSF2.0在一个页面中使用多个表单?_Java_Jsf 2_Primefaces - Fatal编程技术网

Java 如何使用JSF2.0在一个页面中使用多个表单?

Java 如何使用JSF2.0在一个页面中使用多个表单?,java,jsf-2,primefaces,Java,Jsf 2,Primefaces,我尝试在一个页面中使用JSF2.0中的多个表单。我使用PrimeFaces 3.0M1,试图构建一个带有选项卡的应用程序,每个选项卡一个表单 我有如下页面: <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

我尝试在一个页面中使用JSF2.0中的多个表单。我使用PrimeFaces 3.0M1,试图构建一个带有选项卡的应用程序,每个选项卡一个表单

我有如下页面:

<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>

如果我点击选项卡1中的提交按钮,一切都会像excpected一样工作。 但是,如果我单击第二个选项卡上的按钮,该命令将不会在controller2中执行

这里有什么问题?如果我将button2的执行命令绑定到button1,那么controller2中的命令将正确执行,因此我可以排除备份bean中存在问题


如何解决此问题?

Primefaces向导和tabview组件必须包含在一个表单中


没有理由在选项卡视图或向导中不能有多个提交按钮。您可能对此感到困惑,因为您担心当前查看选项卡中未显示的托管bean的其他属性。

我认为您可以指定按钮的“进程”属性

试试这个。 更改您的
标签,并将其替换为
,将其ID设置为form1和form2,并像这样更改您的2个按钮

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

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

这将起作用。:)
使用您的结果更新我

您可以创建一个项目列表,并按您希望在支持bean中浏览的值填充它。将
标记放入
标记中,如下所示:

<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"/>

把表格的内容放在这里

我在对话框中添加了dynamic=“true”,并将表单保留在对话框中,解决了问题。如果整个向导只有一个表单,如何对提交的每个单独表单进行客户端验证?例如,如果我放置require字段,它将不允许我进入下一个选项卡,因为所有选项卡都在同一个表单中