Passing the backing bean as a parameter to a Facelet include

前端 未结 2 1573
不知归路
不知归路 2020-11-29 12:22

I have a Facelet that might be used in different applications. I don\'t to copy it, but reuse it. I need to pass the backing bean that will manage the view as a parameter,

相关标签:
2条回答
  • 2020-11-29 12:55

    Because I would have found it helpful yesterday, when I was looking for this, here is a simple version of how to do this, without the extraneous template, defines and namespaces:

    File1.xhtml (the root tag doesn't matter)

    <ui:include src="File2.xhtml">
      <ui:param name="person" value="#{whatever_value_you_want_to_pass}" />
    </ui:include>
    

    File2.xhtml

    <ui:composition ... xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" ... >
      <h:outputLabel value="#{person.name}" />
    </ui:composition>
    


    You can also nest further in the same manner.

    File1.xhtml

    <ui:include src="File2.xhtml">
      <ui:param name="person" value="#{whatever_value_you_want_to_pass}" />
    </ui:include>
    

    File2.xhtml

    <ui:composition ... xmlns:ui="http://java.sun.com/jsf/facelets" ... >
      <ui:include src="File3.xhtml">
        <ui:param name="name" value="#{person.name}" />
      </ui:include>
    </ui:composition>
    

    File3.xhtml

    <ui:composition ... xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" ... >
      <h:outputLabel value="#{name.length}" />
    </ui:composition>
    
    0 讨论(0)
  • 2020-11-29 13:04

    You can use <ui:param> for that. It needs to be nested in the <ui:include>.

    <ui:include src="formView.xhtml">
        <ui:param name="ParameterBean" value="#{Bean}" />
    </ui:include>
    

    Unrelated to the concrete problem, standard Java Naming Conventions state that instance variable names must start with lower case. You should change your code in such way that respectively parameterBean and #{bean} will be used.

    0 讨论(0)
提交回复
热议问题