Dynamically loaded commandlinks not working

68 views Asked by At

I am trying to dynamically load a view using <f:ajax render=":component"/>. That part works with no problems. Using commandLinks in that view, however, does not.

Container that loads the target view dynamically:

<h:form>
    <h:commandLink>
        <f:param name="tmp2" value="tmp/newxhtml.xhtml"/>
        <f:ajax render=":newXhtml"/>
    </h:commandLink>
</h:form>

<h:panelGroup layout="block" id="newXhtml">
    <ui:include src="#{param['tmp2']}"/>
</h:panelGroup>

When clicking the commandLink, the tmp2 value is set and the 'newXhtml' is re-rendered through ajax.

This link is on the included .xhtml and is not working:

<h:form>
    <h:commandLink>
        <f:ajax listener="#{backingBean.sampleMethod}"/>
    </h:commandLink>
</h:form>

BackingBean.java:

public class BackingBean{

    public void sampleMethod() {
         //breakpoint here is never hit
    }

}
1

There are 1 answers

0
chzbrgla On BEST ANSWER

I got it to work when I'm not using <f:ajax> to include the page but rather use normal <h:commandLink> with the action attribute which will save the include page into a @SessionScope bean.

The including xhtml:

 <h:form>
    <f:ajax render=":newXhtml">
        <h:commandLink action="#{includeBean.setIncludePage('tmp/newXhtml.xhtml')}">
        </h:commandLink>
    </f:ajax>
 </h:form>


 <h:panelGroup layout="block" id="newXhtml">
    <ui:include src="#{includeBean.includePage}"/>
 </h:panelGroup>

The included .xhtml can stay the same.

And the backing bean for the include page:

@Named
@SessionScope
public class IncludeBean implements Serializable {

  private static final long serialVersionUID = 1L;

  private String includePage;

  @PostConstruct
  public void init() {
    includePage = "tmp/newxhtml.xhtml";
  }

  public String getIncludePage() {
    return includePage;
  }

  public void setIncludePage(String includePage) {
    this.includePage = includePage;
  }

}