2011-06-09 51 views
7

我尝试在一个页面中使用JSF 2.0的多个表单。我使用PrimeFaces 3.0M1并尝试使用制表符和每个制表符的一种形式构建应用程序。如何在JSF 2.0的一个页面中使用多个表单?

我有一个页面类似如下:

<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。 但是,如果我点击第二个选项卡上的按钮,该命令将不会在控制器2中执行。

这里有什么问题?如果我将button2的执行命令绑定到button1,controller2中的命令就会正确执行,所以我可以排除后备bean中存在问题。

我该如何解决这个问题?

回答

1

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

没有理由不能在这样的tabview或向导中有多个Submit按钮。您对此的困惑很可能是因为您担心您的托管bean的其他属性未显示在当前查看选项卡中。

+0

如果我只有对整个向导一种形式,哪能每个单独的形式在客户端验证所提交?例如,如果我要求字段,它将不会允许我继续到下一个选项卡,因为它全部在同一个表格中 – Erick 2015-09-08 21:09:43

1

我觉得你可以去指定的按钮

试试这个的“过程”属性。 更改<h:form>标签,并与<h:panelGrid>替换它,并给予相应的ID为Form1中窗口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"> 

这将工作中的2个按钮。 :) 用你的结果更新我

+0

我在对话框中添加了dynamic =“true”,并保存在Dialog内部,它解析了问题。 – tom 2015-07-01 21:09:43

0

你可以创建一个项目列表,并用你想要在你的支持bean中浏览的值来填充它。把<h:form>标签中<ui:repeat>标签是这样的:

<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"/> 
相关问题