JSF label doesn't render

M

markspace

Hi all, I've got a weird problem with JSF rendering. For some reason,
the label attribute doesn't want to render on the resulting HTML output.
For example, if I have this:

<h:inputText label="First Name"
id="fname"
required="true" />

That label, "First Name", never shows up on the HTML. I checked the
HTML source too and it's not there, so it's not a browser problem per se.

There's some other oddities that are convincing me maybe it's a
configuration parameter somewhere, or maybe the JSF library I'm using.
I have Glassfish with the Oracle libraries, i.e. what came with NetBeans
6.9.1. However I haven't been able to locate any configuration
information for Oracles JSF implementation, or even for any JSF
implementation.

Any help getting that label to display would be much appreciated.

Here's the full JSF Xhtml test file I made to duplicate the error.


<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>A Simple JSF App</title>
</h:head>
<h:body>
<h:form>
<h2>JSF Registration APP</h2>
<h4>Registration Form</h4>
<table>
<tr>
<td>
<h:inputText label="First Name"
id="fname"
required="true" />
<h:message for="fname" />
</td>
</tr>
</table>
<p><h:messages /></p>
<p><h:commandButton value="Click Me" action="confirm" /></p>
</h:form>
</h:body>
</html>
 
T

Travers Naran

Hi all, I've got a weird problem with JSF rendering. For some reason,
the label attribute doesn't want to render on the resulting HTML output.
For example, if I have this:

<h:inputText label="First Name"
id="fname"
required="true" />

That label, "First Name", never shows up on the HTML. I checked the HTML
source too and it's not there, so it's not a browser problem per se.

Unless this is something new in JSF 2, there is no "label" attribute on
inputText. In JSF 1.2, you do something like this:

<h:eek:utputLabel value="First Name" for="fname"/>
<h:inputText id="fname" value="#{BackingBean.Property}" required="true"/>
 
E

Esmond Pitt

Hi all, I've got a weird problem with JSF rendering. For some reason,
the label attribute doesn't want to render on the resulting HTML output.

The label attribute is displayed *when there is an <h:message>*. It
isn't displayed with the h:inputText element itself.
 
L

Lew

You should read the tutorial, you should read the taglib docs, and you should
read the other JSF docs on this tag. That would illuminate your error. RTFM.
(Links provided in this post.)
Unless this is something new in JSF 2, there is no "label" attribute on
inputText. In JSF 1.2, you do something like this:

Nope. According to
<http://download.oracle.com/javaee/5/javaserverfaces/1.2/docs/tlddocs/h/inputText.html>

there is, too, a "label" attribute for 'h:inputText'. It is described as a
"localized user presentable name for this component". However, it is NOT the
same as an HTML 'label' tag, nor a JSF 'h:eek:utputLabel' tag. There's no reason
to expect to see it in the HTML at all whatsoever, which is why the OP does
not see it.

The Java EE 6 tutorial at

This description, however, does not match the OP's intended use. Maybe he
should read the tutorial and other JSF docs?

For example:
<http://download.oracle.com/docs/cd/...es/2.0/docs/pdldocs/facelets/h/inputText.html>
describes the "label" attribute of 'h:inputText' as "A localized user
presentable name for this component". There's nothing there to imply anything
emitted in HTML for it.

Contrast with how the tutorial describes the 'h:eek:utputLabel' tag:
"The h:eek:utputLabel tag is used to attach a label to a specified input field
for the purpose of making it accessible."
<h:eek:utputLabel value="First Name" for="fname"/>
<h:inputText id="fname" value="#{BackingBean.Property}" required="true"/>

This will provide his intended use. Note that in HTML, "label" is not an
attribute of the 'input' tag, but a separate tag in its own right. There is
no "label" attribute in HTML for the 'input' tag.

So, bottom line: The 'h:inputText' attribute "label" is not intended to
generate any HTML, that's why you don't see it.

RTFM.
 
M

markspace

So, bottom line: The 'h:inputText' attribute "label" is not intended to
generate any HTML, that's why you don't see it.


Yup, I misinterpreted some examples and didn't double check with the
docs. Thanks for the links and thanks to Mr. Pitt for reinforcing the
message.
 
R

Roedy Green

Hi all, I've got a weird problem with JSF rendering.
JSF creates a Java program just like JSP, right?

Can you peek at the generated Java source?
--
Roedy Green Canadian Mind Products
http://mindprod.com
Politicians complain that Kindles and iBooks are killing jobs by
destroying the paper book industry. I see it that they have create a way
to produce books for less than a third the cost without destroying forests
and emitting greenhouse gases in the process. They have created wealth.
They are encouraging literacy and cutting the costs of education.
 
L

Lew

Yup, I misinterpreted some examples and didn't double check with the docs.
Thanks for the links and thanks to Mr. Pitt for reinforcing the message.

BTW, markspace and others, know that I respect you and that the essay/post has
a rhetorical style that is for pedagogical and didactic purposes only, and in
no wise should cause one to infer lack of respect for you. Anyone who reads
your posts knows that you are knowledgeable and talented.

So a phrase similar "the OP should RTFM" should be taken as general advice for
all readers, myself included. Indeed, I did quite a bit of RTFMing to prepare
for my earlier post - I knew very little of that information until I
researched it for my response. Until then, I had no idea that 'h:inputText'
had a "label" attribute, and was convinced that it didn't exist.

So when I say RTFM, it's something I do myself and often have just done.
Thus, I ferret out links that everyone can use, throwing away the ones I don't
think will help. I'm eating my own dog food (metaphorically speaking).

What's that you say, other Usenetizens? I threw away the wrong links? There
are better links than the ones I indicated? I'm not surprised; I didn't spend
all /that/ long doing the research. Really, somewhere between 15 and 30
minutes or so - nothing anyone else couldn't have done. Assuming they're
willing to do a little research themselves, say up to a half hour's worth in
order to earn those big developer bucks. I'm quite certain your links will be
better, and I look forward to the education I'll receive when you share them.
 
L

Lew

Roedy said:
markspace wrote, quoted or indirectly quoted someone who said :
JSF creates a Java program just like JSP, right?

Nope. It creates a Java program, or rather, the app container does, but most
of the JSF magic doesn't live in that program. So it's really nothing like
JSP. In fact, JSF doesn't even require JSP.
Can you peek at the generated Java source?

Not really.

I mean, you can, but it doesn't help. The generated source is just stuff to
generate HTML; it has nothing to do with the JSF component model maintained by
the JSF framework itself.
 
M

markspace

So when I say RTFM, it's something I do myself and often have just done.
Thus, I ferret out links that everyone can use, throwing away the ones I
don't think will help. I'm eating my own dog food (metaphorically
speaking).


No worries. I found "RTFM" a little abrupt, but I know your posting
style so I just looked at the links and what you were trying to say. I
did misread the documentation at first (2nd hand, unfortunately) and I
still find "user-friendly name" a little confusing, but the reference to
messages is clear enough after a second read.

What's that you say, other Usenetizens? I threw away the wrong links?
There are better links than the ones I indicated? I'm not surprised;


I'd also like to see some better links to JSF documentation, esp. the
faces-config.xml file, if anyone has some pointers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,261
Messages
2,571,040
Members
48,769
Latest member
Clifft

Latest Threads

Top