jonnyhitek
jonnyhitek

Reputation: 1551

create a unordered list in jsf (ul)

Hi I need to implement a unordered list in jsf - just wondering if I have to create a custom tag for this ? I have tried using <ul> but it is currently falling outside of the jsf component tree. Cheers

Upvotes: 1

Views: 11749

Answers (3)

BalusC
BalusC

Reputation: 1108802

but it is currently falling outside of the jsf component tree

This suggests that you're using the legacy JSF 1.0/1.1. See for more detail also JSF/Facelets: why is it not a good idea to mix JSF/Facelets with HTML tags?

You've basically 3 options:

  1. Upgrade to JSF 1.2. It has exactly the same environmental requirements as JSF 1.0/1.1 and would thus not require any other changes, just replacing the JARs would suffice. Once done that, you can write down "plain HTML" without any trouble.

    <ul>
        <li>item 1</li>
        <li>item 2</li>
        <li>item 3</li>
    </ul>
    

  2. If upgrading is really not an option, which would be really strange, then wrap blocks of plain HTML in <f:verbatim>.

    <f:verbatim>
        <ul>
            <li>item 1</li>
            <li>item 2</li>
            <li>item 3</li>
        </ul>
    </f:verbatim>
    

    Note that you don't necessarily need to wrap every individual tag. Only close and reopen it when you encounter a JSF component "halfway". Even the following is valid.

    <f:verbatim>
        <ul>
            <li>item 1</li>
            <li></f:verbatim><h:outputText value="#{bean.some}" /><f:verbatim></li>
            <li>item 3</li>
        </ul>
    </f:verbatim>
    

  3. Use a JSF 1.0/1.1 compatible component library which offers a component out the box which generates a <ul><li>. Only one comes to mind: Tomahawk <t:dataList>. Just set its layout attribute to unorderedlist to get it to generate an <ul><li>.

    <t:dataList layout="unorderedList" value="#{bean.list}" var="item">
        <h:outputText value="#{item}" />
    </t:dataList>
    

Upvotes: 5

jonnyhitek
jonnyhitek

Reputation: 1551

Very crude - I know but just settled for the good old:

<f:verbatim> tag e.g. `
<f:verbatim><ul></f:verbatim>
<f:verbatim><li></f:verbatim>Lorem ipsum dolor sit amet<f:verbatim></li></f:verbatim>
<f:verbatim><li></f:verbatim>Lorem ipsum dolor sit amet<f:verbatim></li></f:verbatim>
<f:verbatim><li></f:verbatim>Lorem ipsum dolor sit amet<f:verbatim></li></f:verbatim>
<f:verbatim><li></f:verbatim>Lorem ipsum dolor sit amet<f:verbatim></li></f:verbatim>
<f:verbatim><li></f:verbatim>Lorem ipsum dolor sit amet<f:verbatim></li></f:verbatim>
<f:verbatim></ul><f:verbatim>`

Upvotes: 0

Behrang Saeedzadeh
Behrang Saeedzadeh

Reputation: 47933

You don't have to embed every start tag, inner text, and end tag in a distinct <f:verbatim>. You can simply do this:

<f:verbatim>
<ul>
 <li>foo</li>
 <li>bar</li>
 <li>baz</li>
</ul>
</f:verbatim>

Alternatively you can use Facelets which handles interleaving of JSF and HTML tags like a charm.

Hope this helps.

Upvotes: 0

Related Questions