【问题标题】:Passing values with ui:param and access them in Backing bean使用 ui:param 传递值并在 Backing bean 中访问它们
【发布时间】:2011-07-20 15:22:38
【问题描述】:

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

感谢您的帮助!

【问题讨论】:

    标签: java jsf icefaces


    【解决方案1】:

    找到解决方案;

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

    Hidden Value 是一个 outputLabel,rendered = false

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

    【讨论】:

    • 嗨,您能否详细说明一下您的代码。 hiddenValue是outputLabel的id,UiTreeWalker是什么?
    【解决方案2】:

    我找到了另一种发送信息的方法,从 UI:Include 到 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-16
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      相关资源
      最近更新 更多