JSF label doesn't render

Discussion in 'Java' started by markspace, Apr 19, 2011.

  1. markspace

    markspace Guest

    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>
     
    markspace, Apr 19, 2011
    #1
    1. Advertising

  2. > 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"/>
     
    Travers Naran, Apr 20, 2011
    #2
    1. Advertising

  3. markspace

    Esmond Pitt Guest

    On 20/04/2011 8:49 AM, markspace wrote:
    > 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.
     
    Esmond Pitt, Apr 20, 2011
    #3
  4. markspace

    Lew Guest

    Travers Naran wrote:
    >> 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.


    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
    <http://download.oracle.com/javaee/6/tutorial/doc/bnarf.html#bnarr>
    presents the 'h:inputText' tag with a "label" attribute in the very first example:
    >> <h:inputText id="name" label="Customer Name" size="50"
    >> value="#{cashier.name}"
    >> required="true"
    >> requiredMessage="#{customMessages.CustomerName}">
    >> <f:valueChangeListener
    >> type="com.sun.bookstore6.listeners.NameChanged" />
    >> </h:inputText>
    >>
    >>
    >> The label attribute specifies a user-friendly name that will be used in the
    >> substitution parameters of error messages displayed for this component.


    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/E17802_01/j2ee/javaee/javaserverfaces/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.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
     
    Lew, Apr 20, 2011
    #4
  5. markspace

    markspace Guest

    On 4/20/2011 6:00 AM, Lew wrote:

    > 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.
     
    markspace, Apr 20, 2011
    #5
  6. markspace

    Roedy Green Guest

    On Tue, 19 Apr 2011 15:49:13 -0700, markspace <-@.> wrote, quoted or
    indirectly quoted someone who said :

    >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.
     
    Roedy Green, Apr 20, 2011
    #6
  7. markspace

    Lew Guest

    On 04/20/2011 04:01 PM, markspace wrote:
    > On 4/20/2011 6:00 AM, Lew wrote:
    >
    >> 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.


    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.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
     
    Lew, Apr 21, 2011
    #7
  8. markspace

    Lew Guest

    Roedy Green wrote:
    > markspace wrote, quoted or indirectly quoted someone who said :
    >> Hi all, I've got a weird problem with JSF rendering.


    > 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.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
     
    Lew, Apr 21, 2011
    #8
  9. markspace

    markspace Guest

    On 4/20/2011 7:47 PM, Lew wrote:

    > 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.
     
    markspace, Apr 21, 2011
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hongbo
    Replies:
    1
    Views:
    522
    Bruce Barker
    Dec 28, 2005
  2. dudu
    Replies:
    0
    Views:
    385
  3. Sebastian Fey

    JSF debugging / JSF newsgroup

    Sebastian Fey, Apr 7, 2006, in forum: Java
    Replies:
    1
    Views:
    7,637
    Danno
    Apr 7, 2006
  4. BlackIce
    Replies:
    1
    Views:
    17,186
  5. Knut Krueger
    Replies:
    8
    Views:
    282
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page