ui:include value is evaluated before preRenderView

ぐ巨炮叔叔 提交于 2019-12-24 15:55:19

问题


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:


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.



来源:https://stackoverflow.com/questions/16544674/uiinclude-value-is-evaluated-before-prerenderview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!