Save button of dialog is not firing bean method - jsf

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!

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.

Displaying Error Message after selecting multiple check box for edit

I am displaying error message after selecting more than one check box. As i click on edit button when i selecting more than one check box i am getting popup. Instead of popup i need to show error message.
this is my jsf page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="myForm">
<div id="page" class="box">
<div class="msg">
<h2>View Outbound Home Page</h2>
<hr />
<p:dialog header="Set Status:" widgetVar="assign" modal="true">
<h:panelGrid columns="2" style="width:400px; height:50px">
<p:outputLabel value="Status" />
<h:selectOneMenu id="status" value="#{leadEditBean.status}">
<f:selectItem itemLabel="--Select one Value--" />
<f:selectItems value="#{leadEditBean.typeOfStatus}" />
</h:selectOneMenu>
</h:panelGrid>
<h:commandButton value="Update"
actionListener="#{leadEditBean.changeStatus()}" />
</p:dialog>
<p:dialog header="Set Reminder Date and Time" widgetVar="setTime"
id="dialog1" resizable="true">
<h:panelGrid columns="2" cellpadding="10" cellspacing="10">
<h:outputText value="set remind time"></h:outputText>
<p:calendar showOn="button" pattern="yyyy-MM-dd hh:mm:ss"
value="#{leadEditBean.date}"></p:calendar>
<h:commandButton value="Set"
action="#{leadEditBean.setRemainderCall()}"></h:commandButton>
</h:panelGrid>
</p:dialog>
</div>
<p:messages for="outbondhome" style="text-align:center"
closable="true"></p:messages>
<div class="callbutton">
<h:panelGrid columns="4">
<p:commandButton id="statusbtn" value="Change Status"
class="button" onclick="PF('assign').show();" ajax="true"
update=":myForm:tbl" disabled="#{leadEditBean.disabled}" />
<p:commandButton id="settime" value="Set Remind Time"
class="button" onclick="PF('setTime').show();" ajax="true"
update=":myForm:tbl" disabled="#{leadEditBean.disabled}"></p:commandButton>
<h:commandButton value="Yesterday Calls"
action="#{leadEditBean.yesterdayCall}" class="button"
immediate="true" />
<h:commandButton value="Remainder Calls"
action="#{leadEditBean.reminderCallsByTime()}" class="button"
immediate="true" />
</h:panelGrid>
</div>
<br></br> <br></br>
<p:dataTable id="tbl" var="lead" value="#{leadEditBean.enquiryTOs}"
widgetVar="filteredlead" rowsPerPageTemplate="25,50,75,100,10000"
filteredValue="#{leadEditBean.filterednewLeadList}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="25" paginator="true" rowKey="#{lead.leadId}"
rowIndexVar="rowIndex" selection="#{leadEditBean.leadrTos}"
style="width:100%;">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search " style="margin-left:840px;" />
<p:inputText id="globalFilter"
onkeyup="PF('filteredlead').filter()" style="width:150px"
placeholder="Enter Phone Number" maxlength="10" />
</p:outputPanel>
</f:facet>
<p:ajax event="rowSelectCheckbox"
listener="#{leadEditBean.onRowSelect}"
update=":myForm:settime :myForm:statusbtn " />
<p:ajax event="rowUnselectCheckbox"
listener="#{leadEditBean.onRowUnselect}"
update=":myForm:settime :myForm:statusbtn " />
<p:column headerText="" style="width:30px;" selectionMode="multiple">
</p:column>
<p:column headerText="Lead Id" style="width:120px;">
<h:outputText value="#{lead.leadId}" />
</p:column>
<p:column headerText="Lead Name">
<h:outputText value="#{lead.firstName}" />
</p:column>
<p:column headerText="Email">
<h:outputText value="#{lead.emailId}" />
</p:column>
<p:column headerText="Phone No" filterMatchMode="contains"
filterBy="#{lead.phoneNum}">
<h:outputText value="#{lead.phoneNum}" />
</p:column>
<p:column headerText="PinCode">
<h:outputText value="#{lead.area.pincode}" />
</p:column>
<p:column rendered="#{leadEditBean.hideColumn}">
<f:facet name="header">
<h:outputText value="Remainder Date" />
</f:facet>
#{lead.time}
</p:column>
<p:column headerText="Edit" style="width:40px;">
<p:commandButton icon="ui-icon ui-icon-pencil"
actionListener="#{leadEditBean.getLeadEnquiryEntityForEdit(lead)}"
oncomplete="PF('edit').show()" ajax="true"
update=":myForm:dialog2" />
</p:column>
</p:dataTable>
</div>
<p:dialog header="Update Lead" widgetVar="edit" id="dialog2"
resizable="true" modal="true">
<p:messages for="home"></p:messages>
<h:panelGrid columns="4" cellpadding="10" cellspacing="4">
<h:outputText value="LeadId" />
<h:outputText value="#{leadEditBean.leadList.leadId}" />
<h:outputText />
<h:outputText />
<h:outputText value="First Name" />
<h:inputText class="input"
value="#{leadEditBean.leadList.firstName}"></h:inputText>
<h:outputText value="Email" />
<h:inputText class="input" value="#{leadEditBean.leadList.emailId}"></h:inputText>
<h:outputText value="Mobile number" />
<h:inputText class="input" value="#{leadEditBean.leadList.phoneNum}"></h:inputText>
<h:outputText value="Pincode" />
<h:selectOneMenu class="input" value="#{leadEditBean.pincode}">
<f:selectItem itemValue="#{leadEditBean.pincode}" />
<f:selectItems value="#{applicationController.typeOfPincode}"></f:selectItems>
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid>
<p:commandButton id="enquiry" value="Send to Enquiry"
update=":myForm:tbl" onclick="PF('send').show();"
style="margin-left:250px" ajax="true"></p:commandButton>
</h:panelGrid>
<h:commandButton value="Update" ajax="true" update=":myForm:dialog" style="margin-left:265px"
actionListener="#{leadEditBean.updateLeadEnquiryEntity}" />
<h:commandButton value="Cancel" action="#{leadEditBean.cancel}" />
</p:dialog>
<div id="footer">
<p>copy right</p>
</div>
</h:form>
</h:body>
</html>
this is my bean
package com.model.acim.common.controller;
#Component
#ManagedBean
#RequestScoped
public class LeadEditBean extends BaseBean<T> {
#Autowired
#Qualifier("baseServiceImpl")
private BaseService<T> baseService;
private int leadID;
private String firstName;
private String lastName;
private String phoneNumber;
private String emailId;
private String address;
private String area;
private String city;
private String pincode;
private List<LeadEnquiryTO> enquiryTOs;
private AreaTO areaTO = new AreaTO();
private StateTO stateTO;
private CityTO cityTO;
private LeadEnquiryTO enquiryTO = new LeadEnquiryTO();
private LeadEnquiryTO leadList=new LeadEnquiryTO();
private LeadEnquiryTO LeadEnquiryTOUpdate=new LeadEnquiryTO();
private List<LeadEnquiryTO> newLeadList;
private List<LeadEnquiryTO> filterednewLeadList;
private List<LeadEnquiryTO> leadrTos;
List<LeadEnquiryTO> allLeads;
private Timestamp setTime;
private String branch;
private Date date;
private String status;
private List<LeadEnquiryTO> leadEnquiryToListAd = null;
HttpSession session = null;
int noOfSelctions=0;
private Boolean disabled = true;
private Boolean hideColumn = false;
private List<LeadEnquiryTO> leadEnquiryToList = null;
int emp_id;
int selectionForEdit=0;
public int getNoOfSelctions() {
return noOfSelctions;
}
public void setNoOfSelctions(int noOfSelctions) {
this.noOfSelctions = noOfSelctions;
}
public List<LeadEnquiryTO> getLeadEnquiryToList() {
return leadEnquiryToList;
}
public void setLeadEnquiryToList(List<LeadEnquiryTO> leadEnquiryToList) {
this.leadEnquiryToList = leadEnquiryToList;
}
public void getLeadEnquiryEntityForEdit(LeadEnquiryTO to){
int size = leadrTos.size();
if(size<=1){
this.setLeadID(to.getLeadId());
leadList = baseService.getLeadEnquiryEntityForEdit(to.getLeadId());
this.setLeadID(leadList.getLeadId());
this.setFirstName(leadList.getFirstName());
this.setLastName(leadList.getLastName());
this.setPhoneNumber(leadList.getPhoneNum());
this.setEmailId(leadList.getEmailId());
this.setAddress(leadList.getAddress());
String areaName = leadList.getArea().getAreaName();
this.setArea(areaName);
this.setPincode(leadList.getArea().getPincode());
this.setCity(leadList.getArea().getCity().getCityName());
}
else
{
FacesContext.getCurrentInstance().addMessage(
"home",
new FacesMessage("Please select only One Value or One Row"));
}
}
public void onRowSelect(SelectEvent event)
{
noOfSelctions = noOfSelctions+1;
#SuppressWarnings("unused")
LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
disabled=false;
}
public void onRowUnselect(UnselectEvent event)
{
noOfSelctions=noOfSelctions-1;
#SuppressWarnings("unused")
LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
if (noOfSelctions<=0) {
disabled=true;
} else {
disabled=false;
}
}
public void updateLeadEnquiryEntity(){
LeadEnquiryTOUpdate.setLeadId(leadList.getLeadId());
LeadEnquiryTOUpdate.setFirstName(leadList.getFirstName());
LeadEnquiryTOUpdate.setLastName(leadList.getLastName());
LeadEnquiryTOUpdate.setPhoneNum(leadList.getPhoneNum());
LeadEnquiryTOUpdate.setAddress(leadList.getAddress());
LeadEnquiryTOUpdate.setEmailId(leadList.getEmailId());
areaTO= getAreaTOByid();
LeadEnquiryTOUpdate.setArea(areaTO);
int result = baseService.updateLeadEnquiryEntity(LeadEnquiryTOUpdate);
if (result>0) {
FacesContext.getCurrentInstance().addMessage(
"leadhome",
new FacesMessage("Updated Successfully"));
} else {
FacesContext.getCurrentInstance().addMessage(
"leadhome",
new FacesMessage("Not Updated Successfully"));
}
enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
}
public void getLeadEnquiryByEmployeeId(){
session = (HttpSession) FacesContext
.getCurrentInstance().getExternalContext()
.getSession(false);
emp_id = (Integer) session.getAttribute("employeeId");
enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
}
//setters getter
}
You should consider to change your checkboxes to radio buttons. In principle this is the right metaphor for a single selection [Checkbox or radio button].
<p:column ... selectionMode="single">

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;
}
}

