3

I'd like to create a master-detail screen with request params and requestScoped beans but the view param doesn't get filled.

The link that invokes the redirect:

<h:form>
        <p:dataTable var="visit" value="#{visitBean.findAllVisits()}">
            <p:column headerText="mdh">
                <p:commandLink action="#{visitDetailBean.seeVisitDetails(visit)}">
                    <h:graphicImage library="images" name="details.png"/>
                </p:commandLink>
            </p:column>
            ....

The method behind it:

public String seeVisitDetails(Visit visit) throws IOException {
   return "/pages/mdh-details.xhtml?visitId=" + visit.getId()+ ";faces-redirect=true";
}

The details xhtml page:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core">

<f:metadata>
  <f:viewParam name="visitId" value="#{visitDetailBean.currentVisitId}" />
</f:metadata>

<ui:composition template="/templates/masterLayout.xhtml">
  <ui:define name="content">
    <h:outputText value="#{visitDetailBean.currentVisit.name}"/>
    test
  </ui:define>
</ui:composition>

and last the details Bean:

private long currentVisitId;

public void setCurrentVisitId(long currentVisitId) {
    this.currentVisitId = currentVisitId;
}

public long getCurrentVisitId() {
    return currentVisitId;
}

public Visit getCurrentVisit() {
    return visitService.findVisit(currentVisitId);
}

currentVisitId is always 0.. I actually can't really find it.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
GregD
  • 1,884
  • 2
  • 28
  • 55

1 Answers1

3

When using templating, anything outside <ui:composition> and <ui:define> is ignored. This includes <f:metadata>.

Move it to inside an <ui:define> of the <ui:composition>.

E.g.

<ui:composition template="/templates/masterLayout.xhtml">
  <ui:define name="metadata">
    <f:metadata>
      <f:viewParam ... />
    </f:metadata>
  </ui:define>

  <ui:define name="content">
    ...
  </ui:define>
</ui:composition>

See also:


Unrelated to the concrete problem, you'd better place masterLayout.xhtml in /WEB-INF folder to prevent direct access.

<ui:composition template="/WEB-INF/templates/masterLayout.xhtml">

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555