在JSF子视图中混合HTML和JSF [英] Mix HTML and JSF in a JSF subview

查看:116
本文介绍了在JSF子视图中混合HTML和JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天遇到的问题是关于使用JSF处理包含的JSP中的HTML. 因此,情况如下:我在Websphere v6.1上使用IBM在RAD上的JSF 1.2,我有一个自定义组件(来自公司层)来使用选项卡. 而且,为了获得更简洁的代码,我只想在单独的JSP中将每个选项卡的JSF代码分开,即main.jsp:

The problem I have today is about dealing with HTML in an included JSP, with JSF. So here's the situation : I use JSF 1.2 by IBM on RAD with Websphere v6.1 I have a custom component (from the company layer) to use tabs. And in order to have a cleaner code, I just want to separate the JSF code of each tab in a separated JSP, this way, main.jsp :

<customTag:tabComponent>
<jsp:include page="/jsp/workflow/tab1.jsp"></jsp:include>
<div align="right">
    <customTag:switchToTab title="Next" tabValue="2"></customTag:switchToTab>
</div>
</customTag:tabComponent>

还有我的tab1.jsp:

And my tab1.jsp :

<!-- Taglibs declared here -->
<f:verbatim>
<div id="myDivId">
    <fieldset>
        <legend>myLegend</legend>
        <h:outputText value="#{myBean.someContent}"></h:outputText>
        <!-- HERE are a lot of JSF components, selectItems, inputText... -->
    </fieldset>
</div>
</f:verbatim>

因此,已处理了JSF组件,但是HTML似乎在由JSF生成的HTML之外被处理,并且出现在JSF生成的HTML之外.像

So the JSF components are processed, but HTML seems to be treated after and appears after, outside of the HTML generated by JSF. Something like

<table>
    <!-- generated content -->
</table>
<div id="myDivId">
...

尽管该表应位于div内.我试图以不同的方式使用<f:verbatim>标记,唯一的解决方案是用逐字的开始和结束标记包围<div></div>,这很脏,使Websphere疯狂.

although the table should be inside the div. I tried to use the <f:verbatim> tag different ways, and the only solution was to surround <div> and </div> by the verbatim opening and closing tags, which is dirty and makes Websphere going crazy.

Google没有找到任何相关内容,所以你们已经遇到了同样的问题吗?是否有可能找到一个干净的解决方案,还是我必须将所有代码都包含在同一个JSP中?预先感谢.

Google did not find anything relevant, so have you guys already encountered the same issue? Is it possible to find a clean solution or do I have to include all my code inside the same JSP? Thanks in advance.

推荐答案

首先,这可以识别为旧版JSF 1.0/1.1行为.确实需要f:verbatim才能将模板文本带入JSF组件树.但是,f:verbatim完全多余,因为2006年JSF 1.2的新视图处理程序自动将f:view中的所有模板文本带到组件树中.因此,您是否真的使用JSF 1.2? Websphere 6.1附带内置的JSF 1.1库,升级到1.2并不像仅将库放置在/WEB-INF/lib中那样简单.

First of all, that's recognizeable as legacy JSF 1.0/1.1 behaviour. The f:verbatim was indeed required to take template text into the JSF component tree. However, the f:verbatim is entirely superfluous since the new view handler of the 2006's JSF 1.2 which automatically takes any template text inside f:view into the component tree. Thus, are you really using JSF 1.2? Websphere 6.1 ships with builtin JSF 1.1 libraries and upgrading to 1.2 isn't as easy as just placing libs in /WEB-INF/lib.

对于您的实际问题,您需要仅使用f:verbatim包装 模板文本,而不是有价值的JSF组件.因此,以下方法应该起作用:

As to your actual problem, you need to wrap only template text with f:verbatim, not worthfully JSF components. Thus, the following should work:

<f:verbatim>
    <div id="myDivId">
        <fieldset>
            <legend>myLegend</legend>
</f:verbatim>
<h:outputText value="#{myBean.someContent}"></h:outputText>
<!-- HERE are a lot of JSF components, selectItems, inputText... -->
<f:verbatim>
        </fieldset>
    </div>
</f:verbatim>

这篇关于在JSF子视图中混合HTML和JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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