p:dataTable filtering doesn't work with template

I'm trying to create a filtering datatable with PrimeFaces framework.
My issue is that the datatable is displayed but filtering option doesn't work , help please !!
My page.xhtml looks like :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition>
<h5>
<h:form>
<p:dataTable var="student" value="#{studentWizard.students}" widgetVar="studentTable" emptyMessage="Aucun élève trouvé" id="tableStudent" filteredValue="#{studentWizard.filteredStudents}" >
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Chercher tous les champs:" />
<p:inputText id="globalFilter" onkeyup="studentTable.filter()" style="width:150px" placeholder="Entrer le mot-clé"/>
</p:outputPanel>
</f:facet>
<p:column filterBy="#{student.studentCode}" headerText="Code de l'élève" filterMatchMode="contains">
<h:outputText value="#{student.studentCode}"/>
</p:column>
<p:column filterBy="#{student.firstName}" headerText="Prénom" filterMatchMode="contains">
<h:outputText value="#{student.firstName}"/>
</p:column>
<p:column filterBy="#{student.lastName}" headerText="Nom" filterMatchMode="contains">
<h:outputText value="#{student.lastName}"/>
</p:column>
<p:column headerText="Modifier" >
<p:commandButton value="Modifier" type="submit" ajax="false" icon="ui-icon-update"/>
</p:column>
</p:dataTable>
</h:form>
</h5>
</ui:composition>
</html>
and My Java Bean :
#ManagedBean(name="studentWizard")
#Component
#ViewScoped
public class StudentWizard implements Serializable {
public StudentWizard() {}
private static final long serialVersionUID = 1L;
private Student student;
private List<Student> students;
private List<Student> filteredStudents;
#PostConstruct
public void init() {
students = getAllStudent();
}
public List<Student> getFilteredStudents() {
return filteredStudents;
}
public void setFilteredStudents(List<Student> filteredStudents) {
this.filteredStudents = filteredStudents;
}
#Autowired
private StudentManager studentManager;
public void setStudentManager(StudentManager studentManager) {
this.studentManager = studentManager;
}
public Student getstudent() {
return student;
}
public StudentManager getStudentManager() {
return studentManager;
}
public void setstudent(Student student) {
this.student = student;
}
public void save() {
studentManager.saveStudent(student);
student = new Student();
}
public List<Student> getAllStudent() {
return studentManager.getAllStudent();
}
public Student getStudentById(int id) {
return studentManager.getStudentById(id);
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
}
This is my home web page
<h:body>
<p:layout style="min-width:400px;min-height:100px;">
<p:layoutUnit position="center" size="400" >
</p:layoutUnit>
</p:layout>
<p:layout style="min-width:400px;min-height:500px;">
<p:layoutUnit position="west" size="244" >
<h5>
<h:form>
<p:menu toggleable="true">
<p:submenu label="Eleves">
<p:menuitem value="Nouvel élève" action="#{menuView.setSelectedItem(1)}" update=":globalPanel" />
<p:menuitem value="Consultation" action="#{menuView.setSelectedItem(2)}" update=":globalPanel" />
</p:submenu>
<p:submenu label="Personnels">
</p:submenu>
<p:submenu label="Notes">
</p:submenu>
<p:submenu label="Caisses">
</p:submenu>
<p:submenu label="Salaires">
</p:submenu>
<p:submenu label="Référentiel">
</p:submenu>
</p:menu>
</h:form>
</h5>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:panelGroup id ="globalPanel" >
<h:panelGroup id="inscriptionPanel" rendered="#{menuView.selectedItem == 1}" header="Inscription" style="margin-bottom:20px">
<ui:include src="/inscription.xhtml" />
</h:panelGroup>
<h:panelGroup id="testerPanel" rendered="#{menuView.selectedItem == 2}" header="Consultation" style="margin-bottom:20px" >
<ui:include src="/consul.xhtml" />
</h:panelGroup>
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>

selected value in p:selectOneMenu was lost

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();
}
}

Resources