tags:

views:

6220

answers:

2

Hi,

Can someone show me how to fix the width of a column in a datatable with JSF?

My code currently reads:

<h:column>
    <f:facet name="header">
        <h:outputText value="Data Field 1" />
    </f:facet>
    <h:commandLink id="dataLink" action="#{pc_SearchResultsFragment.setField1}">
        <h:outputText value="#{(qi.data1 != null) ? '' : qi.data1}"/>              
    </h:commandLink>
</h:column>

Thanks!

+6  A: 
<h:column>
    <f:facet name="header">
        <h:outputText value="Data Field 1" />
    </f:facet>
    <h:commandLink id="dataLink" action="#{pc_SearchResultsFragment.setField1}">
        <h:outputText value="#{(qi.data1 != null) ? '' : qi.data1}"/>                     
    </h:commandLink>
    <%-- <f:attribute name="width" value="20" /> fixed width --%>
    <%-- or --%>
    <%-- <f:attribute name="width" value="20%" /> percentage --%>

    <%-- also available (not a complete list, just some of the more
         common supported attributes) --%>
    <%-- <f:attribute name="align" value="left" /> --%>
    <%-- <f:attribute name="height" value="20" /> --%>
    <%-- <f:attribute name="nowrap" value="true" /> --%>
    <%-- <f:attribute name="valign" value="top" /> --%>
    <%-- <f:attribute name="bgcolor" value="red" /> --%>
    <%-- <f:attribute name="style" value="color:White;" /> --%>
</h:column>
Grant Wagner
Hi, I tried this way, But I couldn't get this working. With the rendered HTML , I don't see a width Attribute either for the Header or for the dataTable rows. I am using JSF 1.2 without any component libs. Any idea ? What could be the problem?
gurupriyan.e
+1  A: 

Well usually you use h:column in a dataTable context.

What you could do is set the width in CSS. If you have the code:

<h:dataTable value="#{action.items}" var="name" 
styleClass="tableClass" columnClasses="first,second">

And in the CSS file you do:

.first {

   width: 250px;

}

That is assuming you have 2 columns.

Check the dataTable properties here, also you can find there all kind of CSS related properties.

Alexandru Luchian