1
votes

page1.xhtml

<h:body>
<h:link outcome="page2.xhtml>
<f:param name="id" value="1"/>
</hlink>
</h:body>

page2.xhtml

 <h:body>
    <f:metadata>
    <f:event type="preRenderView" listener="#{myBean.init}"/>
    </f:metadata>
    <ui:include src="#{myBean.myString}"/>
    </h:body>

MyBean.java

public void init(ComponentsystemEvent e){
  Map<String,String> params = 
  FacesContext.getExternalContext().getRequestParameterMap();
  String myId = params.get("id");
  int id = Integer.parseInteger(myId);
  if(id==1)
    setMyString = "myPage.xhtml";
}

While i am navigating from page1.xhtml to page2.xhtml i am sending an id as a parameter where according to this id i will display a page

the problem is that the page cannot be find

i am printing in console what's happening what i found is that it is evaluating getMyString() before going to preRenderView init so why is this happening like this

i also tried post construct it returned error in resource injection of managedBean

1
PostConstruct seems more correct. Post the stacktraceKarl Kildén

1 Answers

4
votes

That's a classic view build time vs view render time problem: <ui:include> is a tag handler that's evaluated at view build time, while <f:event type="preRenderView"> naturally is called just when the view is about to be rendered. As you guess, the latter event happens after the former, while you expect it to be otherwise. Still, when the former tag requests to evaluate its attribute, it's definitely null, or isn't there yet.

Read the classic JSTL in JSF2 Facelets... makes sense? to get a better grasp at what's the relationship between these two phases of JSF lifecycle.