java - 从多个表单提交

标签 java forms jsf primefaces submit

我的 jsf 应用程序中有多个表单,我想从其中一些表单提交数据以将数据保存在数据库中。

我的 xhtml 看起来像这样:

<h:panelGroup id="tempOptionGroup">
<h:form id="tempOptionForm" >
...
</h:form>
</h:panelGroup>

<h:form id="2Form" >
...
</h:form>


<h:panelGroup id="panel">
<h:form id="3Form">
...
</h:form>
<h:panelGroup>

<h:form id="buttonForm">
<p:commandButton value="Submit"
action="#{Bean.callPersist}" style="margin-top:5px"
id="submit" />
</h:form>

如何使用一个 p:commandButton 提交所有这 3 个表单

更新

我查找了 h:commandButton 的一些属性,我读到 process=":tempOptionGroup:tempOptionForm" 将处理第一个表单,这是否也适用于多个表单表格?

最佳答案

如果你真的需要这个,你可以做一些事情,比如在单击按钮时使用 javascript 提交其他表单(是的,你可以这样做,因为你的 commandButton 是基于 ajax 提交的),为此你应该使用 'onclick' commandButton 并用表单对象调用“submit”(document.getElementById('formid').submit())。除此之外,我不认为 commandButton 本身可以为您做任何事情。

粗略示例:

    <script>
        function submitOthers(){
            document.getElementById('form1').submit();
            document.getElementById('form2').submit();
        }
    </script>

    <h:form id="form1">
    </h:form>
    <h:form id="form2">
    </h:form>
    <h:form id="form3">
        <p:commandButton onclick="submitOthers()" ></p:commandButton>
    </h:form>

如果刷新页面,您可以(丑陋地)在每个表单中添加隐藏的命令按钮,并执行类似的 javascript 来获取按钮并对其调用 click() 。在这种情况下,提交将是 ajax。

<小时/>

但是,由于您的 View 看起来是同质的,因此您可以将树形表单替换为单个表单,其中包含按钮(如果不需要三个表单...)。

关于java - 从多个表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16986480/

相关文章:

java - 每个请求都会创建注入(inject) @Model bean 的 EJB (GlassFish)

java - 使用什么策略来确定 JSON 或 XML?

forms - Symfony2 - 将 CSS 类添加到扩展的选择字段(单选)

javascript - 从我的网页发送电子邮件时出错

java - JBoss Seam : In ScopeType. PAGE 我得到 : java. lang.IllegalStateException:没有 Activity 的对话上下文

javascript - 从 JSF 访问 Javascript 变量

java - 正则表达式导致模式语法异常

java - 如何在mongoDB中批量插入

java - java.awt.Robot.createScreenCapture 的更快替代品?

javascript - 检查输入类型并跳过输入 'password' 字段,同时单击“保存”