Question

I am working on an enhancement project. There is a parent <form> element. I have an XHTML file included inside this parent form. The included XHTML file has an <a4j:commandLink>. This action is not getting called. Now, this will work if i wrap the <a4j:commandLink> inside an <h:form>. This way, the parent form's action is called as well as the <a4j:commandLink>'s action. But nesting forms is not encouraged. I can't use the parent form's action because it goes to a servlet and my action is in a request scoped bean. I cant access the bean in the servlet. Any help on how to make the action call without the <h:form> is highly appreciated. Here is how it looks like:

    <form id="parentFormId" name="parentFormId" action="aservletaction">
      <a4j:outputPanel id="includedRegion">

        <ui:include src="setupView.xhtml"></ui:include>
     </a4j:outputPanel>
   </form>

Contents of setupView.xhtml:

<ui:composition>
   <a4j:outputPanel>
        <h:form>
        <a4j:commandLink action="#{myBean.actionMethod}"
          render="adatatableid" limitRender="true"/>
        </h:form>
</ui:composition>
Was it helpful?

Solution

RichFaces components have to be inside a form otherwise they won't work (at least the executable ones).

Now, <a4j:commandLink> (and commandButton) executing the whole form is the default behaviour, to change it use the execute attribute:

<a4j:commandLink execute="@this" … >

This will limit the execution only to the link.

OTHER TIPS

It ought not work. Do not nest forms, as its not legal in HTML in general and in HTML code rendered by JSF in particular. So, you've got a following construct in your code:

<form>
    ...
    <h:form>
        ...
    </h:form>
    ...
</form>

Get rid if it and it'll work as expected, i.e. by creating a plain form-to-form structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top