JSF将src动态地包含在"ui:include src ="#{bean.pagePath}" [英] JSF dynamically include src in "ui:include src="#{bean.pagePath}"

查看:121
本文介绍了JSF将src动态地包含在"ui:include src ="#{bean.pagePath}"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ui:include标签在不同选项卡中包含多个源页面路径.问题是当我将源页面路径设置为静态时,这表示将显示该页面,但是如果提供来自后备bean的源页面路径,则将不包括该页面.

I tried to include multiple source page path using ui:include tag in different tabs. The problem is when i gave the source page path as static one means that page will be shown but if give the source page path from backing bean mean it won't include the page.

这是我的代码

template.xhtml:

    <p:layoutUnit position="center" id="layoutCenter">
                <h:form id="tempFormId">
                    <p:tabView value="#{multiTabBean.tabsList}" var="useCase"
                        activeIndex="#{multiTabBean.activeTabIndex}">
                        <p:tab title="#{useCase.title}" closable="true">
                            <f:subview>
                                <h:panelGroup id="mainTempPanelGroupId" layout="block">
                                    <ui:include src="#{useCase.path}" />
                                </h:panelGroup>

                            </f:subview>
                        </p:tab>
                    </p:tabView>
                </h:form>
            </p:layoutUnit>

bean:

public String menuAction() {                    
    menuBtnRendered = true;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    selectedModuleViewId = externalContext.getRequestParameterMap().get(
            "moduleViewId");

    tabsList.add(new Tab(getTabId(selectedModuleViewId),
                selectedModuleViewId, getModulePath(selectedModuleViewId)));        

    return null;
}

我正在使用@ViewScoped.

推荐答案

<ui:include>在视图构建期间(当XHTML变成JSF组件树时)运行. <p:tabView>在视图渲染期间(当JSF组件树需要生成HTML时)运行.

<ui:include> runs during view build time (when XHTML is turned into JSF component tree). <p:tabView> runs during view render time (when JSF component tree needs to produce HTML).

因此,<ui:include>运行时,<p:tabView var>不可用.此问题在此答案中进行了详细说明: JSF2 Facelets中的JSTL ...有意义吗?(<ui:include>是一个标记处理程序,因此与JSTL标记具有相同的生命周期).

So, <p:tabView var> isn't available when <ui:include> runs. This problem is detailed in this answer: JSTL in JSF2 Facelets... makes sense? (<ui:include> is a taghandler and has hence same lifecycle as JSTL tags).

您可以通过使用<c:forEach>而不是<p:tabView value>生成<p:tab>来在一定程度上解决此问题.

You can solve this to a certain degree by using <c:forEach> to produce <p:tab>s instead of <p:tabView value>.

<p:tabView activeIndex="#{multiTabBean.activeTabIndex}">
    <c:forEach items="#{multiTabBean.tabsList}" var="useCase" varStatus="loop">
        <p:tab title="#{useCase.title}" closable="true">
            <f:subview id="tab_#{loop.index}">
                <h:panelGroup id="mainTempPanelGroupId" layout="block">
                    <ui:include src="#{useCase.path}" />
                </h:panelGroup>
            </f:subview>
        </p:tab>
    </c:forEach>
</p:tabView>

很有趣的是,您在最初的尝试中以某种方式使用了<f:subview>,而在那儿完全没有用(<p:tabView var>已将其考虑在内),但实际上在这里很有用(它创建了一个新的NamingContainer标签内容周围.)

It's by the way interesting to see that you somehow used <f:subview> in your initial attempt which is completely useless over there (already taken into account by <p:tabView var>), but it's actually helpful in here (it creates a new NamingContainer around the tab content).

这篇关于JSF将src动态地包含在"ui:include src ="#{bean.pagePath}"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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