views:

69

answers:

2

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!

+2  A: 

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>
Colin Gislason
Thanks!! Clearly, I need to do some reading on this. :-)
Liggy
You could also use: <h:commandLink value="Search" />
Naganalf
@Naganalf: does that work on JSF 1.0/1.1 as well? I recall some issues with it.
BalusC
I don't know. I only spent a couple months on 1.1 before we updated to 1.2.
Naganalf
+2  A: 

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.

BalusC