I'm starting to work with PrimeFaces 5.2, my IDE is Eclipse Luna 4.4.2, Java 1.7 and JSF 2.1.
I have a view with a DataTable, there's a column called holding two CommandButtons, one for editing and another one for deleting. When the edit button is pressed I show a modal Dialog filled with an external xhtml file which also has its own ManagedBean.
I want to pass the selected object from the DataTable to the external xhtml's ManagedBean so its fields are filled with the information from it.
My Excepciones.xhtml looks like this:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/facelets/templates/plantillaPrincipal.xhtml">
<ui:define name="mainBody">
<h:form id="form">
<p:dataTable var="excepcion" value="#{excepcionesView.lazyModel}"
paginator="true" rows="10" paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single"
selection="#{excepcionesView.selectedExcepcion}" id="excepcionTable"
lazy="true">
<p:ajax event="rowSelect" listener="#{excepcionesView.onRowSelect}"
update=":form:excepcionDetail"
oncomplete="PF('excepcionDialog').show()" />
<p:column headerText="Id" sortBy="#{excepcion.id}">
<h:outputText value="#{excepcion.id}" />
</p:column>
....
<p:column headerText="Acciones">
<p:commandButton icon="ui-icon-pencil" action="#{excepcionesView.viewExcepcionEditar}" >
<f:setPropertyActionListener value="#{excepcion}"
target="#{excepcionesView.selectedExcepcion}" />
</p:commandButton>
...
</p:column>
</p:dataTable>
...
</h:form>
</ui:define>
</ui:composition>
It's ManagedBean:
@ManagedBean(name="excepcionesView")
@ViewScoped
public class ExcepcionesView implements Serializable{
private LazyDataModel<Excepcion> lazyModel;
private Excepcion selectedExcepcion;
@ManagedProperty("#{excepcionService}")
private ExcepcionService service;
@PostConstruct
public void init() {
lazyModel = new ExcepcionDataModel(service.createExcepciones(200));
}
public void viewExcepcionEditar() {
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("selectedExcepcion", selectedExcepcion);
Map<String,Object> options = new HashMap<String, Object>();
options.put("modal", true);
options.put("draggable", false);
options.put("resizable", false);
options.put("contentHeight", 320);
RequestContext.getCurrentInstance().openDialog("ExcepcionEdicion", options, null);
}
...
}
As you can see, I call the method viewExcepcionEditar to store the selected row and display a dialog that will load my ExcepcionEdicion.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<h:outputStylesheet library="theme" name="css/style.css" />
</h:head>
<h:body>
<h:form id="productoEditarForm">
<p:panelGrid id="productoEditarGrid" styleClass="tablaSinBorde" columns="2" >
<p:outputLabel for="nombreTxt" value="Nombre: "/>
<h:inputText id="nombreTxt" value="#{editarExcepcionView.excepcion.nombre}" />
<p:outputLabel for="ldcTxt" value="Línea de Crédito: "/>
<h:inputText id="ldcTxt" value="#{editarExcepcionView.excepcion.lineaCredito}"/>
</p:panelGrid>
<p:commandButton id="aceptarBtn" value="Aceptar" />
<p:commandButton id="cancelarBtn" value="Cancelar" />
</h:form>
</h:body>
</html>
and it's bean contains:
@ManagedBean(name="editarExcepcionView")
@ViewScoped
public class EditarExcepcionView implements Serializable{
private String excepcionId;
private Excepcion excepcion;
public EditarExcepcionView(){
System.out.println("hey");
excepcion = (Excepcion) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("selectedExcepcion");
System.out.println("excepcion " + excepcion.getNombre());
}
....
}
In its constructor I try to read the parameter I placed but it always comes as null.
How can I pass this object between these beans so the information from said object can be read and displayed on my modal Dialog?