How to get ui: param value in bean database

I pass the parameter p1to another page page.xhtml:

<ui:include src="page.xhtml">
    <ui:param name="p1" value="#{someObject}"/>
</ui:include>

Is it possible to evaluate #{p1}the bean support inside the @PostConstruct method page.xhtml? Using the following code snippet #{p1}cannot solve:

FacesContext currentInstance = FacesContext.getCurrentInstance();
currentInstance.getApplication().evaluateExpressionGet(currentInstance, "#{p1}", String.class);

Why do I need it?

I am using an xhtml file (e.g. component.xhtml) as the user interface component of the user interface. This file has a bean backup from which I should get the component data. Since I include this xhtml file twice or more on my JSF main page, I want to pass different objects to each component.xhtml component so that each of my components works with my custom data.

+5
source share
2 answers

Mojarra FaceletContext. @PostConstruct bean, , , / (, , , <ui:param> ).

FaceletContext faceletContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
Object p1 = faceletContext.getAttribute("p1");

MyFaces FaceletContext beans, , . JSF-, <c:set scope="request">. .

, . . . . < ui: include > , , / ?

+8

:

<ui:include src="page.xhtml">
     <ui:param name="p1" value="#{someObject}"/>
</ui:include>

page.xhtml:

<c:set var="data" value="#{p1}" scope="request"/>

bean:

@ViewScoped
public class ManagedBean{

     private Object someObject;

     public Object getSomeObject(){
         if(someObject== null){
            HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            someObject= request.getAttribute("data");
          }
          return someObject;
     }

     public void setSomeObject(Object someObject){
          this.someObject = someObject;
     }}
0

All Articles