如何使用 JSF 2.0 在一个页面中使用多个表单?

发布于 2024-11-14 19:13:50 字数 1188 浏览 4 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光下的微笑 2024-11-21 19:13:50

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.

生生不灭 2024-11-21 19:13:50

我认为您可以尝试指定按钮的“process”属性


更改您的 标记并将其替换为 并将其 ID 指定为 form1form2 并像这样更改你的 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">

这样就可以了。 :)
告诉我你的结果

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

ゃ人海孤独症 2024-11-21 19:13:50

您可以创建一个项目列表,并用您想要在支持 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"/>

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"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文