can't display the result of a <a4j:commandButton> action in RF 4.2.2
pepelara Sep 8, 2012 2:44 PMHi,
I have developed a richfaces xhtml file managed by its corresponding bean.
In the first action I can display a selected field type of List of an entity.
In the second action I need to select one of the items in the list. This list
is displayed in a <rich:dataTable> as follows,
<rich:dataTable var="cat" value="#{familiaAgent.categorias}"> <rich:column> <f:facet name="header">Nombre</f:facet> <h:outputText value="#{cat.nombre}" /> </rich:column> <rich:column> <f:facet name="header">Seleccionar</f:facet> <a4j:commandButton value="Seleccionar" render="ctg" action="#{familiaAgent.selectCategoria}"> <a4j:param name="sId" value="1" assignTo="#{familiaAgent.sId}" noEscape="true" /> <a4j:param name="cId" value="#{cat.id}" assignTo="#{familiaAgent.id}" noEscape="true" /> </a4j:commandButton> </rich:column> </rich:dataTable>
The second action is the one executed by the second column.
But it does not do what I spect, in fact it does nothing.
Here is the output (render="ctg")
<h:panelGrid id="editPane" rendered="#{familiaAgent.categoriaSelected eq true}"> <rich:panel id="ctg"> <h:outputText value="ID: #{familiaAgent.categoria.id}" /> <h:outputText value="Nombre: #{familiaAgent.categoria.nombre}" /> </rich:panel> </h:panelGrid>
And here is the bean,
@RequestScoped @Named("familiaAgent") public class FamiliaAgent { @Inject private FamiliaDAO familiaDAO; private Familia familia; private List<Categoria> categorias; private Categoria categoria; private Integer id; private String sId; private boolean familiaSelected; private boolean categoriasSelected; private boolean categoriaSelected; public void selectCategorias() { // NOTE get a fresh reference that's managed by the extended persistence context try { if(sId != null) { Integer iId = Integer.valueOf(sId); familia = familiaDAO.buscarPorId(iId); if (familia != null) { categorias = familia.getCategorias(); familiaSelected = true; categoriasSelected = true; } } } catch(Exception ex) { familiaSelected = false; categoriasSelected = false; } } public void selectCategoria() { // NOTE get a fresh reference that's managed by the extended persistence context try { if(sId != null) { Integer iId = Integer.valueOf(sId); familia = familiaDAO.buscarPorId(iId); if (familia != null) { categorias = familia.getCategorias(); if(id != null) { categoria = categorias.get(id); } familiaSelected = true; categoriaSelected = true; } } } catch(Exception ex) { familiaSelected = false; categoriaSelected = false; } } public void cancel() { categoria = null; categorias = null; familia = null; familiaSelected = false; categoriasSelected = false; categoriaSelected = false; } public Familia getFamilia() { return familia; } public void setFamilia(final Familia familia) { this.familia = familia; } public List<Categoria> getCategorias() { return categorias; } public void setCategorias(final List<Categoria> categorias) { this.categorias = categorias; } public Categoria getCategoria() { return categoria; } public void setCategoria(final Categoria categoria) { this.categoria = categoria; } public boolean isFamiliaSelected() { return familiaSelected; } public boolean isCategoriasSelected() { return categoriasSelected; } public boolean isCategoriaSelected() { return categoriaSelected; } public void setId(final Integer id) { this.id = id; } public Integer getId() { return id; } public void setsId(final String sId) { this.sId = sId; } public String getsId() { return sId; } }
I am not sure if it is due the commandButton is in the table or what else
but it does not work.
Both the table and the displayed result are all enclosed in the same form.
Thanks in advance,
Regards,
Jose
El mensaje fue editado por: Jose Alvarez de Lara