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

2

1

-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!

Dustproof answered 22/3, 2011 at 16:11 Comment(0)
D
2

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.

Dustproof answered 25/3, 2011 at 23:20 Comment(1)
hi, can you elaborate your code a bit more please. is hiddenValue the id of the outputLabel, and what is UiTreeWalker?Immethodical
B
1

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);
    }
}
Biffin answered 26/11, 2014 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.