I would like to create a registration form with two PrimeFaces components: Wizard and Progress Bar. For the backing bean, I am using the following one:
Backing bean: UserWizard.xhtml
import java.io.Serializable;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.context.RequestContext;
import org.primefaces.event.FlowEvent;
#ViewScoped
#Named
public class UserWizard implements Serializable {
private User user = new User();
private boolean skip;
private Integer progress = 0;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void save() {
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public boolean isSkip() {
return skip;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
public String onFlowProcess(FlowEvent event) {
String oldStep = event.getOldStep();
Integer oldValue = getStepNumber(oldStep);
String newStep = event.getNewStep();
Integer newValue = getStepNumber(newStep);
if(oldValue < newValue)
progress += 25;
else
progress += 25;
return event.getNewStep();
}
public Integer getStepNumber(String Step) {
Integer StepNumber;
switch(Step) {
case "personal":
StepNumber = 1;
break;
case "address":
StepNumber = 2;
break;
case "contact":
StepNumber = 3;
break;
default:
StepNumber = 4;
break;
}
return StepNumber;
}
public Integer getProgress() {
return progress;
}
public void setProgress(Integer progress) {
this.progress = progress;
}
public void onComplete() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Progress Completed"));
}
public void cancel() {
progress = null;
}
}
Registration Form: registration.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<body>
<f:view contracts="#{view.locale.language}">
<ui:composition template="/template.xhtml">
<ui:define name="centralBody">
<h:form>
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard flowListener="#{userWizard.onFlowProcess}">
<p:tab id="personal" title="Personal">
<p:panel header="Personal Details">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Firstname: *" />
<p:inputText value="#{userWizard.user.firstname}" required="true" label="Firstname"/>
<h:outputText value="Lastname: *" />
<p:inputText value="#{userWizard.user.lastname}" required="true" label="Lastname"/>
<h:outputText value="Age: " />
<p:inputText value="#{userWizard.user.age}" />
<h:outputText value="Skip to last: " />
<h:selectBooleanCheckbox value="#{userWizard.skip}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="address" title="Address">
<p:panel header="Address Details">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Street: " />
<p:inputText value="#{userWizard.user.street}" />
<h:outputText value="Postal Code: " />
<p:inputText value="#{userWizard.user.postalCode}" />
<h:outputText value="City: " />
<p:inputText value="#{userWizard.user.city}" />
<h:outputText value="Skip to last: " />
<h:selectBooleanCheckbox value="#{userWizard.skip}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="contact" title="Contact">
<p:panel header="Contact Information">
<p:messages />
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Email: *" />
<p:inputText value="#{userWizard.user.email}" required="true" label="Email"/>
<h:outputText value="Phone: " />
<p:inputText value="#{userWizard.user.phone}"/>
<h:outputText value="Additional Info: " />
<p:inputText value="#{userWizard.user.info}"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation">
<p:panel header="Confirmation">
<h:panelGrid id="confirmation" columns="3" columnClasses="grid,grid,grid">
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Firstname: " />
<h:outputText value="#{userWizard.user.firstname}" styleClass="outputLabel"/>
<h:outputText value="Lastname: " />
<h:outputText value="#{userWizard.user.lastname}" styleClass="outputLabel"/>
<h:outputText value="Age: " />
<h:outputText value="#{userWizard.user.age}" styleClass="outputLabel"/>
</h:panelGrid>
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Street: " />
<h:outputText value="#{userWizard.user.street}" styleClass="outputLabel"/>
<h:outputText value="Postal: " />
<h:outputText value="#{userWizard.user.postalCode}" styleClass="outputLabel"/>
<h:outputText value="City: " />
<h:outputText value="#{userWizard.user.city}" styleClass="outputLabel"/>
</h:panelGrid>
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Email: " />
<h:outputText value="#{userWizard.user.email}" styleClass="outputLabel"/>
<h:outputText value="Phone " />
<h:outputText value="#{userWizard.user.phone}" styleClass="outputLabel"/>
<h:outputText value="Info: " />
<h:outputText value="#{userWizard.user.info}" styleClass="outputLabel"/>
<h:outputText />
<h:outputText />
</h:panelGrid>
</h:panelGrid>
<p:commandButton value="Submit" actionListener="#{userWizard.save}" update="growl" process="#this"/>
</p:panel>
</p:tab>
</p:wizard>
<p:progressBar id="progressBar" widgetVar="pbAjax" ajax="true" value="#{UserWizard.progress}" labelTemplate="{value}%" styleClass="animated" global="false">
<p:ajax event="complete" listener="#{UserWizard.onComplete}" update="growl" oncomplete="PF('startButton2').enable()"/>
</p:progressBar>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
My purpose is that, when the registration flow goes through the different registration tabs (Personal, Address, Contact and Confirmation), the progress bar in the lower part of the screen to be updated according to the next or back buttons. In order to achieve this, I want to use the method
public String onFlowProcess(FlowEvent event) {
String oldStep = event.getOldStep();
Integer oldValue = getStepNumber(oldStep);
String newStep = event.getNewStep();
Integer newValue = getStepNumber(newStep);
if(oldValue < newValue)
progress += 25;
else
progress -= 25;
return event.getNewStep();
}
public Integer getStepNumber(String Step) {
Integer StepNumber;
switch(Step) {
case "personal":
StepNumber = 1;
break;
case "address":
StepNumber = 2;
break;
case "contact":
StepNumber = 3;
break;
default:
StepNumber = 4;
break;
}
return StepNumber;
}
But I do not know how to update the progress bar. I have tried:
changing the value of progress bar value (variable progress) in the
function onFlowProcess. It does not work.
<p:wizard ... update="progress_bar">. I have realized that the attribute update is not allowed for the Wizard component.
<p:ajax listener="#{UserWizard.onFlowProcess}" update="#this"> within the <p:progressBar> element.
Since the wizard (at least in/upto PrimeFaces 6.0) does not seem to support the update attribute when using a flowListener and no explicit ajax events are supported, the only option I see is to use the PrimeFaces RequestContext to update the other component. Keep in mind that you need to use the 'full absolute path' to the element, so including all the id's of the namingcontainers it is in. It is best then to explicitly assign id's to all namingcontainers (including a form!)
So using
RequestContext.getCurrentInstance().update("formId:progress_bar");
like e.g.
public String onFlowProcess(FlowEvent event) {
String oldStep = event.getOldStep();
Integer oldValue = getStepNumber(oldStep);
String newStep = event.getNewStep();
Integer newValue = getStepNumber(newStep);
if(oldValue < newValue)
progress += 25;
else
progress -= 25;
RequestContext.getCurrentInstance().update("formId:progress_bar");
return event.getNewStep();
}
in the flowListener should work. Keep in mind that in the updates from beans, the ':' as a prefix for absolute paths is not needed, they are assumed to be always absolute
Related
I have mainpage.xhtml which displays entire records in my database and allows me to edit them. In case of clicling Edit button it calls mainPageController.edit() function which fills _bilgi variable in MainPageConroller class then it redirects to edit.xhtml page.
In edit.xhtml page it basically displays the values of _bilgi that are filled before in MainPageController class. There's no problem till here(probably there is but I am not aware of it.)
When I want to update one of those variables such as baslik I created a method in MainPageController which calls updateBilgi(_bilgi) in bilgiDAO class.
In UpdateBilgi it is pretty clear what it does yet it is not updating the table. It is interesting for me that when I debug and follow the variables, everything goes well but in the end it just does not update.
Another thing is when I put just a string in BilgilerDAO such is ps.setString(1, "aqa1") it works but ps.setString(2, bilgi.getBaslik()) does not eventho bilgi.getBaslik() returns the changed value.
What could be wrong?
Thank you for the answers in advance.
I hope I am clear enough.
Edit: I found the glitch. in BilgilerDAO the function updateBilgi(Bilgi bilgi)
the variable bilgi doesn't get the id from _bilgi but gets other variables. Why it wouldn't get the id?
mainpage.xhtml
<h:form id="bilgiForm">
<h:dataTable id="bilgiTable" value="#{mainPageController.bilgiListesi}"
var="bilgiler" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Başlık" />
</f:facet>
<h:outputText value="#{bilgiler.baslik}" />
<f:facet name="footer">
<h:outputText value="Başlık" />
</f:facet>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Bilgi Metni" />
</f:facet>
<h:outputText value="#{bilgiler.bilgi}" />
<f:facet name="footer">
<h:outputText value="Bilgi Metni" />
</f:facet>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Bilgi Metni" />
</f:facet>
<h:outputText value="#{bilgiler.bilgi}" />
<f:facet name="footer">
<h:outputText value="Bilgi Metni" />
</f:facet>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Bilgi Metni" />
</f:facet>
<h:graphicImage
value="https://canakkale.000webhostapp.com/showImage.php/?name=#{bilgiler.img.name}" />
<f:facet name="footer">
<h:outputText value="Bilgi Metni" />
</f:facet>
</h:column>
<h:column>
<fcore:facet name="header">Edit</fcore:facet>
<h:commandButton action="edit" value="Edit"
actionListener="#{mainPageController.edit()}">
<fcore:param name="id" value="#{bilgiler.id}" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
<fcore:view>
<h:form>
<fcore:view>
<h:form>
<h1>Update</h1>
<h:panelGrid border="" cellpadding="20" cellspacing="20"
columns="3">
<h:outputLabel value="Bilgi ID" />
<h:inputText value="#{mainPageController._bilgi.id}"
readonly="true" required="true" requiredMessage="Id is Required"
id="bilgiID">
</h:inputText>
<h:message for="bilgiID" />
<h:outputLabel value="Tag" />
<h:inputText value="#{mainPageController._bilgi.tag}"
readonly="true" required="true"
requiredMessage="Tag Girmeniz Gereklidir." id="bilgiTag">
</h:inputText>
<h:message for="bilgiTag" />
<h:outputLabel value="Başlık" />
<h:inputText value="#{mainPageController._bilgi.baslik}"
required="true" requiredMessage="Başlık Girmeniz Gereklidir."
id="bilgiBaslik">
</h:inputText>
<h:message for="bilgiBaslik" />
<h:outputLabel value="Bilgi Metni" />
<h:inputTextarea value="#{mainPageController._bilgi.bilgi}"
required="true" requiredMessage="Başlık Girmeniz Gereklidir."
id="bilgiBilgi">
</h:inputTextarea>
<h:message for="bilgiBilgi" />
<h:outputLabel value="Image URL" />
<h:inputText value="#{mainPageController._bilgi.img.name}"
required="true" requiredMessage="Başlık Girmeniz Gereklidir."
readonly="true" id="bilgiImgName">
</h:inputText>
<h:message for="bilgiImgName" />
<h:outputLabel value="Başlık" />
<input type="file" value="#{mainPageController._bilgi.img.image}" />
<h:commandButton action="#{mainPageController.updateRecord()}"
value="Update">
</h:commandButton>
</h:panelGrid>
</h:form>
</fcore:view>
</h:form>
</fcore:view>
</h:body>
</html>
MainPageController Class
#ManagedBean
public class MainPageController implements Serializable {
List<Bilgi> bilgiListesi = new ArrayList<Bilgi>();
private Bilgi _bilgi = new Bilgi();
private static final long serialVersionUID = 1L;
BilgilerDAO bilgiDao = new BilgilerDAO();
ImageDAO imgDao = new ImageDAO();
public MainPageController() {// Default Constructor
try {
bilgiListesi = showAllRecords();
} catch (SQLException e) {
e.printStackTrace();
}
}
public List<Bilgi> showAllRecords() throws SQLException {
return bilgiDao.getAllBilgiler();
}
public List<Image> showAllImages() throws Exception {
return imgDao.getAllImages();
}
public void updateRecord() {
try {
bilgiDao.updateBilgi(_bilgi);
//imgDao.updateImage(_bilgi.getImg());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void edit() {
FacesContext fc = FacesContext.getCurrentInstance();
int id;
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
id = Integer.parseInt(request.getParameter("id"));
try {
bilgiListesi = bilgiDao.getAllBilgiler();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Bilgi bilgi : bilgiListesi) {
if (bilgi.getId() == id) {
_bilgi.setBaslik(bilgi.getBaslik());
_bilgi.setBilgi(bilgi.getBilgi());
_bilgi.setImg(bilgi.getImg());
_bilgi.setTag(bilgi.getTag());
_bilgi.setId(bilgi.getId());
}
}
}
public void edit(Bilgi bilgi) {
for (Bilgi existing : getBilgiListesi()) {
existing.setEditable(false);
}
bilgi.setEditable(true);
}
}
BilgilerDAO
#Override
public String updateBilgi(Bilgi bilgi) throws Exception {
String sql = "UPDATE bilgiler SET bilgi=?, baslik =? WHERE id=? ";
ps = DatabaseConnection.getConnection().prepareStatement(sql);
ps.setString(1, "aqa1");
ps.setString(2, bilgi.getBaslik());
ps.setInt(3, bilgi.getId());
int ex = ps.executeUpdate();
if (ex > 0) {
System.err.println("coodld");
}
ps.close();
return "mainpage";
}
I kind of solved the issue.
<h:inputText value="#{mainPageController._bilgi.id}" readonly="true" required="true" requiredMessage="Id is Required" id="bilgiID">
in this xhtml line readonly="true" caused it return null. I removed it now it works how I wanted. Though, I still want them to be displayed but not editable.
I am using Primefaces 3.5 with Weblogic 11. I have a page where a dialog to edit a 'profile' entity ('perfil' in Portuguese) which is called from two places. First from a commandButton to insert a new profile. The second from a dataTable to edit a specific profile. Below, I show the code:
Snippet of XHTML page
<p:fieldset legend="Pesquisa de Perfil">
<p:panelGrid columns="2">
<f:facet name="footer">
<p:commandButton id="btnPesquisar"
actionListener="#{perfilAcessoMB.pesquisar}" value="Pesquisar"
immediate="true" update="pnlPerfis" styleClass="ui-icon-search" />
<p:spacer width="20"></p:spacer>
<!-- OPEN DIALOG TO CREATE A NEW PROFILE -->
<p:commandButton id="btnIncluir" value="Incluir"
update="dlgPerfil" immediate="true"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(null)}"
oncomplete="dlgPerfil.show();">
</p:commandButton>
</f:facet>
</p:panelGrid>
</p:fieldset>
<br />
<p:outputPanel id="pnlPerfis" layout="block">
<p:fieldset id="resultadoPesquisa" legend="Resultado da Pesquisa"
rendered="#{not empty perfilAcessoMB.perfis}">
<p:dataTable id="tblPerfis" value="#{perfilAcessoMB.perfis}"
var="perfil" emptyMessage="Nenhum perfil encontrado.">
<p:column headerText="Nome do Perfil">
<h:outputText value="#{perfil.nome}"></h:outputText>
</p:column>
<p:column headerText="Descrição do Perfil">
<h:outputText value="#{perfil.descricao}"></h:outputText>
</p:column>
<p:column headerText="Situação do Perfil"
style="text-align: center; width: 100px;">
<h:outputText value="Ativo" rendered="#{perfil.situacao}" />
<h:outputText value="Inativo" rendered="#{not perfil.situacao}" />
</p:column>
<p:column headerText="Editar"
style="text-align: center; width: 50px;">
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="Editar Perfil" update=":formPrincipal:dlgPerfil :formPrincipal:pnlPerfilEdicao"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(perfil)}"
oncomplete="dlgPerfil.show();">
<h:outputText value="Editar" />
</p:commandLink>
</p:column>
<p:column headerText="Excluir"
style="text-align: center; width: 50px;">
</p:column>
</p:dataTable>
</p:fieldset>
</p:outputPanel>
<p:dialog id="dlgPerfil" widgetVar="dlgPerfil" resizable="false"
closable="true" modal="true" closeOnEscape="true"
header="#{(empty perfilAcessoMB.perfil)? 'Incluir': 'Editar'} Perfil">
<h:outputText value="#{perfilAcessoMB.perfil}"></h:outputText>
<h:panelGroup id="pnlPerfilEdicao" layout="block">
<p:fieldset legend="Dados do Perfil">
<p:panelGrid columns="2">
<h:outputLabel id="lblNomePerfilEdicao" value="Nome do Perfil"
for="txtNomePerfilEdicao" />
<p:inputText id="txtNomePerfilEdicao" required="true"
requiredMessage="É obrigatório preencher o campo Nome do Perfil."
value="#{perfilAcessoMB.perfil.nome}" maxlength="20" size="20"></p:inputText>
<h:outputLabel id="lblDescricaoPerfilEdicao"
value="Descrição do Perfil" for="txtDescricaoPerfilEdicao" />
<p:inputText id="txtDescricaoPerfilEdicao" required="true"
requiredMessage="É obrigatório preencher o campo Descrição do Perfil."
value="#{perfilAcessoMB.perfil.descricao}" maxlength="20"
size="20"></p:inputText>
<h:outputLabel id="lblSituacaoPerfilEdicao" value="Situação"
for="selSituacaoPerfilEdicao" />
<p:selectOneMenu id="selSituacaoPerfilEdicao"
value="#{perfilAcessoMB.perfil.situacao}">
<f:selectItems value="#{perfilAcessoMB.situacoesEdicao}" />
</p:selectOneMenu>
</p:panelGrid>
</p:fieldset>
<br />
<p:fieldset legend="Permissões">
<p:pickList id="pickFuncoes" value="#{perfilAcessoMB.funcoes}"
var="funcao" itemValue="#{funcao}"
itemLabel="#{funcao.descricao}" required="true"
requiredMessage="É obrigatório associar ao menos uma funcionalidade ao perfil."
converter="funcaoConverter" />
<p:column>#{funcao.descricao}</p:column>
</p:fieldset>
<p:panelGrid columns="2">
<p:commandButton id="btnSalvarPerfil" value="Salvar"
actionListener="#{perfilAcessoMB.salvar}"
oncomplete="if(args && !args.validationFailed) dlgPerfil.hide();" />
<p:commandButton id="btnCancelarPerfil" value="Cancelar"
immediate="true" onclick="dlgPerfil.hide();" />
</p:panelGrid>
</h:panelGroup>
</p:dialog>
MangedBean (perfilAcessoMB)
#ManagedBean
#ViewScoped
public class PerfilAcessoMB extends BaseMB {
private PerfilAcessoORM perfil;
private List<PerfilAcessoORM> perfis;
private String nomePerfil;
private Boolean situacao;
private DualListModel<FuncaoORM> funcoes;
private SelectItem[] situacoesPesquisa = new SelectItem[] {
new SelectItem(null, "Todos"), SELECT_ITEM_ATIVO,
SELECT_ITEM_INATIVO };
private SelectItem[] situacoesEdicao = new SelectItem[] {
SELECT_ITEM_ATIVO, SELECT_ITEM_INATIVO };
private FuncaoORM funcaoA = new FuncaoORM(1L, "FUNÇÃO A"), //
funcaoB = new FuncaoORM(2L, "B Function"), //
funcaoC = new FuncaoORM(10L, "Se Funssaum");
public void abrirDialogoEdicao(PerfilAcessoORM p) {
this.perfil = (p == null)? new PerfilAcessoORM(): p;
System.out.println("PerfilAcessoMB.onAbrirDialogoEdicao(): "
+ this.perfil);
List<FuncaoORM> funcoesDisponiveis = new ArrayList<FuncaoORM>(
Arrays.asList(funcaoA, funcaoB, funcaoC));
// Remove from funcoesDisponiveis those whose are present in perfil.
if (this.perfil.getFuncoes() == null) {
this.funcoes = new DualListModel<FuncaoORM>(funcoesDisponiveis,
Lists.<FuncaoORM> newArrayList());
} else {
funcoesDisponiveis.removeAll(this.perfil.getFuncoes());
this.funcoes = new DualListModel<FuncaoORM>(funcoesDisponiveis,
this.perfil.getFuncoes());
}
}
// Getters & Setters
}
PerfilAcessoORM (Profile) Entity
public class PerfilAcessoORM {
private Long id;
private String nome;
private String descricao;
private Boolean situacao = null;
private List<FuncaoORM> funcoes;
// Getters & Setters
}
FuncaoORM Entity:
public class FuncaoORM {
private Long id;
public String descricao;
// Getters & Setters
}
What is my problem? Apparently, when I want insert a new Profile, all seems OK. However, when I click to edit an existent profile to open the dialog, although the outputText and pickList are correctly filled, the inputText's and selectOneMenu are not.
Looking for solutions, I found here a suggestion to use appendToBody="true" in dialog. When I tried, the inputText's and selectOneMenu are correctly filled. However, the validation is not working as waited. When I click to save it is showed a message indicating that pickList is not filled, even if it is really filled. Actually, even if inputText's are not filled, there is no message about these inputTexts although they are required.
Another alternative would be use <f:setPropertyActionListener> inside commandLink:
<!-- OPEN DIALOG TO CREATE A NEW PROFILE -->
<p:commandButton id="btnIncluir" value="Incluir"
update="dlgPerfil" immediate="true"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao}"
oncomplete="dlgPerfil.show();">
<f:setPropertyActionListener target="#{perfilAcessoMB.perfil}" value="#{null}"/>
</p:commandButton>
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="Editar Perfil" update=":formPrincipal:dlgPerfil :formPrincipal:pnlPerfilEdicao"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao}"
oncomplete="dlgPerfil.show();">
<f:setPropertyActionListener target="#{perfilAcessoMB.perfil}" value="#{perfil}"/>
<h:outputText value="Editar" />
</p:commandLink>
The actionListener method would changed to:
public void abrirDialogoEdicao() {
if(this.perfil == null) {
this.perfil = new PerfilAcessoORM();
}
System.out.println("PerfilAcessoMB.onAbrirDialogoEdicao(): "
+ this.perfil);
// The rest remains the same ...
}
Now, when I click to create a new perfil, although in actionListener method the perfil attribute is filled, I got a NullPointerException when the dialog is renderized. It is like first is called perfilAcessoMB.setPerfil(), after the dialog is opened and finally actionListener method. On the other hand, if I click to edit an existent profile, I return to initial situation.
Therefore, I am lost, without idea how to solve this issue.
Thanks,
Rafael Afonso
The solution was incredible simple: just added process="#this" to both commandButtons.
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="#{msg['titulo.edicao']}" process="#this"
update=":formPrincipal:dlgPerfil"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(perfil)}"
oncomplete="dlgPerfil.show();">
<h:outputText value="#{msg['titulo.edicao']}" />
</p:commandLink>
I use POI & Itext jar to export Data to PDF or Excel file, I would like to generate a report that contain the data from datatable, but here is what I got as result
http://hpics.li/3653d83
As you see, fields contain variable not the data from datatable.
I would like that file containe data like id, name, email... Please any suggestion
This is my FormateurController.java
package com.controller;
import com.dao.FormateurDao;
import com.dao.InterfaceFormateur;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.model.Formateur;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.servlet.ServletContext;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
/**
*
* #author Ucf
*/
#ManagedBean
#SessionScoped
public class FormateurController {
private Formateur formateur;
private DataModel listFormateurs;
private Formateur selectedFormateur;
private Formateur[] selectedFormateurs;
private List<Formateur> filteredFormateurs;
public Formateur getFormateurs() {
if(this.formateur == null){
this.formateur = new Formateur();
}
return formateur;
}
public void setFormateurs(Formateur formateur) {
this.formateur = formateur;
}
public DataModel getListFormateurs() {
List<Formateur> lista = new FormateurDao().list();
listFormateurs = new ListDataModel(lista);
return listFormateurs;
}
public void preparerajouterFormateur(ActionEvent actionEvent){
formateur = new Formateur();
}
public void preparermodifierFormateur(ActionEvent actionEvent){
formateur = (Formateur)(listFormateurs.getRowData());
}
public void ajouter(ActionEvent actionEvent){
InterfaceFormateur dao = new FormateurDao();
dao.enregistrer(formateur);
}
public void modifier(ActionEvent actionEvent){
InterfaceFormateur dao = new FormateurDao();
dao.actualiser(formateur);
}
public String exclure(){
Formateur employers = (Formateur)(listFormateurs.getRowData());
InterfaceFormateur dao = new FormateurDao();
dao.supprimer(employers);
return "index";
}
public Formateur getSelectedFormateur() {
return selectedFormateur;
}
public void setSelectedFormateur(Formateur selectedFormateur) {
this.selectedFormateur = selectedFormateur;
}
public List<Formateur> getFilteredFormateurs() {
return filteredFormateurs;
}
public void setFilteredFormateurs(List<Formateur> filteredFormateurs) {
this.filteredFormateurs = filteredFormateurs;
}
public Formateur[] getSelectedFormateurs() {
return selectedFormateurs;
}
public void setSelectedFormateurs(Formateur[] selectedFormateurs) {
this.selectedFormateurs = selectedFormateurs;
}
public void postProcessXLS(Object document) {
HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow header = sheet.getRow(0);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
for(int i=0; i < header.getPhysicalNumberOfCells();i++) {
HSSFCell cell = header.getCell(i);
cell.setCellStyle(cellStyle);
}
}
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
Document pdf = (Document) document;
pdf.open();
pdf.setPageSize(PageSize.A4);
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "ACTUS-0-740-econocom-logo.gif";
pdf.add(Image.getInstance(logo));
}
public String redirectFormateur(){
return "ModifierFournisseur.xhtml";
}
}
this is my index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Gestion de réservation pour une formation</title>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="150">
<center> <h1>Gestion de réservation pour une formation</h1></center>
</p:layoutUnit>
<p:layoutUnit position="west" size="200" rendered="true" collapsible="true" resizable="true" closable="true" header="menu">
<h:form>
<p:commandLink value="Nouveau formateur" actionListener="#{formateurController.preparerajouterFormateur(actionEvent)}" onclick="dlgFormateur.show();" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="form">
<p:dialog widgetVar="dlgFormateur" resizable="false" height="400" width="450" header="Ajout formateur" position="center">
<p:panelGrid columns="2">
<h:outputText value="nom"/>
<p:inputText id="adresse2" value="#{formateurController.formateurs.adresse}"/>
<h:outputText value="cin"/>
<p:inputText id="cin2" value="#{formateurController.formateurs.cin}"/>
<h:outputText value="email"/>
<p:inputText id="email2" value="#{formateurController.formateurs.email}"/>
<h:outputText value="nom"/>
<p:inputText id="nom2" value="#{formateurController.formateurs.nom}"/>
<h:outputText value="prenom"/>
<p:inputText id="prenom2" value="#{formateurController.formateurs.prenom}"/>
<h:outputText value="pseudo"/>
<p:inputText id="pseudo2" value="#{formateurController.formateurs.pseudo}"/>
<h:outputText value="sexe"/>
<p:inputText id="sexe2" value="#{formateurController.formateurs.sexe}"/>
<h:outputText value="telephone"/>
<p:inputText id="telephone2" value="#{formateurController.formateurs.telephone}"/>
<p:commandButton value="enregistrer" id="eng" actionListener="#{formateurController.ajouter(actionEvent)}" update="dataformateur" oncomplete="dlgFormateur.hide()"/>
</p:panelGrid>
</p:dialog>
<p:dataTable id="dataformateur" value="#{formateurController.listFormateurs}" var="formateur" rowKey="#{formateur.formateurId}" paginator="true" rows="10" selection="#{formateurController.selectedFormateurs}" selectionMode="multiple" filteredValue="#{formateurController.filteredFormateurs}" rowsPerPageTemplate="5,10,20,30">
<p:ajax event="rowSelect" update=":form:display" oncomplete="formateurDialog.show()" />
<f:facet name="header">
List of Formateurs
</f:facet>
<p:column headerText="Id" sortBy="#{formateur.formateurId}" filterBy="#{formateur.formateurId}" id="id_formateur">
#{formateur.formateurId}
</p:column>
<p:column headerText="Adresse" sortBy="#{formateur.adresse}" filterBy="#{formateur.adresse}" id="adresse">
#{formateur.adresse}
</p:column>
<p:column headerText="CIN" sortBy="#{formateur.cin}" filterBy="#{formateur.cin}" id="cin">
#{formateur.cin}
</p:column>
<p:column headerText="Email" sortBy="#{formateur.email}" filterBy="#{formateur.email}" id="email">
#{formateur.email}
</p:column>
<p:column headerText="Nom" sortBy="#{formateur.nom}" filterBy="#{formateur.nom}" id="nom">
#{formateur.nom}
</p:column>
<p:column headerText="Prenom" sortBy="#{formateur.prenom}" filterBy="#{formateur.prenom}" id="prenom">
#{formateur.prenom}
</p:column>
<p:column headerText="Pseudo" sortBy="#{formateur.pseudo}" filterBy="#{formateur.pseudo}" id="pseudo">
#{formateur.pseudo}
</p:column>
<p:column headerText="Sexe" sortBy="#{formateur.sexe}" filterBy="#{formateur.sexe}" id="sexe">
#{formateur.sexe}
</p:column>
<p:column headerText="Telephone" sortBy="#{formateur.telephone}" filterBy="#{formateur.telephone}" id="telephone">
#{formateur.telephone}
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Excluir" />
</f:facet>
<p:commandLink value="Excluir" action="#{formateurController.exclure()}" onclick="if(!confirm('Existe déjà #{formateur.nom}?'))return false;" update ="dataformateur"/>
</p:column>
</p:dataTable>
<h:panelGrid columns="2">
<p:panel header="Export All Data">
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="dataformateur" fileName="formateurs" postProcessor="#{formateurController.postProcessXLS}" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="dataformateur" fileName="formateurs"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="formateur" fileName="formateurs" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="formateur" fileName="formateurs" />
</h:commandLink>
</p:panel>
<p:panel header="Export Page Data">
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="formateur" fileName="formateurs" pageOnly="true"/>
</h:commandLink>
</p:panel>
</h:panelGrid>
<p:dialog header="Formateur Detail" widgetVar="formateurDialog" resizable="false"
width="300" showEffect="explode" hideEffect="explode">
<p:dataList id="display"
value="#{formateurController.selectedFormateurs}"
var="selectedFormateur" type="definition">
Id: #{selectedFormateur.formateurId}, Adresse: #{selectedFormateur.adresse}
</p:dataList>
</p:dialog>
</h:form>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
I'd be grateful for your feedback.
It's because you're printing the variables and not an outputtext with the VALUE of the fields. Took me two hours to figure it out.
Instead of
#{formateur.adresse}
write
<h:outputText value="#{formateur.adresse}" />
You should instantiate Formateur in the beginning itself like:
private Formateur formateur = new Formateur();
When you call its getter, you are checking if formateur is null, but it has not been initialized yet. That might be the problem as far as I understand. I am not sure if you can check if an object is null if it has not even been created/initialized. So, maybe try initializing it in the declarataion itself OR try removing the condition where you check if it is null.
I have a smiliar problem like here: Primefaces: commandButton in confirmDialog cannot update datatable in the same form
I have a table with games. In the last column there are 2 buttons: delete and details.
The delete button should delete the game
The button does delete the game but the update doesn't work.
update=":form1:overviewTableGame" --> no reaction (no refresh)
update="#form" --> update performes (table refreshes), but the entire scren is locked. i think due to the fact, that the form which contains the dialog is updated...
The table code:
<h:form id="form1">
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:dataTable id="overviewTableGame" var="game" value="#{gameMB.list}">
<p:column headerText="#{msg.ID}" sortBy="#{game.id}">
<h:outputText value="#{game.id}" />
</p:column>
<p:column headerText="#{msg.NAME}" sortBy="#{game.name}">
<h:outputText value="#{game.name}" />
</p:column>
<p:column headerText="#{msg.DESCRIPTION}"
sortBy="#{game.description}">
<h:outputText value="#{game.description}" />
</p:column>
<p:column headerText="#{msg.ADMIN}" sortBy="#{game.admin.firstname}">
<h:outputText value="#{game.admin.firstname}" />
</p:column>
<p:column headerText="#{msg.ACTION}">
<p:commandButton id="commandButtonDELETE" value="löschen"
onclick="confirmation.show()" type="button"
update=":form1:display">
<f:setPropertyActionListener value="#{game}"
target="#{gameMB.selectedGame}" />
</p:commandButton>
<p:commandButton id="commandButtonDETAIL" value="detail"
action="#{gameMB.details()}">
<f:param name="id" value="#{game.id}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog id="confirmDialog"
message="Are you sure about destroying the world?"
header="Initiating destroy process" severity="alert"
widgetVar="confirmation">
<h:panelGrid id="display" columns="2" cellpadding="4"
style="margin:0 auto;">
<h:outputText value="Name:" />
<h:outputText value="#{gameMB.selectedGame.name}"
style="font-weight:bold" />
<p:commandButton id="confirm" value="Yes Sure"
oncomplete="confirmation.hide()"
actionListener="#{gameMB.delete(gameMB.selectedGame)}"
update=":form1:overviewTableGame">
</p:commandButton>
</h:panelGrid>
<p:commandButton id="decline" value="Not Yet"
onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
</h:form>
The Delete Method:
public void delete(Game game) {
//FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"DELETE", "Game Deleted!"));
System.out.println("==================");
System.out.println(game);
getGameService().removeGame(game);
//this.gameList = gameService.listAllGames();
}
The selectedGame
private Game selectedGame;
public Game getSelectedGame() {
return selectedGame;
}
public void setSelectedGame(Game selectedGame) {
this.selectedGame = selectedGame;
}
Any ideas?
Thanks
Separate your dialog from p:dataTable. Following code is working:
The xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" template="/WEB-INF/templates/globalTemplate.xhtml">
<ui:define name="title">15344819</ui:define>
<ui:define name="content">
<p:growl id="growl" showDetail="true" />
<h:form id="form">
<p:dataTable id="students" value="#{so15344819.students}" var="student">
<p:column>
<p:commandButton id="selectButton" update=":form:display" oncomplete="studentDialog.show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{student}" target="#{so15344819.selectedStudent}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Student Detail" widgetVar="studentDialog" resizable="false" id="studentDlg"
showEffect="fade" hideEffect="explode" modal="true">
<h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">
<h:outputText value="Name:" />
<h:outputText value="#{so15344819.selectedStudent.name}" style="font-weight:bold"/>
<p:commandButton id="deleteButton" actionListener="#{so15344819.delete(so15344819.selectedStudent)}" oncomplete="studentDialog.hide()"
update=":form:students" value="Delete"/>
<p:commandButton id="cancelButton" onclick="studentDialog.hide()" value="Cancel"/>
</h:panelGrid>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
The managed bean:
package app.so.dev.web.controller;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import app.so.dev.web.model.Student;
#ManagedBean(name = "so15344819")
#ViewScoped
public class SO15344819 implements Serializable {
private static final long serialVersionUID = 6686378446131077581L;
private List<Student> students;
private Student selectedStudent;
#PostConstruct
public void init() {
students = new ArrayList<Student>();
students.add(new Student("Student 1"));
students.add(new Student("Student 2"));
}
public void delete(Student student) {
System.out.println("==================");
System.out.println(student);
students.remove(student);
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
public Student getSelectedStudent() {
return selectedStudent;
}
public void setSelectedStudent(Student selectedStudent) {
this.selectedStudent = selectedStudent;
}
}
Feel free to revert.
I am using primefaces3.3 version. I have a datatable to show the details and the CRUD buttons as part of the footer of the datatable. A Dialog would be shown on click of the CRUD buttons after selecting a particular row in the datatable.
This dialog contains the input fields with requiredMessage and validationMessage properties and a Save button. When i do not enter any input and click on the save button in the dialog the validation message is showing up. However, upon closing the dialog , only the old data is showing up even if a different row is selected in the datatable. I have attached both the BackingBean and xhtml code.
account.xhtml
<?xml version="1.0" encoding="UTF-8" ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<ui:composition template="/template.xhtml">
<ui:define name="body">
<h:form id="form" prependId="false">
<p:contextMenu for="dataTable">
<p:menuitem value="View" update=":form2:accountDisplay"
icon="ui-icon-search" oncomplete="accountDialog.show()"
process="#this">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.selectedAccount}" />
</p:menuitem>
<p:menuitem value="Edit" update=":form2:accountDisplay"
icon="ui-icon-edit" oncomplete="accountDialog.show()"
process="#this" immedeate="true">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.currentAccount}" />
</p:menuitem>
<p:menuitem value="Delete" update=":dialogForm:confirmDialog"
icon="ui-icon-close" oncomplete="confirmation.show()" />
</p:contextMenu>
<h:panelGroup id="dataPanel">
<p:dataTable var="account" value="#{accountBean.accounts}"
paginator="true" rows="20" rowKey="#{account.accountCode}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
selection="#{accountBean.selectedAccount}" selectionMode="single"
id="dataTable">
<p:column id="accountCode" headerText=" Account Code"
sortBy="#{account.accountCode}" filterBy="#{account.accountCode}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.accountCode}" />
</p:column>
<p:column id="accountCode" headerText=" Account Code"
sortBy="#{account.accountDescription}" filterBy="#{account.accountDescription}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.accountDescription}" />
</p:column>
<f:facet name="footer">
<p:toolbar>
<p:toolbarGroup align="left">
<p:commandButton id="btnAdd" value="Add" title="Add New Account"
icon="ui-icon-add"
oncomplete="accountDialog.show()" />
<p:commandButton id="editButton" value="Edit" icon="ui-icon-edit"
update=":form2:accountDisplay" oncomplete="accountDialog.show()">
</p:commandButton>
<p:commandButton id="showDialogButton" icon="ui-icon-delete"
value="Delete"
title="Delete Account Details" oncomplete="confirmation.show()">
</p:commandButton>
<p:commandButton id="viewButton" value="View"
icon="ui-icon-search" update=":form2:display"
oncomplete="accountDialog.show()" />
<p:commandButton id="btnRefresh" styleClass="refreshButton"
title="Refresh Account Information" value="Refresh"
icon="ui-icon-refresh"
actionListener="#{accountBean.populateAccounts}"
update=":form:dataTable"/>
</p:toolbarGroup>
</p:toolbar>
</f:facet>
</p:dataTable>
</h:panelGroup>
</h:form>
<h:form id="form2">
<!-- <p:growl id="growl" showDetail="true" sticky="true" /> -->
<p:dialog id="basicDialog" header="Account Details"
widgetVar="detailDialog" resizable="false">
<h:panelGrid id="display" columns="2">
<h:outputText value="#{bundle.AccountLabel_accountCode}" />
<h:outputText value="#{accountBean.selectedAccount.accountCode}"
title="#{bundle.AccountTitle_accountCode}" />
<h:outputText value="#{bundle.AccountLabel_accountDescription}" />
<h:outputText value="#{accountBean.selectedAccount.accountDescription}"
title="#{bundle.AccountTitle_alertCode}" />
</h:panelGrid>
</p:dialog>
<p:dialog header="Account Detail" widgetVar="accountDialog"
resizable="false" height="600" width="600" showEffect="clip"
hideEffect="fold" id="dialog" modal="true">
<h:panelGrid id="accountDisplay" columns="2" cellpadding="4">
<f:facet name="header">
<p:messages id="messages" autoUpdate="true" />
</f:facet>
<h:outputLabel value="Account Code:" for="accountCode" />
<p:inputText label="Account Code" id="accountCode"
value="#{accountBean.selectedAccount.accountCode}"
title="Account Code" required="true"
validatorMessage="#{bundle.AccountValidationAccountCode}" requiredMessage="#{bundle.AccountRequiredMessage_accountCode}">
</p:inputText>
<h:outputLabel value="Account Description:" for="accountDescripition" />
<p:inputText label="Account Description" id="accountDescription"
value="#{accountBean.selectedAccount.accountDescription}"
title="Account Description" required="true"
validatorMessage="#{bundle.AccountValidationAccountDescription}" requiredMessage="#{bundle.AccountRequiredMessage_accountDescription}">
</p:inputText>
<f:facet name="footer">
<!-- <p:commandButton value="New" icon="ui-icon-check"/> -->
<h:outputLabel />
<p:commandButton styleClass="saveButton" value="Save"
icon="ui-icon-check"
actionListener="#{accountBean.createOrUpdate}"
update=":form:dataTable,:form2:accountDisplay" oncomplete="if (!args.validationFailed) {accountDialog.hide();}"/>
<p:commandButton styleClass="cancelButton" value="Cancel"
icon="ui-icon-cancel" oncomplete="accountDialog.hide()" process="#this"/>
</f:facet>
</h:panelGrid>
</p:dialog>
</h:form>
<h:form id="dialogForm">
<p:confirmDialog id="confirmDialog" header="Confirm Delete Account"
severity="alert" widgetVar="confirmation">
<f:facet name="message">
<h:outputText
value="Delete #{accountBean.selectedAccount.accountCode}?" />
</f:facet>
<p:commandButton id="confirm" value="Yes"
oncomplete="confirmation.hide()" update=":form:dataTable"
actionListener="#{accountBean.remove}" ajax="false"/>
<p:commandButton id="decline" value="No"
onclick="confirmation.hide()" type="button" ajax="false"/>
</p:confirmDialog>
</h:form>
</ui:define>
</ui:composition>
AccountBean.java
package com.cba.web.beans;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;
import com.cba.services.AccountService;
import com.cba.utils.ServiceLocator;
import com.cba.web.model.Account;
#ManagedBean(name = "accountBean")
#ViewScoped
public class AccountBean implements Serializable {
private transient AccountService accountService;
private List<Account> accounts;
private Account selectedAccount = new Account();
private Account currentAccount = new Account();
public Account getSelectedAccount() {
return selectedAccount;
}
public void setSelectedAccount(Account selectedAccount) {
this.selectedAccount = selectedAccount;
}
public Account getCurrentAccount() {
return currentAccount;
}
public void setCurrentAccount(Account currentAccount) {
this.currentAccount = currentAccount;
}
public AccountBean() {
populateAccounts();
}
public AccountService getAccountService() {
return accountService;
}
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
public List<Account> getAccounts() {
return accounts;
}
public void populateAccounts() {
accountService = (AccountService) ServiceLocator.getInstance().getBean(
"accountService");
accounts = accountService.getAccountDetails();
}
public void createOrUpdate(ActionEvent e) {
try {
System.out.println("entering createOrUpdate in AccountBean");
accountService = (AccountService) ServiceLocator.getInstance()
.getBean("accountService");
accountService.updateAccountDetails(selectedAccount);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void remove(ActionEvent e) {
try {
accountService = (AccountService) ServiceLocator.getInstance()
.getBean("accountService");
accountService.deleteAccountDetails(selectedAccount);
selectedAccount = new Account();
populateAccounts();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I am using Google Chrome 19 and IE 8. Any input on this would be appreciated. Thanks in advance