我正在组件内部创建列,数据表然后使用新列正确呈现,但是不会执行在其中声明的actionListeners。我甚至检查过它向服务器发送请求的组件......但是就像没有定义动作监听器一样。这是我用来创建表的代码,可能是错的???。
public void addColumns(){
UIDataTable dataTable = (UIDataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("frmAdmArt:dtArtResult:dtArticulos");
for(int i=0;i<2;i++){
UIColumn column = (UIColumn) FacesContext.getCurrentInstance().getApplication().createComponent(UIColumn.COMPONENT_TYPE);
if(i==0){
column.setStyle("width:36.5px;white-space:nowrap;");
HtmlOutputText values = (HtmlOutputText) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
values.setValue("No"+i);
column.getChildren().add(values);
}
if(i==1){
column.setStyle("width:151px;white-space:nowrap;");
UICommandLink commandLink = (UICommandLink) FacesContext.getCurrentInstance().getApplication().createComponent(UICommandLink.COMPONENT_TYPE);
commandLink.addActionListener(getMethodExpressionActionListener("cc.attrs.controller.verDetalleArticulo"));
commandLink.setValueExpression("value", createValueExpression("#{!empty detalle.codigoBarrasActivo.id.codigoBarras ? detalle.codigoBarrasActivo.id.codigoBarras : '----'}", String.class));
commandLink.setTitle("Detalle artículo");
commandLink.setExecute("@this");
commandLink.setImmediate(true);
commandLink.setId("verDestalle");
column.getChildren().add(commandLink);
}
column.setId("col"+i);
dataTable.getChildren().add(i, column);
}
}
private MethodExpressionActionListener getMethodExpressionActionListener(String method){
FacesContext facesContext = FacesContext.getCurrentInstance();
return new MethodExpressionActionListener(facesContext.getApplication().getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
"#{" + method + "}", Void.TYPE, new Class[] { ActionEvent.class }));
}