Passing values ​​using ui: param and accessing them in backing bean mode

-xhtml file

I can not pass the passed parameter

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

The way I tried to use the parameters, I searched for each variable with a debugger, but it seems that the value of ui: param is not 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 your help!

+1
source share
2 answers

Found a solution

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

The hidden value is outputLabel with rendered = false

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

+2
source

I found another way to send information from the UI: Enable in Bean in JSF 2.2. By setting a hidden value and referring to a method in a bean. eg:

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

No need to use: in an intitial line in this file. First, this hidden parameter will be specified, which will be set in the Bean in order. And in toInclude.xhtml will be:

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

in 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); } } 
+1
source

Source: https://habr.com/ru/post/1435533/


All Articles