selected value in p:selectOneMenu was lost - jsf

Good day!
I'm using JSF 2.1 Primefaces 4.0 Glassfish 3.2.1
In my Form.xhtml, I have this code.
<h:form id="modDlgFormc">
<p:dialog id="modIDc" header="Criteria Info"
showEffect="fade" hideEffect="fade" modal="true"
resizable="false" widgetVar="modDlgc" closable="false"
position="center" visible ="#{Fame.modVisiblec}">
<p:messages id="pmsgCrit" closable="true"/>
<h:panelGrid id="criteriapGrid" columns="1">
<h:panelGrid id="critLabelId" columns="2">
<p:selectOneMenu id="fieldNameId" value="#
{Fame.fieldName}" var="fieldSelect">
<f:selectItem itemLabel="Select Field Name"
itemValue="" />
<f:selectItems value="#{Fame.fieldNameMap}" />
<p:ajax event="change" update="fieldNameId
operandId" listener="#{Fame.fieldNameChange}"/>
</p:selectOneMenu>
<p:selectOneMenu id="operandId" value="#{Fame.operator}" >
<f:selectItem itemLabel="Select Operand" itemValue="" />
<f:selectItems value="#{Fame.operandMap}" />
<p:ajax event="change" update="operandId valueId"
listener="#{Fame.operandChange}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="valueId" columns="2">
<c:if test="#{Fame.showValue == 'txt'}">
<h:outputLabel for="inputVal" value="Value : " style="font-weight: bolder"/>
<p:inputText id="inputVal" size="30" value="#{Fame.value}"/>
<c:if test="#{Fame.operator == 'Is Between'}">
<h:outputText value=""/>
<p:inputText size="30" value="#{Fame.value2}"/>
</c:if>
</c:if>
<c:if test="#{Fame.showValue == 'cal'}">
<h:outputLabel for="fromDateId" value="From : " style="font-weight: bolder"/>
<p:calendar id="fromDateId" value="#{Fame.date}" showButtonPanel="true" maxdate="#{Fame.maxDate}"/>
<c:if test="#{Fame.operator == 'Is Between'}">
<h:outputLabel for="toDateId" value="To : " style="font-weight: bolder"/>
<p:calendar id="toDateId" value="#{Fame.date2}" showButtonPanel="true" maxdate="#{Fame.maxDate}"/>
</c:if>
</c:if>
<c:if test="#{Fame.showValue == 'upload'}">
<h:outputText value=""/>
<p:commandButton value="UPLOAD" onclick="uconfirmation.show()" type="button" />
</c:if>
</h:panelGrid>
<h:panelGrid id="critBtnId" columns="4">
<p:commandButton id="addBtn" value="ADD" actionListener="#{Fame.saveCriteria}" update=":modDlgFormc:modIDc" rendered="#{empty Fame.editMode}" />
<p:commandButton value="SAVE" actionListener="#{Fame.updateCriteria}" update=":modDlgFormc:modIDc" rendered="#{not empty Fame.editMode}"/>
<p:commandButton value="CANCEL" actionListener="#{Fame.cancelCriteria}" update=":modDlgFormc" rendered="#{not empty Fame.editMode}"/>
<p:commandButton id="mCancelButtonc" value="CLOSE" update=":modDlgFormc:modIDc :wbookForm" actionListener="#{Fame.closealldialogsopen}"/>
</h:panelGrid>
<br/>
</h:panelGrid>
<center>
<h:panelGrid id="critDTable" columns="1">
<p:dataTable id="criteriaTbl" var="criteria" value="#{Fame.createdCriteria}" paginator="true" rows="5" rowIndexVar="rowIndex" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="{totalRecords} record(s) in {totalPages} page(s)">
<p:column headerText="WORKSHEET NAME">
#{criteria.wsheetName}
</p:column>
<p:column headerText="FIELD NAME">
#{criteria.fieldName}
</p:column>
<p:column headerText="OPERATOR">
#{criteria.operator}
</p:column>
<p:column headerText="VALUE">
#{criteria.value}
</p:column>
<p:column headerText="UPDATE">
<p:panelGrid>
<p:row>
<p:column style="vertical-align: top;border: none">
<p:commandButton actionListener="#{Fame.editCri(rowIndex)}" style="width:30px;text-align:center;border:none;background-color:transparent;" icon="ui-icon-pencil" update=":modDlgFormc" />
<p:commandButton actionListener="#{Fame.deleteCri(rowIndex)}" style="width:30px;text-align:center;border:none;background-color:transparent;" icon="ui-icon-close" update=":modDlgFormc" />
</p:column>
</p:row>
</p:panelGrid>
</p:column>
</p:dataTable>
</h:panelGrid>
</center>
</p:dialog>
</h:form>
My Main code
#ManagedBean(name = "Fame")
#SessionScoped
private FameCriteriaDAOImpl fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
private ArrayList<FameCriteriaBean> createdCriteria = new ArrayList();
public void saveCriteria() {
fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
try {
if (this.validate() == true) {
//String wsheetId = fameManagementDP.getWsheetId(group_Id, workbookName);
FameCriteriaBean bean = new FameCriteriaBean();
bean.setWsheetId(this.worksheetId);
bean.setFieldName(this.fieldName);
bean.setOperator(this.operator);
bean.setValue(this.value);
String actionStr = "inserted";
fameCriteriaDAOImpl.save(bean);
}
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
error(converter.getConvertedError(sqlEx.getMessage()));
} finally {
this.initialize();
this.initializeCreatedCriteria();
this.resetCriteria();
}
}
My Bean code.
public class FameCriteriaBean {
private String wsheetName = "";
private String wsheetId = "";
private String fieldName = "";
private String operator = "";
private String value = "";
public FameCriteriaBean(){
}
/**
* #return the fieldName
*/
public String getFieldName() {
return fieldName;
}
/**
* #param fieldName the fieldName to set
*/
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
/**
* #return the operator
*/
public String getOperator() {
return operator;
}
/**
* #param operator the operator to set
*/
public void setOperator(String operator) {
this.operator = operator;
}
/**
* #return the value
*/
public String getValue() {
return value;
}
/**
* #param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* #return the wsheetId
*/
public String getWsheetId() {
return wsheetId;
}
/**
* #param wsheetId the wsheetId to set
*/
public void setWsheetId(String wsheetId) {
this.wsheetId = wsheetId;
}
/**
* #return the wsheetName
*/
public String getWsheetName() {
return wsheetName;
}
/**
* #param wsheetName the wsheetName to set
*/
public void setWsheetName(String wsheetName) {
this.wsheetName = wsheetName;
}
}
Below is the scenario.
I choose a fieldName then the lists of operand was loaded. This is correct.
I click the button ADD, then a p:message appear that there is no operand selected. This is correct.
I had noticed that the fieldname value that I was selected when error appears was gone.
My question is how not to refresh the value of fieldNameId so that I can use it after an error is displayed in p:message.
I'm using SessionScoped for my java class because I'm using p:wizard in Form.xhtml.
Please help me to solve this.
Thank you and More Power! :)

