0

I have a list of commandLinks in a JSF page where each commandLink sets to the corresponding page in a content.xhtml page.

Problem: In the below list of commandLinks only the last one works successfully:

<ui:composition>
    <h:form>
      <ul class="nav nav-sidebar">
        <li>
            <h:commandLink value="Title1"  >
                <f:param  value="#{pageBean.setPage('title1')}" />
            </h:commandLink>
        </li>
        <li>
            <h:commandLink value="Title2"   >
                <f:param value="#{pageBean.setPage('title2')}" />
            </h:commandLink>
        </li>
        <li>
            <h:commandLink value="Title3"  >
                <f:param  value="#{pageBean.setPage('title3')}" />
            </h:commandLink>
        </li>           
     </ul>     
  </h:form>

Per How can I pass selected row to commandLink inside dataTable? Item Number 2, I understand that there is a need of accessing the request parameter map. Is this correct in this case with <f:param>? How can I set one page to be included below with the correct title page?

content.xhtml

<ui:composition>
    <div class="container-fluid">
        <div class="row">

            <div id="target" class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">                    
              <ui:insert name="content" >  
                <ui:include src="/WEB-INF/includes/#{pageBean.page}.xhtml" /> 
              </ui:insert>          
            </div>
        </div>
    </div>
</ui:composition>

PageBean

@ManagedBean
@ViewScoped
public class PageBean implements Serializable {

    private String page;

    @PostConstruct
    public void init() {
        page = "title1"; //  Default include.
    }

//getter & setter
}

Related to the problem: when PageBean is RequestScoped events inside title1 work properly but the commandLinks fail. when PageBean is ViewScoped event in title1 don't work and I have only the last commandLink working.

What am I doing wrong? Thanks.


EDIT (per below mentioned tutorial):

        <li>
            <h:commandLink value="Title1" action="#{pageBean.setPage}" >
                <f:param  name="action" value="title1" />
            </h:commandLink>
        </li>

The below method is NOT called

public void setPage() {

    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

    String page = params.get("action");

    System.out.println("page " + page);

    this.page = page;
}
Community
  • 1
  • 1
LEK
  • 83
  • 2
  • 11
  • This is wrong use of f:param and wrong way to call setPage method. http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ – Mahendran Ayyarsamy Kandiar Dec 29 '15 at 03:24
  • @MahendranAyyarsamyKandiar: I have used the mentioned tutorial but the setPage() method is not called. – LEK Dec 29 '15 at 17:21
  • while i will ignore the nomenclature of an action method's name please read http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked and debug – Mahendran Ayyarsamy Kandiar Dec 29 '15 at 17:25
  • @MahendranAyyarsamyKandiar: Thanks. which Item do you think is causing the problem? – LEK Dec 29 '15 at 17:35

0 Answers0