Is it possible to process multiple forms with ajax call? Consider next example:
Server side:
@Component
@Scope("session")
public class TestBean implements Serializable {
private String field11;
private String field21;
private String output;
public void dummyAction() {
output = "Output: "
+ "field11=" + field11 + "; "
+ "field21=" + field21 + "; ";
}
public String getField11() {
return field11;
}
public void setField11(String field11) {
this.field11 = field11;
}
public String getField21() {
return field21;
}
public void setField21(String field21) {
this.field21 = field21;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
}
Client side:
<h:form id="f_1" name="f_1" >
<p:panelGrid id="pg_1" columns="1">
<p:outputLabel value="Form1" />
<p:outputLabel value="field11:" />
<p:inputText id="field11" value="#{testBean.field11}" />
<p:commandLink value="Process f_1 and f_2 from f_1"
process="@form :f_2" action="#{testBean.dummyAction}"
ajax="true" update="pg_1 :f_2:pg_2">
</p:commandLink>
<p:commandLink value="Process field11 and field21 from f_1"
process="@this field11 :f_2:field21" action="#{testBean.dummyAction}"
ajax="true" update="pg_1 :f_2:pg_2">
</p:commandLink>
</p:panelGrid>
</h:form>
<h:form id="f_2" name="f_2" >
<p:panelGrid id="pg_2" columns="1">
<p:outputLabel value="Form2" />
<p:outputLabel value="field21:" />
<p:inputText id="field21" value="#{testBean.field21}" />
</p:panelGrid>
</h:form>
When commandLink is clicked, only fields inside parent form are submitted.
Is it possible to process multiple forms when commandLink is clicked using process attribute?
If not, is there a workaround for this issue (I am thinking of remote command for each form but hoping there is a better and simpler solution)?
Working example of client side code using RemoteCommand which I would like to avoid:
<p:outputPanel autoUpdate="true">
#{testBean.output}
</p:outputPanel>
<h:form id="f_1" name="f_1" >
<p:panelGrid id="pg_1" columns="1">
<p:outputLabel value="Form1" />
<p:outputLabel value="field11:" />
<p:inputText id="field11" value="#{testBean.field11}" />
<p:commandLink value="Process f_1 and f_2 from f_1 using rc to process f_2"
onclick="rcProcessForm2();"
process="@form" action="#{testBean.dummyAction}"
ajax="true" update="pg_1 :f_2:pg_2">
</p:commandLink>
</p:panelGrid>
</h:form>
<h:form id="f_2" name="f_2" >
<p:panelGrid id="pg_2" columns="1">
<p:outputLabel value="Form2" />
<p:outputLabel value="field21:" />
<p:inputText id="field21" value="#{testBean.field21}" />
</p:panelGrid>
<!-- Remote command -->
<p:remoteCommand name="rcProcessForm2"
partialSubmit="true" process="@form">
</p:remoteCommand>
</h:form>