What I did is this.
Please see updated Main class
#ManagedBean(name = "Fame")
#SessionScoped
private FameCriteriaDAOImpl fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
private ArrayList<FameCriteriaBean> createdCriteria = new ArrayList();
public void saveCriteria() {
fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
if (!this.validate()) {
return;
}
try {
FameCriteriaBean bean = new FameCriteriaBean();
bean.setWsheetId(this.worksheetId);
bean.setFieldName(this.fieldName);
bean.setOperator(this.operator);
bean.setValue(this.value);
String actionStr = "inserted";
fameCriteriaDAOImpl.save(bean);
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
error(converter.getConvertedError(sqlEx.getMessage()));
} finally {
this.initialize();
this.initializeCreatedCriteria();
this.resetCriteria();
}
}

Related

I'm trying to initilize an attribut in a bean with #viewScoped but it does not work

hello everyone I'm trying to build a webpage with two oneMenu the second one depending on the second one. My XHTML file is below as well as my bean.
when I try to create a new "structureAttache" I have the following problem
TemplateStructureAttache.xhtml #40,139 value="#{structureBean.structureAttache.intituleStructure}": Target Unreachable, 'structureAttache' returned null
and when I use the method initStruc to create a new structureAttache then I call it in the listener of my first ajax, I succeed to create a structureAttache but when I do it for the second time, it seems like the value already exit in the DB and it refuses please help me to solve this issue
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dresen.dresen.Beans;
import com.dresen.dresen.ServiceInterface.IArrondissementService;
import com.dresen.dresen.ServiceInterface.IStructureService;
import com.dresen.dresen.entities.Arrondissement;
import com.dresen.dresen.entities.StructureAttache;
import com.dresen.dresen.entities.CategorieStructure;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import com.dresen.dresen.ServiceInterface.ICategorieStructureService;
import com.dresen.dresen.ServiceInterface.IDepartementService;
import com.dresen.dresen.entities.Departement;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
/**
*
* #author Vivien Saa
*/
#ManagedBean
#ViewScoped
public class StructureBean implements Serializable{
#ManagedProperty(value = "#{IStructureService}")
private IStructureService iStructureService;
#ManagedProperty(value = "#{IArrondissementService}")
private IArrondissementService iArrondissementService;
#ManagedProperty(value = "#{ICategorieStructureService}")
private ICategorieStructureService iCategorieStructureService;
#ManagedProperty(value ="#{IDepartementService}")
private IDepartementService iDepartementService;
private long idDepartement;
private long idArrondissement;
private long idCategorieStructure;
private StructureAttache structureAttache;
private List<Arrondissement> listArrondissement;
private List<Departement> listDepartement;
private List<CategorieStructure> listCategorieStructure;
private Arrondissement arrondissement = new Arrondissement();
private CategorieStructure CategorieStructure = new CategorieStructure();
public StructureBean() {
structureAttache = new StructureAttache();
idDepartement = 0L;
idArrondissement = 0L;
idCategorieStructure = 0L;
}
public ICategorieStructureService getiCategorieStructureService() {
return iCategorieStructureService;
}
public void setiCategorieStructureService(ICategorieStructureService iCategorieStructureService) {
this.iCategorieStructureService = iCategorieStructureService;
}
public long getIdDepartement() {
return idDepartement;
}
public void setIdDepartement(long idDepartement) {
this.idDepartement = idDepartement;
}
public IDepartementService getiDepartementService() {
return iDepartementService;
}
public void setiDepartementService(IDepartementService iDepartementService) {
this.iDepartementService = iDepartementService;
}
public List<Departement> getListDepartement() {
return iDepartementService.findAllDepartement();
}
public void setListDepartement(List<Departement> listDepartement) {
this.listDepartement = listDepartement;
}
public long getIdCategorieStructure() {
return idCategorieStructure;
}
public void setIdCategorieStructure(long idCategorieStructure) {
this.idCategorieStructure = idCategorieStructure;
}
public List<CategorieStructure> getListCategorieStructure() {
return iCategorieStructureService.findAllCategorieStructure();
}
public void setListCategorieStructure(List<CategorieStructure> listCategorieStructure) {
this.listCategorieStructure = listCategorieStructure;
}
public IStructureService getiStructureService() {
return iStructureService;
}
public void setiStructureService(IStructureService iStructureService) {
this.iStructureService = iStructureService;
}
public IArrondissementService getiArrondissementService() {
return iArrondissementService;
}
public void setiArrondissementService(IArrondissementService iArrondissementService) {
this.iArrondissementService = iArrondissementService;
}
public long getIdArrondissement() {
return idArrondissement;
}
public void setIdArrondissement(long idArrondissement) {
this.idArrondissement = idArrondissement;
}
public StructureAttache getStructureAttache() {
return structureAttache;
}
public void setStructureAttache(StructureAttache structureAttache) {
this.structureAttache = structureAttache;
}
public List<Arrondissement> getListArrondissement() {
return iArrondissementService.findArrondissementByIdDepart(idDepartement);
}
public void setListArrondissement(List<Arrondissement> listArrondissement) {
this.listArrondissement = listArrondissement;
}
public Arrondissement getArrondissement() {
return arrondissement;
}
public void setArrondissement(Arrondissement arrondissement) {
this.arrondissement = arrondissement;
}
public CategorieStructure getCategorieStructure() {
return CategorieStructure;
}
public void setCategorieStructure(CategorieStructure CategorieStructure) {
this.CategorieStructure = CategorieStructure;
}
public void initStruc() {
structureAttache = new StructureAttache();
}
public StructureAttache createStructure(){
System.out.println("vvsssssssssvsssssssssssssssssssssssvv why don't you work");
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.createStructureAttache(structureAttache);
}
public StructureAttache findStructureById(){
return iStructureService.findStructureAttacheById(structureAttache.getId());
}
public StructureAttache updateStructure(){
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.updateStructureAttache(structureAttache);
}
public List<StructureAttache> findAllStructure(){
return iStructureService.findAllStructureAttache();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Application de gestion du personnel des services déconcentrés du MINESEC EXTREME NORD</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<h:body>
<div id="menu">
<ui:include src="Menu.xhtml"/>
</div>
<f:view>
<p:dialog widgetVar="dlg" header=" Enregistrer une nouvel nouvelle Structure d'attache " hideEffect="explode" showEffect="explode" modal="true">
<h:form id="formAjouter" >
<p:panelGrid id="panelAjouter" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<p:commandButton value="Enregistrer" action="#{structureBean.createStructure()}" oncomplete="PF('dlg').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="dl" header=" Modifier une structure d'attache" hideEffect="fold" showEffect="explode" resizable="true">
<h:form id="formModifier" enctype="multipart/form-data">
<p:panelGrid id="panelGModifier" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<h:inputHidden id="number" value="#{structureBean.structureAttache.id}" />
<p:commandButton value="Modifier" action="#{structureBean.updateStructure()}" oncomplete="PF('dl').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
</f:view>
<f:view>
<h:form id='tableForm'>
<p:dataTable value="#{structureBean.findAllStructure()}" var="item" paginator="true" rows="10" paginatorTemplate=" {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} " id="table" rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{structureBean.structureAttache}" rowKey="#{item.id}">
<f:facet name="header">
La liste des Structures d'attache
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Structure"/>
</f:facet>
<h:outputText value="#{item.intituleStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Code/Abréviation Structure"/>
</f:facet>
<h:outputText value="#{item.codeStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Arrondissement"/>
</f:facet>
<h:outputText value="#{item.arrondissement.intituleArrondissement}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Département"/>
</f:facet>
<h:outputText value="#{item.arrondissement.departement.intituleDepartement}"/>
</p:column>
</p:dataTable>
<p:toolbar>
<f:facet name="left">
<p:commandButton type="push" onclick="PF('dlg').show();" value="Nouvelle Structure" icon="ui-icon-disk">
<p:ajax update=":formAjouter:panelAjouter" resetValues="true" />
</p:commandButton>
<p:commandButton onclick="PF('dl').show()" value="Modifier Structure" update=":formModifier:panelGModifier" icon="ui-icon-arrowrefresh-1-w"/>
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<p:commandButton type="push" title="Save" image="ui-icon-disk" />
<p:commandButton type="push" title="Update" icon="ui-icon-arrowrefresh-1-w"/>
<p:commandButton type="push" title="Print" image="ui-icon-print"/>
</f:facet>
</p:toolbar>
</h:form>
</f:view>
</h:body>
</html>
You can use a method to initialize your attributes as you would like to, then through an AJAX or and actionListener, you call the method that will do the job before you try to use the attribute.

f:setPropertyActionListener not invoked in p:dataTable

I followed Primefaces DataGrid showcase for doing my datatable. I want an edit imagebutton for each row of datatable and after onclick I want to show an edit dialog form.
The problem is that setSelectedChannel method not fired on commandlink click , so I have this error when dialog try to access to selecteChannel fields:
javax.el.PropertyNotFoundException: /WEB-INF/includes/channels.xhtml #54,91 value="#{channelBean.selectedChannel.name}": Target Unreachable, 'selectedChannel' returned null
So this is my xhtml include page:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:form id="channelForm">
<p:dataTable var="channel" value="#{channelBean.channels}">
<p:column headerText="Name">
<h:outputText value="#{channel.name}" />
</p:column>
<p:column headerText="Field 1">
<h:outputText value="#{channel.field1}" />
</p:column>
<p:column headerText="Field 2">
<h:outputText value="#{channel.field2}" />
</p:column>
<p:column headerText="ApiWriteKey">
<h:outputText value="#{channel.apiWriteKey}" />
</p:column>
<p:column headerText="Edit">
<p:commandLink update=":channelForm:panelEditCh" oncomplete="PF('dlg2').show();" title="Edit">
<h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
<f:setPropertyActionListener value="#{channel}" target="#{channelBean.selectedChannel}" />
</p:commandLink>
</p:column>
</p:dataTable>
<p:dialog id="dialogNewChannel" header="New Channel" widgetVar="dlg1" modal="false" >
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="channelName" value="Channel name:" />
<p:inputText id="channelName" value="#{channelBean.name}" />
<p:outputLabel for="channelDesc" value="Channel description:" />
<p:inputText id="channelDesc" value="#{channelBean.description}" />
<p:outputLabel for="channelField1" value="Channel field 1:" />
<p:inputText id="channelField1" value="#{channelBean.field1}" />
<p:outputLabel for="channelField2" value="Channel field 2:" />
<p:inputText id="channelField2" value="#{channelBean.field2}" />
</h:panelGrid>
<p:commandButton id="saveButton" value="Save" action="#{channelBean.saveChannel}" update="channelForm" ajax="true" />
<p:commandButton value="Cancel" type="button" action="#{channelBean.resetForm}" onclick="PF('dlg1').hide();" />
</p:dialog>
<p:dialog id="dialogEditChannel" header="Edit Channel" widgetVar="dlg2" modal="false" >
<h:panelGrid id="panelEditCh" columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="channelNameEdit" value="Channel name:" />
<p:inputText id="channelNameEdit" value="#{channelBean.selectedChannel.name}" />
<p:outputLabel for="channelDescEdit" value="Channel description:" />
<p:inputText id="channelDescEdit" value="#{channelBean.selectedChannel.description}" />
<p:outputLabel for="channelField1Edit" value="Channel field 1:" />
<p:inputText id="channelField1Edit" value="#{channelBean.selectedChannel.field1}" />
<p:outputLabel for="channelField2Edit" value="Channel field 2:" />
<p:inputText id="channelField2Edit" value="#{channelBean.selectedChannel.field2}" />
</h:panelGrid>
<p:commandButton id="saveButtonEdit" value="Save" action="#{channelBean.saveChannel}" update="channelForm" ajax="true" />
<p:commandButton value="Cancel" type="button" action="#{channelBean.resetForm}" onclick="PF('dlg2').hide();" />
</p:dialog>
<p:spacer></p:spacer>
<p:spacer></p:spacer>
<p:commandButton value="New Channel" type="button" onclick="PF('dlg1').show();" />
<!-- <p:blockUI block="dialogNewChannel" trigger="saveButton">
<p:graphicImage name="images/ajax-loader-large.gif"/>
</p:blockUI>
-->
</h:form>
and ManagedBean :
#ManagedBean
#ViewScoped
public class ChannelBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1668407926998690759L;
private String idChannel;
private String apiWriteKey;
private String name;
private String description;
private String userId;
private String field1;
private String field2;
private Channel selectedChannel;
private List<Channel> channels= new ArrayList<Channel>() ;
#PostConstruct
public void populateChannelList(){
refreshList();
}
public void refreshList(){
HttpSession session = Util.getSession();
int idUser=-1;
if(session!=null &&session.getAttribute("idUser")!=null){
idUser=(int) session.getAttribute("idUser");
}
channels=ChannelDAO.getChannels(idUser);
}
public void saveChannel(){
....
}
public void resetForm(){
idChannel="";
apiWriteKey="";
name="";
description="";
userId="";
field1="";
field2="";
}
public String getIdChannel() {
return idChannel;
}
public void setIdChannel(String idChannel) {
this.idChannel = idChannel;
}
public String getApiWriteKey() {
return apiWriteKey;
}
public void setApiWriteKey(String apiWriteKey) {
this.apiWriteKey = apiWriteKey;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getField1() {
return field1;
}
public void setField1(String field1) {
this.field1 = field1;
}
public String getField2() {
return field2;
}
public void setField2(String field2) {
this.field2 = field2;
}
public List<Channel> getChannels() {
return channels;
}
public void setChannels(List<Channel> channels) {
this.channels = channels;
}
public Channel getSelectedChannel() {
return selectedChannel;
}
public void setSelectedChannel(Channel selectedChannel) {
this.selectedChannel = selectedChannel;
}
}

Save button of dialog is not firing bean method

I'm trying to implement an edit functionality by using a dialog that loads row data from a data table. I'm able to load staff details fro the data table into the dialog and display save button accordingly. But my save button is not firing my bean method to save the updated record in the dialog.What could I be missing, Here are my codes,
the .xhtml file
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Asset Manager-Home</title>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="200">
<h:outputText value="Home content." />
</p:layoutUnit>
<p:layoutUnit position="south" size="50">
<h:outputText value="All Rights Reserved." />
</p:layoutUnit>
<p:layoutUnit position="west" size="250" header="">
<h:form>
<p:panelMenu>
<p:submenu label="Home">
<p:menuitem value="Home" url="/faces/index.xhtml" />
</p:submenu>
<p:submenu label="Staff">
<p:menuitem value="Create Staff " url="/face/createStaff.xhtml" icon="ui-icon-disk" />
<p:menuitem value="Update Staff " url="/faces/updateStaff.xhtml" />
<p:menuitem value="All Staff " url="/faces/updateStaff.xhtml" />
</p:submenu>
<p:submenu label="Categories">
<p:menuitem value="Create Category" url="/faces/createCategory.xhtml" icon="ui-icon-disk" />
<p:menuitem value="Update Category" url="/faces/updateCategory.xhtml" />
<p:menuitem value="View Category" url="/faces/updateCategory.xhtml" />
</p:submenu>
<p:submenu label="Asset">
<p:menuitem value="Create Asset" url="/faces/createAsset.xhtml" icon="ui-icon-disk" />
<p:menuitem value="Update Asset" url="/faces/updateAsset.xhtml" />
<p:menuitem value="All Asset" url="/faces/updateAsset.xhtml" />
</p:submenu>
<p:submenu label="Asset Status">
<p:menuitem value="Create/Update Status Register" url="/faces/CreateStatus.xhtml" />
</p:submenu>
<p:submenu label="Assigned Asset">
<p:menuitem value="Assign Asset" url="/faces/assignAsset.xhtml" icon="ui-icon-disk" />
<p:menuitem value="Do Update" url="/faces/updateAssignAsset.xhtml" />
<p:menuitem value="View All" url="/faces/updateAssignAsset.xhtml" />
</p:submenu>
<p:submenu label="Reports">
</p:submenu>
</p:panelMenu>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="east" size="250" header="Right">
<h:outputText value="Right unit content." />
</p:layoutUnit>
<p:layoutUnit position="center">
<p:separator id="customSeparator" style="width:1000px;height:20px" />
<p:panel header="All Staff" id="allstaff">
<h:form prependId="false" id="staffform">
<p:dataTable id="dataTable" var="stf" value="#{allStaffTableBean.staffList}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" selectionMode="single"
selection="#{allStaffTableBean.selectedStaff}"
emptyMessage="KoblaGasu:: No data to be found for displaying"
rowKey="#{stf.uniqueID}">
<p:column sortBy="#{stf.uniqueID}" filterBy="#{stf.uniqueID}">
<f:facet name="header">
<h:outputText value="Staff ID" />
</f:facet>
<h:outputText value="#{stf.uniqueID}" />
</p:column>
<p:column sortBy="#{stf.firstName}" filterBy="#{stf.firstName}">
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:outputText value="#{stf.firstName}" />
</p:column>
<p:column sortBy="#{stf.lastName}" filterBy="#{stf.lastName}">
<f:facet name="header">
<h:outputText value="Last Name" />
</f:facet>
<h:outputText value="#{stf.lastName}" />
</p:column>
<f:facet name="footer">
<div>
<p:commandButton id="edit" value="Edit" update=":staffform:display" onclick="PF('StaffEditDialog').show()" />
<p:commandButton id="delet" value="Delete" />
</div>
</f:facet>
</p:dataTable>
<p:dialog id="StaffEditDlg" widgetVar="StaffEditDialog" modal="true" resizable="false" appendTo="#(body)" header="Edit Staff" closeOnEscape="true">
<h:panelGroup id="display">
<p:panelGrid columns="2" rendered="#{allStaffTableBean.selectedStaff != null}">
<h:outputLabel value="Staff ID" for="staffUniqueID" />
<h:outputText id="staffUniqueID" value="#{allStaffTableBean.selectedStaff.uniqueID}" />
<p:outputLabel value="First Name" for="firstName" />
<p:inputText id="firstName" value="#{allStaffTableBean.selectedStaff.firstName}" title="First Name" size="45" maxlength="45" />
<p:outputLabel value="Last Name" for="lastName" />
<p:inputText id="lastName" value="#{allStaffTableBean.selectedStaff.lastName}" title="Last Name" size="45" maxlength="45" />
</p:panelGrid>
<p:commandButton actionListener="#{allStaffTableBean.update}" value="Save" oncomplete="PF().hide();" />
<p:commandButton value="Cancel" onclick="StaffEditDialog.hide()" />
</h:panelGroup>
</p:dialog>
</h:form>
</p:panel>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
The staff bean
public class Staff implements Serializable
{
private String uniqueID;
private String firstName;
private String lastName;
/**
* Creates a new instance of Staff
*/
public Staff()
{
}
public Staff(String uniqueID, String firstName, String lastName)
{
this.uniqueID = uniqueID;
this.firstName = firstName;
this.lastName = lastName;
}
public void updateSaff(ActionEvent event)
{
boolean status = new StaffManager().updateStaff(uniqueID, firstName, lastName);
System.out.println("Kobla::Update called in Staff.java");
}
/**
* # return string's
*/
public String save()
{
StaffManager staffManager = new StaffManager();
boolean status = staffManager.saveStaff(uniqueID, firstName, lastName);
if(status == true)
{
return "index";
}
else
{
return "createStaff";
}
}
/**
* #return: method to call getSstaff for staff manager
*/
public String searchStaff()
{
Staff myStaff = new Staff();
myStaff = new StaffManager().getStaff(uniqueID);
this.uniqueID = myStaff.getUniqueID();
this.firstName = myStaff.getFirstName();
this.lastName = myStaff.getLastName();
return "updateStaff";
}
public String deleteStaff()
{
StaffManager staffManager = new StaffManager();
boolean status = staffManager.delStaff(uniqueID);
if(status == true)
{
return "index";
}
else
{
return "updateStaff";
}
}
/**
* #return the uniqueID
*/
public String getUniqueID()
{
return uniqueID;
}
/**
* #param uniqueID
* the uniqueID to set
*/
public void setUniqueID(String uniqueID)
{
this.uniqueID = uniqueID;
}
/**
* #return the firstName
*/
public String getFirstName()
{
return firstName;
}
/**
* #param firstName
* the firstName to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* #return the lastName
*/
public String getLastName()
{
return lastName;
}
/**
* #param lastName
* the lastName to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
#Override
public String toString()
{
return "Staff{" + "uniqueID=" + uniqueID + ", firstName=" + firstName + ", lastName=" + lastName + '}';
}
}
And a dataTable bean
public class AllStaffTableBean implements Serializable
{
private List<Staff> staffList;
private Staff selectedStaff;
/**
* Creates a new instance of AllStaffTableBean
*/
public AllStaffTableBean()
{
staffList = new ArrayList<>();
staffList = new StaffManager().getAllStaff();
for(Staff stf : staffList)
{
System.out.println("allstafftablebean:: " + stf);
}
{
System.out.println("selectedStaff :: " + selectedStaff);
}
}
public void update(ActionEvent event)
{
RequestContext context = RequestContext.getCurrentInstance();
new StaffManager().saveStaff(selectedStaff.getUniqueID(), selectedStaff.getFirstName(), selectedStaff.getLastName());
System.out.println("Update callded in allstafftablebean.java :: " + selectedStaff);
}
/**
* #return the staffList
*/
public List<Staff> getStaffList()
{
return staffList;
}
/**
* #return the selectedStaff
*/
public Staff getSelectedStaff()
{
return selectedStaff;
}
/**
* #param selectedStaff
* the selectedStaff to set
*/
public void setSelectedStaff(Staff selectedStaff)
{
this.selectedStaff = selectedStaff;
}
}
You have to tell commandButton what do you want to process, try with:
<p:commandButton actionListener
="#{allStaffTableBean.update}" value="Save" oncomplete="PF().hide();"
process="#this,StaffEditDlg"/>
or:
<p:commandButton actionListener
="#{allStaffTableBean.update}" value="Save" oncomplete="PF().hide();"
process="#this,#widgetVar(StaffEditDialog)"/>
For working with the data in the dialog, you have to process dataTable information (selected item) so:
<p:commandButton id="edit" value="Edit" update=":staffform:display"
onclick="PF('StaffEditDialog').show()" process=":staffform:dataTable" />
I recommend working with another instance of Staff to edit, remember that instances are just references, so if you change the value (for any reason), will be updated to all variables that have that reference, look up Shadow clone or deep clone. I think with these code will gonna work. If not, add a comment.
Have fun!

Calling another page using DataTable - Instant Row Selection

I have a dataTable but when I select a row nothing happens, I've tried calling p:dialog and nothing happened. I tried to redirect to another page with the selected data and also could not (this is my goal). What is missing in my code do. Below is my xhtml and bean.
xhtm:
<h:form id="form" style="font-size: 11pt">
<h3>Cancelar Processo de Portabilidade</h3>
<p:panel header="Consulta por Numeração" id="CancProcP1">
<h:panelGrid columns="3" style="margin-bottom:10px" cellpadding="5"
id="pgridTipoCanc1">
<p:selectOneRadio id="tipoCancela"
value="#{beanBuscarDadosCancPort.tipoBusca}">
<f:selectItem itemLabel="TN" itemValue="1" />
<f:selectItem itemLabel="Bilhete" itemValue="2" />
<f:selectItem itemLabel="Período" itemValue="3" />
<f:ajax render="pgridTipoCanc2" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"
id="pgridTipoCanc2">
<h:outputLabel for="tn" value="TN:"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '1'}" />
<h:inputText id="tn" value="#{beanBuscarDadosCancPort.tn}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '1'}" />
<h:outputLabel for="bilhete" value="Bilhete de Portabilidade:"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '2'}" />
<h:inputText id="bilhete"
value="#{beanBuscarDadosCancPort.srvProvId}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '2'}" />
<h:outputLabel for="dataInicial" value="Data Inicial"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
<p:calendar id="dataInicial"
value="#{beanBuscarDadosCancPort.dataInicial}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
<h:outputLabel for="dataFinal" value="Data Final"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
<p:calendar id="dataFinal"
value="#{beanBuscarDadosCancPort.dataFinal}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
</h:panelGrid>
<p:commandButton id="pesquisar"
action="#{beanBuscarDadosCancPort.pesquisar}"
value="Buscar" ajax="false" update="display" />
</p:panel>
</h:form>
<p:panel id="CancProcP2">
<h:form id="form2" style="font-size: 11pt">
<p:growl id="growl" showDetail="true"/>
<p:dataTable id="dataTable" var="valor"
value="#{beanBuscarDadosCancPort.listaNumeroPortado}"
paginator="true" rows="5" rowKey="#{valor.srvProvIdDoadoraAnterior}"
selection="#{beanBuscarDadosCancPort.selectedNumP}" selectionMode="single"
rowSelectListener="#{beanBuscarDadosCancPort.onRowSelect}"
onRowSelectUpdate="display growl"
onRowSelectComplete="carDialog.show()"
rowUnselectListener="#{beanBuscarDadosCancPort.onRowUnselect}"
onRowUnselectUpdate="growl"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="4,5,7"
style="max-width: 580px; min-width: 550px">
<f:facet name="header">
</f:facet>
<p:column selectionMode="single" style="width:18px" />
<p:column
style="max-width: 50px; min-width: 50px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Operadora Doadora" />
</f:facet>
<h:outputText value="#{valor.srvProvIdDoadoraAnterior}" />
</p:column>
<p:column
style="max-width: 40px; min-width: 40px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Bilhete" />
</f:facet>
<h:outputText value="#{valor.srvProvId}" />
</p:column>
<p:column
style="max-width: 40px; min-width: 40px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Data/Hora da Janela" />
</f:facet>
<h:outputText value="#{valor.dataJanelaPortabilidade}" />
</p:column>
<p:column
style="max-width: 40px; min-width: 40px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Telefone" />
</f:facet>
<h:outputText value="#{valor.tn}" />
</p:column>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="teste"/>
</f:facet>
<h:outputText value="Model:" />
<h:outputText value="#{beanBuscarDadosCancPort.selectedNumP.srvProvIdDoadoraAnterior}" />
</h:panelGrid>
</p:dialog>
</h:form>
Bean
public class BuscarDadosCancelarPortBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<NumeroPortado> regSelecionado = null;
private String tipoBusca;
private String tn;
private String srvProvId;
private Date dataInicial;
private Date dataFinal;
private List<NumeroPortado> listaNumeroPortado = null;
NumeroPortado numPortato = new NumeroPortado();
private NumPortadoDataModel numModel;
private NumeroPortado selectedNumP;
#EJB
private ConsultasSpnService consultaOp;
public List<NumeroPortado> pesquisar(){
String busca = null;
//String busca = "tn";
//String parametro = "1133100038";
String parametro = null;
String parametro2 = null;
if(tipoBusca.equals("1")){
parametro = tn;
busca = "tn";
}else if(tipoBusca.equals("2")){
parametro = srvProvId;//bilhete
busca = "bilhete";
}else if(tipoBusca.equals("3")){
//DateFormat df = new SimpleDateFormat("dd/MM/yy");
//parametro = df.format(dataInicial);
//parametro2 = df.format(dataFinal);
//busca = "data";
}
if(listaNumeroPortado == null){
listaNumeroPortado = new ArrayList<NumeroPortado>();
listaNumeroPortado = consultaOp.listarNumerosPortados(busca, parametro, parametro2);
//Excluir depois de descobrir porque não está pegando estes campos da tabela
for(int i=0;i<listaNumeroPortado.size();i++){
if(tipoBusca.equals("1")){
listaNumeroPortado.get(i).setTn(parametro);
}else if(tipoBusca.equals("2")){
listaNumeroPortado.get(i).setSrvProvId(parametro);
}
}
//numModel = new NumPortadoDataModel(listaNumeroPortado);
}
return listaNumeroPortado;
}
public String getTn() {
return tn;
}
public void setTn(String tn) {
this.tn = tn;
}
public String getSrvProvId() {
return srvProvId;
}
public void setSrvProvId(String srvProvId) {
this.srvProvId = srvProvId;
}
public Date getDataInicial() {
return dataInicial;
}
public void setDataInicial(Date dataInicial) {
this.dataInicial = dataInicial;
}
public Date getDataFinal() {
return dataFinal;
}
public void setDataFinal(Date dataFinal) {
this.dataFinal = dataFinal;
}
public String getTipoBusca() {
return tipoBusca;
}
public void setTipoBusca(String tipoBusca) {
this.tipoBusca = tipoBusca;
}
public List<NumeroPortado> getListaNumeroPortado() {
return listaNumeroPortado;
}
public void setListaNumeroPortado(List<NumeroPortado> listaNumeroPortado) {
this.listaNumeroPortado = listaNumeroPortado;
}
public NumeroPortado getNumPortato() {
return numPortato;
}
public void setNumPortato(NumeroPortado numPortato) {
this.numPortato = numPortato;
}
public ConsultasSpnService getConsultaOp() {
return consultaOp;
}
public void setConsultaOp(ConsultasSpnService consultaOp) {
this.consultaOp = consultaOp;
}
public List<NumeroPortado> getRegSelecionado() {
return regSelecionado;
}
public void setRegSelecionado(List<NumeroPortado> regSelecionado) {
this.regSelecionado = regSelecionado;
}
public NumPortadoDataModel getNumModel() {
return numModel;
}
public void setNumModel(NumPortadoDataModel numModel) {
this.numModel = numModel;
}
public NumeroPortado getSelectedNumP() {
return selectedNumP;
}
public void setSelectedNumP(NumeroPortado selectedNumP) {
this.selectedNumP = selectedNumP;
}
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage("Line Selected", ((NumeroPortado) event.getObject()).getTn());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowUnselect(UnselectEvent event) {
FacesMessage msg = new FacesMessage("Line Unselected", ((NumeroPortado) event.getObject()).getTn());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String onRowSelectNavigate(SelectEvent event) {
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedNumP", event.getObject());
return "cancelarPortabilidade?faces-redirect=true";
}
}
I changed the rowSelectListener = "#{beanBuscarDadosCancPort.onRowSelect}" by rowSelectListener = "#{beanBuscarDadosCancPort.onRowSelectNavigate}" without success!
I got using only the tag
<p:ajax event="rowSelect" listener="# {beanConsultaPorNum.onRowSelectHeader}" /> between <p:dataTable...> </p:dataTable>.

