在 JSF 子视图中混合 HTML 和 JSF
我今天遇到的问题是关于使用 JSF 处理包含的 JSP 中的 HTML。 情况如下:我在 RAD 上使用 IBM 的 JSF 1.2 和 Websphere v6.1 我有一个自定义组件(来自公司层)来使用选项卡。 为了有一个更干净的代码,我只想将每个选项卡的JSF代码分离在一个单独的JSP中,这样, 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 :
<!-- 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 之外。虽然
<table>
<!-- generated content -->
</table>
<div id="myDivId">
...
表格应该位于 div 内部。我尝试以不同的方式使用
标签,唯一的解决方案是包围
和
< /code> 由逐字开始和结束标记组成,这很脏并且让 Websphere 变得疯狂。
谷歌没有找到相关的信息,请问你们是否也遇到过同样的问题?是否可以找到一个干净的解决方案,或者我是否必须将所有代码包含在同一个 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>
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>
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">
...
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,这可以被认为是遗留的 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
中那么简单。至于您的实际问题,您需要使用
f:verbatim
包装 only 模板文本,而不是有价值的 JSF 组件。因此,以下应该有效: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, thef:verbatim
is entirely superfluous since the new view handler of the 2006's JSF 1.2 which automatically takes any template text insidef: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
.As to your actual problem, you need to wrap only template text with
f:verbatim
, not worthfully JSF components. Thus, the following should work: