将支持bean作为参数传递给Facelet包括 [英] Passing the backing bean as a parameter to a Facelet include
问题描述
我有一个可能在不同应用程序中使用的Facelet。
我不要复制它,而是重复使用它。我需要传递将视图作为参数进行管理的支持bean,因为某些逻辑可能会根据使用它的应用程序而有所不同。
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, as some logic may vary according to the application where it is used in.
我不知道想要使用复合组件,但只需包含Facelet并指定哪个bean将管理视图。我怎样才能做到这一点?
I don't want to use a composite component, but just include the Facelet and specify which bean will manage the view. How can I achieve this?
让我举一个例子:
<ui:composition template="/resources/common/templates/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich" xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<ui:define name="content">
<!-- somehow establish the backing bean that will manage formView.xhtml -->
<!-- f:set assign="ParameterBean" value="#{Bean}" / -->
<ui:include src="formView.xhtml" />
</ui:define>
</ui:composition>
formView.xhtml:
formView.xhtml :
<ui:composition template="/resources/common/templates/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich" xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<ui:define name="content">
<h:outputText value="#{ParameterBean.texto}" />
</ui:define>
</ui:composition>
推荐答案
你可以使用<ui:param>
为此。它需要嵌套在 < ; ui:include>
。
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>
不相关到具体问题,标准 Java命名约定规定实例变量名称必须启动小写的。你应该改变你的代码,分别使用 parameterBean
和#{bean}
。
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.
这篇关于将支持bean作为参数传递给Facelet包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!