JSF中的嵌套表单

问题描述:

我正在尝试使用< rich:tabPanel> ,并在每个标签上添加表单。 Facelet看起来像

I am trying to use <rich:tabPanel> with form on each tab. Facelet looks like

      <h:form>
      <rich:tabPanel switchType="ajax">
        <rich:tab>
          <f:facet name="header">
            <h:outputText value="Form1" />
          </f:facet>
      <ui:include src="form1.xhtml" />
        </rich:tab>
        <rich:tab>
          <f:facet name="header">
            <h:outputText value="Form2" />
          </f:facet>
          <ui:include src="form2.xhtml" />              
        </rich:tab>
      </rich:tabPanel>
      </h:form>

formX.xhtml 拥有它自己的 ViewScoped 托管bean(formXBean)和典型语法,如

formX.xhtml has it's own ViewScoped managed bean (formXBean) and typical syntax like

<ui:composition>
  <h:panelGroup rendered="#{formXBean.show}">
    <h3>FormX list</h3>
    <h:form rendered="#{not empty formXBean.list}">
      <h:dataTable value="#{formXBean.list}" var="item">
        <h:column><f:facet name="header">field1</f:facet>#{item.subject}</h:column>
        <h:column><f:facet name="header">field2</f:facet>#{item.mload}</h:column>
        <h:column><f:facet name="header">actions</f:facet>
          <h:commandButton value="Edit" action="#{formXBean.edit(item)}" />
          <h:commandButton value="Delete" action="#{formXBean.delete(item)}" />
        </h:column>
      </h:dataTable>
    </h:form>
    <h:panelGroup rendered="#{empty finalMarksBean.list}">
      <p>No records.</p>
    </h:panelGroup>
    <h:form>
      <center><p>
        <h:commandButton value="Add" action="#{formXBean.add()}" />
      </p></center>
    </h:form>
  </h:panelGroup>
  <h:panelGroup rendered="#{formXBean.edit}">
    // Add (edit) record form
  </h:panelGroup>
  <h:panelGroup rendered="#{finalMarksBean.delete}">
    // delete record form
  </h:panelGroup>
</ui:composition>

如果我使用formX.xhtml而没有放入 rich:tab ,它有效。当我将它包含在 rich:tab 中时 - 它不起作用。我认为,嵌套表格是原因,但我该如何解决呢?我在哪里可以找到这种情况的典型解决方案?

If I using formX.xhtml without placing into rich:tab, It works. When I include it into rich:tab - It doesn't work. I think, that nested forms is the reason, but how can I workaround it? Where can I find typical solution for this case?

不要使用嵌套的 h:form 。从包含的xhtml文件中删除 h:form 。如果需要数据包装器,则可以使用面板(例如 a4j:outputPanel )。

Don't use nested h:form. Remove h:form from included xhtml files. If you need wrapper for data, then you can use panel (for example a4j:outputPanel).