我的 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/