JSF h:列标记修复宽度

时间:2008-11-28 18:33:23

标签: jsf

有人可以告诉我如何使用JSF修复数据表中列的宽度吗?

我的代码目前显示为:

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

谢谢!

4 个答案:

答案 0 :(得分:16)

通常你在dataTable上下文中使用h:列。

你可以做的是在CSS中设置宽度。如果你有代码:

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

在CSS文件中你可以:

.first {

   width: 250px;

}

假设您有2列。

检查dataTable属性here,你也可以找到所有类型的CSS相关属性。

答案 1 :(得分:3)

我遇到了这个问题,我可以使用h:datatable的columnclasses属性来解决它。请参阅标签lib。

JSF DataTable

答案 2 :(得分:0)

如果您使用的是JSF 2.2,则可以使用其pass-through功能解决此问题,并使用它将style属性从服务器端XHTML传递到客户端html

像这样:

<h:column pt:style="width:20px;text-align:center;"></h:column>

解决了这个问题:

<td style="width:20px;text-align:center;"></td>

不要忘记添加xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"并同时使用所有其他jsf名称空间

答案 3 :(得分:-6)

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