使用ui:param传递值并在Backing bean中访问它们

时间:2011-03-22 16:11:50

标签: java jsf icefaces

-xhtml文件

我无法控制传递的参数

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

这就是我尝试接受参数的方式,我在调试器的帮助下查找了每个变量,但似乎ui:param值似乎没有传递:

    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();
}

谢谢你的帮助!

2 个答案:

答案 0 :(得分:2)

找到解决方案;

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

隐藏值是一个outputLabel,其render = false

这背后的想法是你可以将参数放在JSF页面上的隐藏值中,然后你可以从这个java片段中访问该参数。

答案 1 :(得分:1)

我找到了另一种从UI发送信息的方法:在JSF 2.2中包含Bean。通过设置隐藏值并引用bean中的方法。 例如:

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

不需要使用:在此文件的初始行。 这个隐藏的参数将首先放入,将按顺序在bean中进行设置。 在toInclude.xhtml中将是:

<h:inputHidden id="idValue"
        value="#{toIncludeBean.putIdValue(idValue)}" />
在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);
    }
}
相关问题