如何在JSF中设置dataTable呈现列的宽度? [英] How to set the width for the dataTable rendered column in JSF?

查看:199
本文介绍了如何在JSF中设置dataTable呈现列的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSF h:column标记修复宽度

我尝试过这种方式,但无法正常工作.使用呈现的HTML,我看不到Header或dataTable行的width属性.我正在使用没有任何组件库的JSF 1.2.可能是什么问题?

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. What could be the problem?

推荐答案

老实说,链接的答案对我来说没有任何意义.默认的JSF实现中的<h:column> 根本不支持这些属性.它为何获得6票并被标记为接受,这远远超出了我.将会是无知或巧合(也许发问者和答案都使用JSF实现,但我不知道哪个实现具有<h:column>的渲染器,该渲染器自动将所有未知属性转换为真实的HTML属性,但至少是标准JSF RI/Mojarra不这样做,也许是MyFaces?).

That linked answer honestly doesn't make sense to me. The <h:column> as it is in the default JSF implementation does not support those attributes at all. It's far beyond me why it got 6 votes and is marked accepted. It'll be ignorance or coincidence (maybe both the questioner and answer are using a JSF implementation I am not aware of which has a renderer for <h:column> which automagically converts all unknown attributes into real HTML attributes, but at least, the standard JSF RI / Mojarra doesn't do that, MyFaces maybe?).

也就是说,要分别设置列的样式,您需要使用

That said, to style the columns separately, you need to make use of the columnClasses attribute of the <h:dataTable>. It accepts a commaseparated string of CSS class names which will be subsequently applied on the <td> elemenes generated by <h:column>.

<h:dataTable columnClasses="column1,column2,column3">
    <h:column>...</h:column>
    <h:column>...</h:column>
    <h:column>...</h:column>
</h:dataTable>

这最终将变为:

<table>
    <tbody>
        <tr>
            <td class="column1">...</td>
            <td class="column2">...</td>
            <td class="column3">...</td>
        </tr>
    </tbody>
</table>

要指定宽度,只需相应地应用CSS.

To specify the width, just apply CSS accordingly.

.column1 { width: 200px; }
.column2 { width: 100px; }
.column3 { width: 50px; }

这篇关于如何在JSF中设置dataTable呈现列的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