Ignore the set method of a value in p:inputText until the form is submitted

Anyone know of a way to assign the value of a p:inputText so it displays correctly in a dialog window but only update a change in the value from a commandButton action instead of a dynamic set method of the value in the backing bean. Have the users add a step and it shows up in the ring then they can click the individual steps, but I want them to be able to update the step info only through the update step button, not by just changing the field and closing the dialog? Built-in method would be prefer, I know I can code around, but trying not to.
Thanks in advance....
<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
<p:dialog modal="true" widgetVar="statusDialog" header="Status"
draggable="false" closable="false">
<p:graphicImage value="/resources/images/ajaxloadingbar.gif" />
</p:dialog>
<h:form id="form">
<p:panel header="Setup System" >
<p:selectOneMenu value="#{groups.selected_sys_code}" id="systems" rendered="#{utility.systemDD}">
<f:selectItem itemLabel="Choose System" itemValue="" />
<f:selectItems value="#{supportBean.access_system_codes}"/>
<p:ajax listener="#{groups.valueChanged}" event="valueChange" render="systemForm" execute="#all"/>
</p:selectOneMenu>
<h:panelGroup id="systemForm" >
<p:panel id="panel" header="Step Details">
<p:messages id="msgs"/>
<h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
<p:panelGrid columns="2" styleClass="veaGrid">
<h:outputLabel for="name" value="Name:"/>
<p:inputText id="name" value="#{setup.name}" label="Name" required="true"/>
<h:outputLabel for="desc" value="Description:"/>
<p:inputText id="desc" value="#{setup.description}" label="Description" required="true"/>
<h:outputLabel for="email" value="Email For Group Responsible:"/>
<p:inputText id="email" value="#{setup.emailResp}" label="Email" required="true"/>
<h:outputLabel for="process" value="Process:"/>
<p:inputText id="process" value="#{setup.process}" label="Process" required="true"/>
</p:panelGrid>
</h:panelGrid>
<p:commandButton value="Add Step" update="panel,stepsRing" actionListener="#{setup.setSteps}" process="#form" >
</p:commandButton>
<p:commandButton value="Submit All Steps" actionListener="setup.submitSteps">
</p:commandButton>
</p:panel>
</h:panelGroup>
<h:panelGroup id="stepsRing" >
<p:panel header="Steps">
<p:ring id="basic" value="#{setup.steps}" var="step" >
<p:column>
<p:outputPanel/>
<p:outputPanel style="text-align:center;" layout="block" >
Step #{step.sequence}
<br/>
<p:commandButton update=":form:detail" title="View" oncomplete="dlg.show()" value="Details" >
<f:setPropertyActionListener value="#{step}" target="#{setup.selectedStep}" />
</p:commandButton>
</p:outputPanel>
</p:column>
</p:ring>
</p:panel>
</h:panelGroup>
<p:dialog id="dialog" widgetVar="dlg" showEffect="fade" hideEffect="fade" modal="true" width="300" >
<p:outputPanel id="detail" style="text-align:center;" layout="block">
<h:panelGrid columns="2" cellpadding="5" rendered="#{not empty setup.selectedStep}">
<f:facet name="header">
Step #{setup.selectedStep.sequence}
</f:facet>
<h:outputText value="Name: " />
<p:inputText id="name2" value="#{setup.selectedStep.name}" />
<h:outputText value="Description: " />
<p:inputText id="desc2" value="#{setup.selectedStep.description}" />
<h:outputText value="Email: " />
<p:inputText id="email2" value="#{setup.selectedStep.emailResp}"/>
<h:outputText value="Process: " />
<p:inputText id="process2" value="#{setup.selectedStep.process}"/>
<p:commandButton update="stepsRing" actionListener="#{setup.removeStep}" title="Remove" oncomplete="dlg.hide()" value="Remove Step" >
<f:setPropertyActionListener value="#{step}" target="#{setup.selectedStep}" />
</p:commandButton>
<p:commandButton update="stepsRing" process="#form" actionListener="#{setup.updateStep}" title="Update" value="Update Step" >
<f:setPropertyActionListener value="#{step}" target="#{setup.selectedStep}" />
</p:commandButton>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</p:panel>
</h:form>
BackingBean
#ManagedBean(name="setup")
#ViewScoped
public class WorkStepSetupSystemBean implements Serializable{
private WorkSetup step;
public ArrayList <WorkSetup> steps=new ArrayList <WorkSetup> ();
private WorkSetup ws;
private String system="test1";
private String emailResp;
private String process;
private String name;
private String description;
private Integer sequence;
private String email2;
private String process2;
private String name2;
private String desc2;
private WorkSetup selectedStep;
public WorkStepSetupSystemBean(){
}
public String getDesc2() {
return desc2;
}
public String getEmail2() {
return email2;
}
public String getName2() {
return name2;
}
public String getProcess2() {
return process2;
}
public WorkSetup getSelectedStep() {
return selectedStep;
}
public ArrayList<WorkSetup> getSteps() {
return steps;
}
public WorkSetup getStep() {
return step;
}
public void setSteps(ActionEvent event) {
step= new WorkSetup();
step.setName(name);
step.setEmailResp(emailResp);
step.setDescription(description);
step.setSystem(system);
step.setProcess(process);
step.setSequence(steps.size()+1);
steps.add(step);
return;
}
public void setStep(ArrayList<WorkSetup> steps) {
this.steps = steps;
}
public Integer getSequence() {
return sequence;
}
public String getDescription() {
return description;
}
public String getEmailResp() {
return emailResp;
}
public String getName() {
return name;
}
public String getProcess() {
return process;
}
public String getSystem() {
return system;
}
public void setDescription(String description) {
this.description = description;
}
public void setEmailResp(String emailResp) {
this.emailResp = emailResp;
}
public void setName(String name) {
this.name = name;
}
public void setProcess(String process) {
this.process = process;
}
public void setSequence(Integer sequence) {
this.sequence = sequence;
}
public void setSystem(String system) {
this.system = system;
}
public void setDesc2(String desc2) {
this.desc2 = desc2;
}
public void setEmail2(String email2) {
this.email2 = email2;
}
public void setName2(String name2) {
this.name2 = name2;
}
public void setProcess2(String process2) {
this.process2 = process2;
}
public void setSelectedStep(WorkSetup selectedStep) {
this.selectedStep = selectedStep;
}
public void removeStep(ActionEvent event) {
steps.remove(steps.indexOf(this.selectedStep));
for(int i=0;i<steps.size();i++){
steps.get(i).setSequence(i+1);
}
}
public void updateStep(ActionEvent event) {
step=steps.get(steps.indexOf(this.selectedStep));
step.setName(name2);
step.setEmailResp(email2);
step.setDescription(desc2);
step.setSystem(system);
}
}
Ended up using
<p:inplace id="inplaceName" >
<p:inputText id="name2" value="#{setup.selectedStep.name}" />
<p:tooltip for="inplaceName" value="Click here to edit"/>
</p:inplace>
without the AJAX option

Resources