开发者

Has anyone seen this h:commandLink behavior?

I have a very simple JSF form:

<h:form id="si开发者_开发知识库mpleSearch">
    <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!


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:

<h:commandLink><h:outputText value="Search" /></h:commandLink>


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 of h:outputText is more common, unless it's plain HTML. E.g.

<f:verbatim><h1>Title</h1></f:verbatim>

Else you need to set escape attribute of the h:outputText to false to avoid it being escaped:

<h:outputText value="<h1>Title</h1>" escape="false" />

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