如何在我的自定义组件中使用IncludeHandler? [英] How to use the IncludeHandler inside my custom component?

查看:100
本文介绍了如何在我的自定义组件中使用IncludeHandler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
ui背后的课程:包括JSF标签
我发现我需要使用IncludeHandler来使用

In question: The class behind ui:include JSF tag I found out that I need to use the IncludeHandler to use

<ui:include>

以编程方式。
但是,构造函数需要一个config参数,我不知道如何设置它。

请举例说明如何使用IncludeHandler进行简单包含

programmatically. However, the constructor needs a "config"-parameter and I don't know how to set this up.
Please give an example that shows how to use the IncludeHandler for a simple include like

<ui:include src="include.xhtml" />

我的jsf-component目前是以编程方式构建的,但我想包含一些写成.xhtml的部分。所以最后一个网页设计师只有一个组件,如

My jsf-component currently is built programmaticly but I want to include some parts written as ".xhtml". So at the end a web-designer simply has a component like

<fg:generator></fg:generator>

和一些.xhtml文件可以解决样式问题。如果有比IncludeHandler更好的方法(仍然需要使用Java),请告诉我:)

and some ".xhtml"-files to play around with the styling. If there's a better approach than the IncludeHandler (still needs to be in Java) let me know :)

推荐答案

如果你的唯一目的是以编程方式使用< ui:include> ,那么你应该使用 FaceletContext #includeFacelet() 而不是。假设您在自定义组件中:

If your sole purpose is to use <ui:include> programmatically, then you should be using FaceletContext#includeFacelet() instead. Assuming that you're inside your custom component:

FacesContext facesContext = FacesContext.getCurrentInstance();
FaceletContext faceletContext = (FaceletContext) facesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
faceletContext.includeFacelet(this, "include.xhtml"); // this is your current UIComponent.

这是另一个启动示例,演示动态包含命令按钮:

Here's another kickoff example which demonstrates dynamic include by command button:

<h:form>
    <h:commandButton value="include" action="#{bean.include}" />
</h:form>
<h:panelGroup id="include" />

with

public void include() throws IOException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    FaceletContext faceletContext = (FaceletContext) facesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    faceletContext.includeFacelet(facesContext.getViewRoot().findComponent("foo"), "include.xhtml");
}

这篇关于如何在我的自定义组件中使用IncludeHandler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