有人见过这个 h:commandLink 行为吗?
我有一个非常简单的 JSF 表单:
<h:form id="simpleSearch">
<h:inputText id="surname" value="#{myBean.surname}" required="true" />
<h:commandLink>Search</h:commandLink>
</h:form>
呈现此页面时,生成的锚点如下所示(为简洁起见,我删除了生成的 onclick 代码):
Search<a href="#" onclick="..."></a>
如您所见,“搜索”位于锚点之外,并且锚体是空的。这对我来说没用。我不能用这个。
有没有任何建议/参考/奇迹可以帮助我解决/理解这里发生的事情?
谢谢!
I have a very simple JSF form:
<h:form id="simpleSearch">
<h:inputText id="surname" value="#{myBean.surname}" required="true" />
<h:commandLink>Search</h:commandLink>
</h:form>
When this page is rendered, the anchor that is generated looks like this (for brevity, I stripped out the generated onclick code):
Search<a href="#" onclick="..."></a>
As you can see, the "Search" is outside the anchor and the anchor body is empty. This is useless to me. I can't use this.
Are there any suggestions/references/miracles out there to help me fix/understand what is going on here?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在混合 HTML 和 JSF 组件。这通常在 JSP 上效果不佳。您希望将“搜索”文本放入
h:outputText
组件中:You are mixing HTML and JSF components. This generally doesn't work well on JSPs. You want to put the 'Search' text in an
h:outputText
component:在旧版 JSF 1.0/1.1 中,任何模板文本都会在 JSF 组件树之前呈现。您需要将模板文本包装在
中以将其放入 JSF 组件树中。但h:outputText
的使用更为常见,除非它是纯 HTML。例如,否则您需要将
h:outputText
的escape
属性设置为 false 以避免它被转义:在 JSF 1.2 及更高版本中,通过改进的视图处理程序,您可以“以通常的方式”使用模板文本,它将按照您期望的编码方式在组件树中自动获取。
因此,此问题表明您“仍在”使用旧版 JSF 1.0/1.1。如果可以的话,我宁愿建议至少升级到 JSF 1.2。您可以让它在任何 Servlet 2.4 兼容容器上工作。 JSF 1.2 和 Servlet 2.4 已于 4 年前发布。那是很久以前的事了。
In legacy JSF 1.0/1.1 any template text is rendered before the JSF component tree. You need to wrap template text in
<f:verbatim>
to take it in the JSF component tree. But the use ofh:outputText
is more common, unless it's plain HTML. E.g.Else you need to set
escape
attribute of theh:outputText
to false to avoid it being escaped:In JSF 1.2 and newer, with the improved view handler, you can just use template text "the usual way", it will be taken automatically in the component tree the way as you'd expect from the coding.
So, this problem indicates that you're "still" using the legacy JSF 1.0/1.1. If you can, I'd rather suggest to upgrade to at least JSF 1.2. You can get it to work on any Servlet 2.4 compatible container. JSF 1.2 and Servlet 2.4 were released over 4 years ago. That's a pretty long time ago.