Possible to set HtmlDataTable column width in backingbean

332 Views Asked by At

As the title suggests, I'm looking for a way to set a column's width in my backing bean. There's a panel on the jsp that is common to several screens; its content is loaded depending on which screen the user is currently viewing. For this particular screen, I'm creating an HtmlDataTable in the backing bean, which is then added to the panel.

I need to change its width for a specific column. I can access the column as a UIColumn, but UIColumn does not have a width attribute. Perhaps something using ColumnClasses, but searching Google turned up no leads.

Any ideas?

1

There are 1 best solutions below

2
On BEST ANSWER

Since you have mentioned about column classes I post this. I don't know exactly whether this solves your problem. If not please clarify little bit. 1.You should have style classes like this.

<style>
.first{
       background-color:green;
       width:100px;
  }
.second{
       background-color:yellow;
       width:200px;
 }
</style>

Your table will be as below

<h:dataTable value="" binding="#{myBean.table}">
      <rich:column>First Column</rich:column>
      <rich:column>Second Column</rich:column>
</h:dataTable>

Your bean contains some what like this.

HtmlDataTable table = new HtmlDataTable();

public HtmlDataTable getTable() {
      table.setStyle("border:solid");
      table.setColumnClasses("first, second");
      return table;
}
public void setTable(HtmlDataTable table) {
      this.table = table;
}