如何使用 JSF 2.0 在一个页面中使用多个表单?
我尝试在一页中使用 JSF 2.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 中的提交按钮,一切都会按预期进行。 但是,如果我单击第二个选项卡上的按钮,该命令将不会在controller2中执行。
这里有什么问题呢?如果我将button2的执行命令绑定到button1,则controller2中的命令将正确执行,因此我可以排除支持bean中存在问题。
我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Primefaces 向导和选项卡视图组件必须包含在单个表单中。
没有理由不能在一个选项卡视图或向导中拥有多个提交按钮。您对此感到困惑可能是因为您担心托管 Bean 的其他属性未出现在当前查看的选项卡中。
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.
我认为您可以尝试指定按钮的“process”属性
。
更改您的
标记并将其替换为
并将其 ID 指定为 form1 和 form2 并像这样更改你的 2 个按钮,这样就可以了。 :)
告诉我你的结果
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 thisthis will work. :)
update me with your result
您可以创建一个项目列表,并用您想要在支持 bean 中浏览的值填充它。将
标签放入
标签中,如下所示: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: