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
).
Nested forms in JSF
-
16-06-2023 - |
Question
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
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>
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?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow