Bom dia pessoal,
Seguinte, estou tentando criar uma
via código, mas meu problema é em relação as columns, não consigo colocar os atributos nelas. Segue um exemplo do que estou querendo fazer…
MeuBean.java
class MeuBean {
private HtmlPanelGrid htmlPanelGrid;
public MeuBean() {
htmlPanelGrid = (HtmlPanelGrid) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlPanelGrid.COMPONENT_FAMILY);
//Defino os atributos da <table>
htmlPanelGrid.setCellpadding("0");
htmlPanelGrid.setCellspacing("0");
htmlPanelGrid.setBorder(0);
htmlPanelGrid.setStyle("height: 24px;");
htmlPanelGrid.setWidth("100%");
htmlPanelGrid.setColumns(3);
//Define as classes para as coluna
htmlPanelGrid.setColumnClasses("classe1,classe1,classe1");
for(int i = 0; i < 3; i++) {
HtmlColumn htmlColumn = (HtmlColumn) getApplication().createComponent(HtmlColumn.COMPONENT_TYPE);
//Tentando definir dois atributos para as colunas
htmlColumn.setValueExpression("width", createValueExpression("90",String.class));
htmlColumn.setValueExpression("align", createValueExpression("center", String.class));
HtmlOutputText htmlOutputText = (HtmlOutputText) getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
htmlOutputText.setValue("teste");
htmlColumn.getChildren().add(htmlOutputText);
htmlPanelGrid.getChildren().add(htmlPanelGrid);
}
}
public HtmlPanelGrid getHtmlPanelGrid() {
return this.htmlPanelGrid;
}
}
Na minha pagina jsp eu coloco o seguinte
....
<h:panelGrid id="menuTable" binding="#{meuBean.htmlPanelGrid}" />
....
Acontece que quando ele termina de renderizar a página, o código que ele monta fica assim
table id="menuTable" border="0" cellpadding="0" cellspacing="0" style="height: 24px;" width="100%">
<tbody>
<tr>
<td class="classe1">teste</td>
<td class="classe1">teste</td>
<td class="classe1">teste</td>
</tr>
</tbody>
</table>
Mas eu gostaria que ficasse assim
table id="menuTable" border="0" cellpadding="0" cellspacing="0" style="height: 24px;" width="100%">
<tbody>
<tr>
<td width="90" align="center" class="classe1">teste</td>
<td width="90" align="center" class="classe1">teste</td>
<td width="90" align="center" class="classe1">teste</td>
</tr>
</tbody>
</table>
Já pesquisei no google, procurei em varios sites mas não consegui resolver o meu problema… Usar as bibliotecas do richfaces seria uma solução pois ele atribui estes valores, mas em contra partida o richfaces coloca uns estilo dele que eu também já me aborreci… minha solução seria usar os componentes do jsf mesmo mas o que estou fazendo errado?
Estou usando o método setValueExpression de maneira errada? Olhei também alguns exemplos que usam o método setValueBinding mas na documentação este método está marcado com @Deprecated e eles sugerem usar o setValueExpression, mas eu uso e não acontece nada!
Alguém poderia me dar uma solução de como atribuir estes atributos nas minhas colunas?!