tags:

views:

361

answers:

3

I want to look at using JSF but I'm put off by what appears to be the liberal use of html tables for layout by many components.

How do you go about using JSF to develop css-based layouts?

[edit]

I seem to be labouring under a misaprehension here, but every JSF tutorial I've seen ends up producing table-based html layouts. I've also looked at RichFaces and IceFaces demos and there's an awful lot of tables-for-layout there as well.

Does anyone know of a JSF tutorial that develops a CSS based layout? If not, does anybody fancy making one? ;)

A: 

I haven't tried it, but since most components have a style and styleClass property you can put css into the JSF elements.

You may find this article useful: http://www.ibm.com/developerworks/web/library/wa-aj-jsfcss1/index.html

James Black
Thanks, but unfortunately the article is about styling tables, which I'd rather not use at all :)
Bedwyr Humphreys
You can write your own components, then you can use the css styling to position the divs appropriately.
James Black
+5  A: 

Many components? There are as far as I know only two which does that "unnecessarily": h:selectManyRadio and h:selectManyCheckbox, both from the UISelectMany family. If you want table-less radiobuttons/checkboxes, instead use the Tomahawk variant which have an extra layout attribute value of spread.

For the remnant you just have the control fully in your own hands. Just do not use tables for layout, i.e. do not use JSF h:panelGrid for layout. Just use HTML div elements to display content blocks. Or if you're a JSF-purist, use h:panelGroup layout="block" instead of HTML div elements.

As to applying CSS, it isn't that hard, every JSF HTML component has a styleClass attribute wherein you can specify CSS classes (which would end up in a HTML class attribute) and style attribute wherein you can specify inline CSS (which would end up in a HTML style attribute).

You can even define global CSS styles and use the ID selectors. Only thing which you need to take care in JSF+CSS is that the JSF-generated HTML element ID's are prepended with the ID's of all parent UINamingContainer components (e.g. f:subview, h:form, h:dataTable, etc) with a colon : as separator. As the colon is an illegal character in CSS identifiers, you need to escape it using \. So styling the input element of for example

<h:form id="form">
    <h:inputText id="input" ... />

which generates <input type="text" id="form:input" ... /> should be done as

#form\:input {
    background: gray;
}
BalusC
I've looked at the resulting html for components from component libraries and many of them are table based. Maybe I've looked at the wrong ones.
Bedwyr Humphreys
The `panelGrid` and `dataTable` renders a table as well, but there they **are** for! I must however admit, I have seen too often that new-to-JSF users are unnecessarily using `panelGrid`s instead of `div`s for layout. Maybe you've seen that as well.
BalusC
In addition to this answer, you can also consider `Facelets` for your templating. I used Facelets, div and CSS to create the skeletons of my pages.
romaintaz
I admit that Facelets is a much better view technology than JSP, but since JSF 1.2 which already came out early 2006 you can use inline HTML without the need to wrap with nasty `f:verbatim` as in JSF 1.1 or older.
BalusC
A: 

It is definitely possible to produce a website built on JSF that does not use tables for layout. I'm not sure why you think JSF relies upon tables? JSF provides the framework for you to develop whatever type of page you want.

Here is another link that may prove useful: http://www.ibm.com/developerworks/java/library/j-jsf1/index.html

Ben
I'll add some more to the question, but it's generally because every tutorial I've seen ends up producing html tables, and having looked at components from richfaces, icefaces etc. they all seem to use a lot of tables for layout
Bedwyr Humphreys