Passing values with ui:param and access them in Backing bean

北战南征 提交于 2019-12-11 05:48:51

问题


-xhtml File

I cannot accsses the passed Parameter

<ui:insert>
        <ui:include src="#{PopUpBean.includeUrl}">
           <ui:param name="includeParam" id="includeParam" value="HalloWert!"  />                                  
        </ui:include>
</ui:insert>

Thats the way i tried to accses the parameters, i have lookedup every variable with help of the debugger, but it seems as if the ui:param value isn't passed:

    private void init () {
   FacesContext ctx =  FacesContext.getCurrentInstance();
   ExternalContext ectx = ctx.getExternalContext();
   Object o = ectx.getRequestParameterMap().get("includeParam");
   Object request =  ectx.getRequest();
}

@PostConstruct
public void postContruction () {
    this.init();
}

Thank you for help!


回答1:


Found a Solution;

  HtmlOutputLabel ob = (HtmlOutputLabel) UiTreeWalker.findComponent(FacesContext.getCurrentInstance().getViewRoot(), "hiddenValue");
       ValueExpression vb = ob.getValueExpression("value");
      Object value =  vb.getValue(FacesContext.getCurrentInstance().getELContext());

Hidden Value is a outputLabel with rendered = false

The idea behind this is that you can put the parameter in a hidden value on your JSF page, and then you can access that parameter from this java snippet.




回答2:


I found another way to send information, from UI:Include to Bean in JSF 2.2. By setting a hidden value and reference a method in the bean. for instance:

<ui:include src="/toInclude.xhtml">
    <ui:param name="idValue"
     value="#{masterBean.idValue}" />
</ui:include>

Don't needed to use: at the intitial line in this file. This hidden parameter will be put at first, that will be setting in the bean in order. And in the toInclude.xhtml will be:

<h:inputHidden id="idValue"
        value="#{toIncludeBean.putIdValue(idValue)}" />

in the Bean:

@Named(value = "toIncludeBean")
@Scope("view")
public class ToIncludeBean  {
private String value;    

public void putIdValue(String idValue) {
        //This is in my bean
        this.setValue(idValue);
    }
}


来源:https://stackoverflow.com/questions/5394304/passing-values-with-uiparam-and-access-them-in-backing-bean

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