javax.ejb.EJBException: Transaction aborted - jpa

I'm a student :D and I'm working on a project for Web Technologies. I have to work in JavaEE in JSF framework with JPA, EJB, JDBC, and I have a problem.
Warning: #{cc.attrs.loginButtonAction}: javax.ejb.EJBException: Transaction aborted
javax.faces.FacesException: #{cc.attrs.loginButtonAction}: javax.ejb.EJBException: Transaction aborted
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at
All errors
https://shrib.com/#Gaur8rM4LwV
And my code.
EJB. Controller with database
#Stateless
public class UsersFacade extends AbstractFacade<Users> {
#PersistenceContext(unitName = "OtoNaszDomPU")
private EntityManager em;
#Override
protected EntityManager getEntityManager() {
return em;
}
//...
//...
public String LoginAuthentication(String username, String password) {
Users user = null;
user = GetUser(username);
if (user == null) {
return "notExist";
}
String salt = user.getSalt();
byte[] hashed = HashSha256(password.concat(salt));
String encryptedPassword = bytesToString(hashed);
System.out.println("haslo:" + password + ", salt:" + salt + ", sha: " + encryptedPassword + " == " + user.getPassword());
//Until next line everything works properly.
return encryptedPassword.equals(user.getPassword()) == true ? "true" : "false";
}
Methods Hash256 and byteToString works properly
And My front
komponentyZlozone:Logowanie is a CompositeComponent
<center>
<h:form class="centered Form">
<h3 style="font-size: 50px">Oto Nasz Dom</h3>
<komponentyZlozone:Logowanie
usernameLabel="#{bundle['logowanie.pseudonim']}"
usernameValue="#{loginController.user}"
passwordLabel="#{bundle['logowanie.haslo']}"
passwordValue="#{loginController.pwd}"
loginButtonLabel="#{bundle['logowanie.zaloguj']}"
loginButtonAction="#{loginController.validateUsernamePassword()}"
/>
<br/><br/>
<h:button value="Rejestracja" outcome="userRegister" style="font-size: 25px; box-shadow: gray; padding: 5px;">
<f:ajax execute="toogle" render="toogleRender" event="click"/>
</h:button>
</h:form>
</center>
CompositeComponent "Blueprint"
<?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://java.sun.com/jsf/html"
xmlns:f = "http://java.sun.com/jsf/core"
xmlns:composite = "http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name = "usernameLabel" />
<composite:attribute name = "usernameValue" />
<composite:attribute name = "passwordLabel" />
<composite:attribute name = "passwordValue" />
<composite:attribute name = "loginButtonLabel" />
<composite:attribute name = "loginButtonAction"
method-signature = "java.lang.String validateUsernamePassword()" />
</composite:interface>
<composite:implementation>
<h:form>
<h:panelGrid columns = "2" id = "loginPanel">
#{cc.attrs.usernameLabel} :
<h:inputText id = "username" value = "#{cc.attrs.usernameValue}" required="true" />
#{cc.attrs.passwordLabel} :
<h:inputSecret id = "password" value = "#{cc.attrs.passwordValue}" required="true" />
</h:panelGrid>
<h:commandButton
action = "#{cc.attrs.loginButtonAction}"
value = "#{cc.attrs.loginButtonLabel}"
style="padding: 10px"
/>
</h:form>
</composite:implementation>
</html>
Thanks for help!
edit.
I don't uderstand why i'm getting this error. During debugging i could not find out what's the problem. :(

Related

Clearing forms and components in JSF 2.2 [duplicate]

This question already has answers here:
Clear JSF form input values after submitting
(5 answers)
Closed 5 years ago.
After you have made a registration, it clears the form normally, but when I turn the page and come back to the registration page, the fields are filled with the values ​​I have registered before. The scoped I'm using is #ViewScoped.
Registration page..
Realizar Emprestimos
<h:form id="form" prependId="false">
<p:messages id="msgs"/>
<p:toolbar>
<f:facet name="left">
<p:toolbarGroup>
<p:commandButton value="Confirmar" action="#{empMB.inserir}" process="#this"
update="form:list_publicacao" ajax="false">
<f:ajax render="form:list_publicacao" resetValues="true"/>
</p:commandButton>
</p:toolbarGroup>
</f:facet>
<f:facet name="right">
<p:toolbarGroup>
<p:commandButton value="Cancelar" action="#{empMB.limparCampos()}"
immediate="true">
<f:ajax render="#form" resetValues="true"/>
</p:commandButton>
</p:toolbarGroup>
</f:facet>
</p:toolbar>
<f:ajax event="blur">
<h:panelGrid id="p1" columns="4" layout="grid">
<p:outputLabel value="Usuário: " for="usuario" />
<p:selectOneMenu id="usuario" effect="fade" filter="true"
filterMatchMode="contains"
value="#{empMB.emprestimo.usuario.idUsuario}" required="true"
requiredMessage="Selecione um usuário">
<f:selectItem itemLabel="selecione um usuario"
noSelectionOption="true" />
<f:selectItems value="#{usuarioMB.todosUsuarios}" var="usu"
itemValue="#{usu.idUsuario}" itemLabel="#{usu.nomeUsuario}" />
</p:selectOneMenu>
<p:outputLabel value="Data Emprestimo: " for="dataEmprestimo" />
<p:calendar id="dataEmprestimo"
value="#{empMB.emprestimo.dataEmprestimo}" effect="fold"
navigator="true" required="true"
requiredMessage="Inserir uma data do emprestimo"
pattern="dd/MM/yyyy" title="Data do Emprestimo">
<f:convertDateTime pattern="dd/MM/yyyy" locale="pt_BR"
timeZone="America/Sao_Paulo" />
</p:calendar>
</h:panelGrid>
<h:panelGrid id="p2" columns="2" layout="grid">
<p:outputLabel value="Publicacao: " for="publicacao" />
<p:selectOneMenu label="Publicação:" id="publicacao" effect="fade"
filter="true" filterMatchMode="contains"
value="#{empMB.emprestimo.publicacao.publicacaoId}">
<f:selectItem itemLabel="Selecione uma publicação"
noSelectionOption="true" />
<f:selectItems value="#{pubMB.publicacoesDisponiveis}" var="pub"
itemValue="#{pub.publicacaoId}" itemLabel="#{pub.titulo}" />
<f:ajax listener="#{empMB.setlistPublicacao()}"
render="list_publicacao msgs publicacao" />
</p:selectOneMenu>
</h:panelGrid>
<h2 style="font-size: 1.9em; margin-top: 3%;">Publicações
selecionadas</h2>
<p:dataTable reflow="true" id="list_publicacao"
value="#{empMB.listPublicacaoDesejada}" var="pub"
emptyMessage="Suas publicações aparecerão aqui.">
<ui:include src="/colunasPublicacoes.xhtml" />
</p:dataTable>
</f:ajax>
</h:form>
</ui:define>
Method..
public Emprestimo inserir() {
System.out.println(getListPublicacaoDesejada().size());
try {
for (int i = 0; i < getListPublicacaoDesejada().size(); i++) {
Calendar dataPrevista = Calendar.getInstance();
dataPrevista.setTime(emprestimo.getDataEmprestimo());
dataPrevista.add(Calendar.DAY_OF_MONTH,
Integer.parseInt(JSFHelper.getExternalContext().getInitParameter("previsaoDevolucao")));
emprestimo.setFuncionarioEmprestimo("usuarioteste08");
emprestimo.setDataPrevistaDevolucao(dataPrevista.getTime());
emprestimo.getPublicacao().setPublicacaoId(emprestimo.getListPublicacao().get(i).getPublicacaoId());
emprestimoFacade.inserir(emprestimo);
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Emprestimo(s)", "realizado(s) com sucesso!");
RequestContext.getCurrentInstance().showMessageInDialog(message);
emprestimo = new Emprestimo();
return emprestimo;
} catch (DAOException e) {
e.printStackTrace();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Atenção", "Erro ao realizada emprestimo");
RequestContext.getCurrentInstance().showMessageInDialog(message);
return null;
}
}
Thank you very much in advance.
Solved, I added the PostConstruct method at the beginning of MB.
#PostConstruct
public void init() {
emprestimo = new Emprestimo();
}

How to save form data from <t:dataTable> in JSF 1.2

I am trying to save the data edited in a t:dataTable object when a user clicks on a Save button h:commandButton. However, before the action is called, the postConstruct() method in the bean is called which tries to load the data for the table, but does not have the docId that was initially passed in. I have tried using f:param in the h:commandButton to pass in the docId, but that does not work. Does anyone have the correct strategy for loading the page with a docId, then saving the changes once the save button is clicked? The following is my current bean code and xhtml. I do not have the option of upgrading to JSF 2.0 yet unfortunately.
<h:form enctype="multipart/form-data">
<t:outputText value="Document: #{documentWorkflowCommentsBean.document.name}" />
<br/><br/>
<t:dataTable id="commentTable" sortable="false"
value="${documentWorkflowCommentsBean.document.workflowComments}"
var="comment"
styleClass="addmTable">
<t:column styleClass="commentId">
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<t:outputText value="${comment.commentId}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Reviewer" />
</f:facet>
<t:outputText value="${comment.reviewer}"/>
</t:column>
<t:column styleClass="charColumn">
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<t:outputText value="${comment.commentType}"
rendered="${!documentWorkflowCommentsBean.editComments}"/>
<t:selectOneListbox id="typeList" title="Choose Comment type"
size="1" rendered="${documentWorkflowCommentsBean.editComments}"
value="${comment.commentType}">
<f:selectItems value="${documentWorkflowCommentsBean.commentTypes}"/>
</t:selectOneListbox>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Page" />
</f:facet>
<t:outputText value="${comment.pageNumber}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Section/Paragraph" />
</f:facet>
<t:outputText value="${comment.sectionParagraph}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Comment/Rationale" />
</f:facet>
<t:outputText value="${comment.commentRationale}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="PO Resolution" />
</f:facet>
<t:outputText value="${comment.poResolution}"
rendered="${!documentWorkflowCommentsBean.editComments}"/>
<t:inputTextarea id="poResolutionTextArea" value="${comment.poResolution}"
rendered="${documentWorkflowCommentsBean.editComments}"
rows="3" cols="20"/>
</t:column>
<t:column styleClass="charColumn">
<f:facet name="header">
<h:outputText value="Decision" />
</f:facet>
<t:outputText value="${comment.decision}"
rendered="${!documentWorkflowCommentsBean.editComments}"/>
<t:selectOneListbox id="decisionList" title="Choose Decision"
size="1" rendered="${documentWorkflowCommentsBean.editComments}"
value="${comment.decision}">
<f:selectItems value="${documentWorkflowCommentsBean.commentDecisions}"/>
</t:selectOneListbox>
</t:column>
</t:dataTable>
<br/>
<h:commandButton value="Save" action="#{documentWorkflowCommentsBean.saveDocumentComments}">
<f:param name="docId" value="#{documentWorkflowCommentsBean.documentId"/>
<f:param name="editComments" value="#{documentWorkflowCommentsBean.editComments}"/>
</h:commandButton>
<input type="button" value="Cancel" title="Close the dialog" onclick="closeModal();"/>
</h:form>
public class DocumentWorkflowCommentsBean extends PageBean {
private static final long serialVersionUID = -866249792018248429L;
private static final Logger log = LogManager.getLogger(DocumentWorkflowCommentsBean.class);
/**
* Holds a reference to the DocumentBusiness object.
*
* #uml.property name="docBiz"
*/
private DocumentBusiness docBiz;
/**
* This represents the documentId parameter passed
*
* #uml.property name="documentId"
*/
private long documentId;
/**
* This is the corresponding Document object represented by the documentId property
*
* #uml.property name="document"
*/
private Document document;
/**
* Determines if the Type, Resolution, and Decision fields are editable
*
* #uml.property name="editComments"
*/
private boolean editComments = false;
private static final List<SelectItem> COMMENT_TYPES = Arrays.asList(new SelectItem("C", "C"),
new SelectItem("M", "M"),
new SelectItem("S", "S"),
new SelectItem("A", "A"));
private static final List<SelectItem> COMMENT_DECISIONS = Arrays.asList(
new SelectItem("A", "A"),
new SelectItem("R", "R"),
new SelectItem("M", "M"));
/**
* This is called after all resources are injected
*/
#PostConstruct
public void postConstruct() {
docBiz = BusinessUtils.getDocumentBusiness();
// Get the parameters that are passed in
String docIdString = (String) getPassedParam("docId");
String editString = (String) getPassedParam("editComments");
// editComments will be null when closing dialog
if (editString != null) {
editComments = Boolean.parseBoolean(editString);
}
if (docIdString != null) {
try {
// Retrieve the Document object
documentId = Long.parseLong(docIdString);
} catch (NumberFormatException ignore) {
// do nothing
log.error("Invalid parameter - " + docIdString);
}
if (documentId > 0) {
//lazy load of workflow comments to be displayed
document = docBiz.getDocumentFetchWorkflowComments(documentId);
}
// Check to see that the Document exists
if (document == null) {
this.getAddmSessionBean().addPageErrorMessage("Cannot perform action - document has been deleted.");
}
}
}
public String saveDocumentComments() {
docBiz.updateDocument(document); //JPA merge call on document
return null;
}
public long getDocumentId() {
return documentId;
}
public void setDocumentId(long documentId) {
this.documentId = documentId;
}
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
public List<SelectItem> getCommentTypes() {
return COMMENT_TYPES;
}
public List<SelectItem> getCommentDecisions() {
return COMMENT_DECISIONS;
}
}
As you're apparently already using Tomahawk, you can just simulate the JSF 2.x view scope using <t:saveState>.
Put this somewhere in the view to make a JSF 1.x request scoped bean to behave like a JSF 2.x view scoped bean:
<t:saveState value="#{documentWorkflowCommentsBean}" />
This way the bean will live as long as you interact with the same view by postbacks returning void/null and it won't be reconstructed/reinitialized on every postback, exactly like as in JSF 2.x.

xhtml don't recognize methods declared in managed Bean

in my XHTML page I can't call methods declared in managed bean, I'm new to this platform , I'd like that some one clarifies this to me. I'm working on a JSF 2.1 project with JPA on Eclipse Juno 4.2
here's my managed been code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package managedBean;
import java.util.List;
import javax.ejb.Local;
import model.*;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import service.EmpFacadeLocal;
/**
*
* #author Louuup
*/
#ManagedBean (name= "empbean")
#RequestScoped
#ViewScoped
public class EmpManagedBean {
public Employe emp;
#EJB
public EmpFacadeLocal empfacadelocal;
public Boolean saisie;
private List<Employe> emps;
private String iddd;
private Employe selectedemp;
private List<Employe> filteredemps;
private Employe[] selectedemps;
/**
* Creates a new instance of EmpManagedBean
*/
public EmpManagedBean() {
emps = new ArrayList<Employe>();
}
#PostConstruct
public void initEmp(){
emp = new Employe();
saisie = false;
emps = empfacadelocal.getEmpRq("");
}
public Employe getEmp() {
return emp;
}
public void setEmp(Employe emp) {
this.emp = emp;
}
public Boolean getSaisie() {
return saisie;
}
public void setSaisie(Boolean saisie) {
this.saisie = saisie;
}
public List<Employe> getEmps() {
return emps;
}
public void setEmps(List<Employe> emps) {
this.emps = emps;
}
public String getIddd() {
return iddd;
}
public void setIddd(String iddd) {
this.iddd = iddd;
}
public Employe getSelectedemp() {
return selectedemp;
}
public void setSelectedemp(Employe selectedemp) {
this.selectedemp = selectedemp;
}
public List<Employe> getFilteredemps() {
return filteredemps;
}
public void setFilteredemps(List<Employe> filteredemps) {
this.filteredemps = filteredemps;
}
public Employe[] getSelectedemps() {
return selectedemps;
}
public void setSelectedemps(Employe[] selectedemps) {
this.selectedemps = selectedemps;
}
public void findEmpaff(){
//admin = adminfacadelocal.getAdmin(iddd);
emps = empfacadelocal.getEmpRq("");
}
public void creerEmp(){
System.out.println("azertre ");
empfacadelocal.create(emp);
saisie = true;
}
}
and here is my xhtml 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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<body>
<ui:composition template="./../resource/Template.xhtml">
<ui:define name="title">
<title> Ajout emp</title>
</ui:define>
<ui:define name="page">
<h:form id="dd">
<p:growl id="growl" showDetail="true"/>
<p:panel header="Fiche Emplyé" >
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputLabel value="Matricule Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{empbean.emp.matEmp}"/>
<h:outputLabel value="Nom Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{empbean.emp.nomEmp}"/>
<h:outputLabel value="Prénom Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{empbean.emp.prenomEmp}"/>
<h:outputLabel value="Date de naissance Employé :"/>
<p:calendar disabled="#{empbean.saisie}" locale="pt" showButtonPanel="true" navigator="true" id="pttCal" value="#{empbean.emp.dateNaisEmp}"/>
<h:outputLabel value="Adresse Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{empbean.emp.adressEmp}"/>
<h:outputLabel value="N° téléph Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{emp.emp.numTelfEmp}"/>
<h:outputLabel value="E-mail Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{empbean.emp.emailEmp}"/>
<h:outputLabel value="N° compte Employé :"/>
<p:inputText disabled="#{empbean.saisie}" value="#{empbean.emp.numCompteEmp}"/>
<p:selectOneMenu disabled="#{empManagedBean.saisie}" value="#{empbean.emp.fonctionEmp}">
<f:selectItem itemLabel="Jardinier" itemValue="Jardinier" />
<f:selectItem itemLabel="Agent d'hygiene" itemValue="Agent d'hygiene" />
<f:selectItem itemLabel="Agent de sécurité" itemValue="Agent de sécurité" />
<f:selectItem itemLabel="Magasinier" itemValue="Magasinier" />
</p:selectOneMenu>
</h:panelGrid><br/>
<p:commandButton disabled="#{empbean.saisie}" value="Valider" update="dd" style="margin-left: 250px;" actionListener="#{empbean. }"/>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
I want call "creerEmp" method in command button's actionlistener like this #{empbean.creerEmp()} but I can't do this , please someone help me
A method for an actionlistener needs to have an ActionEvent parameter. But I think what you want is a normal action which should be fine like this:
<p:commandButton disabled="#{empbean.saisie}" value="Valider"
update="dd" style="margin-left: 250px;" action="#{empbean.creerEmp}"/>
Should work with #{empbean.creerEmp} . ActionEvent parameter is not neccesary.
You should try without composition component firstly to see if your ActionListener method works. Besides I think that You're using composition component incorrectly.

RichFaces 4 dataTable edit issue

I would like to do such table with editing like here -> http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=dataTable&sample=dataTableEdit&skin=blueSky . The problem ist that, when I do changes in editPane (popupPanel) they are not remembered in private OsobaTelefon edytujOsobe. This make update impossible via JPA. I have all getters and setters and class OsobaTelefon implements Serializable.
#ManagedBean(name = "administrator")
#ViewScoped
#SessionScoped
public class Administrator implements Serializable
#EJB
private UzytkownikFacade uzytkownikFacade;
private static final long serialVersionUID = 1L;
#EJB
private OsobaFacade osobaFacade;
private Osoba osobaAdmina;
private int numerStrony = 1;
private Uzytkownik uzytkownik;
private List<Osoba> listaOsob;
private static final int CLIENT_ROWS_IN_AJAX_MODE = 10;
private int clientRows;
private int wybranaOsoba;
private OsobaTelefon edytujOsobe; //it doesn't remember the changes made in editPane
private List<OsobaTelefon> osobyITelefony;
/**
* Creates a new instance of Administrator
*/
public Administrator() {
}
public void aktualizacjaWybranejOsoby() {
this.osobyITelefony.set(this.wybranaOsoba, this.edytujOsobe);
Osoba nowaOsoba = new Osoba();
List<Telefon> nowaListaTelefonow = new ArrayList<Telefon>();
OsobaTelefon osobaTelefon = this.osobyITelefony.get(this.wybranaOsoba);
int o = this.osobyITelefony.get(this.wybranaOsoba).getIdosoby();
int of = this.osobyITelefony.get(this.wybranaOsoba).getIdtelefonu();
System.out.println("Wybrana osoba ID " + o);
System.out.println("Wybrane ID fona " + of);
boolean znalezionoOsobe = false;
Iterator<Osoba> iteOs = this.listaOsob.iterator();
while (!znalezionoOsobe && iteOs.hasNext()) {
Osoba os = iteOs.next();
if (os.getIdosoba() == o) {
znalezionoOsobe = true;
nowaOsoba.setIdosoba(os.getIdosoba());
nowaOsoba.setImie(osobaTelefon.getImie());
nowaOsoba.setNazwisko(osobaTelefon.getNazwisko());
nowaOsoba.setKodpocztowy(osobaTelefon.getKodpocztowy());
nowaOsoba.setMiejscowosc(osobaTelefon.getMiejscowosc());
nowaOsoba.setUlica(osobaTelefon.getUlica());
nowaOsoba.setUzytkownikList(os.getUzytkownikList());
Telefon nowyTelefon = new Telefon();
for (Telefon tel : os.getTelefonList()) {
if (tel.getIdtelefon() == of) {
nowyTelefon.setFkIdosoba(nowaOsoba);
nowyTelefon.setIdtelefon(of);
nowyTelefon.setNumer(this.edytujOsobe.getNumer());
System.out.println("Nr tel. "+tel.getNumer());
nowyTelefon.setOpis(this.edytujOsobe.getOpis());
nowyTelefon.setZastrzezony(this.edytujOsobe.getZastrzezony());
nowaListaTelefonow.add(nowyTelefon);
} else {
nowaListaTelefonow.add(tel);
}
}
nowaOsoba.setTelefonList(nowaListaTelefonow);
this.osobaFacade.aktualizujOsoba(nowaOsoba);
this.pobierzOsobyDoTabeli();
}
}
}
public List<Osoba> pobierzOsobyDoTabeli() {
//getting people with phone to List<OsobaTelefon> works good
}
public void switchAjaxLoading(ValueChangeEvent event) {
this.clientRows = (Boolean) event.getNewValue() ? CLIENT_ROWS_IN_AJAX_MODE : 0;
}
public void zapelnijListeTelefonow() {
//getting people phone number to List<Phone> works good
}
public void usunOsobe() {
//deleting people works good
}
}
The XHTML
<a4j:status onstart="#{rich:component('statPane')}.show()" onstop="#{rich:component('statPane')}.hide()" />
<h:form id="formProjekty">
<rich:dataTable value="#{administrator.osobyITelefony}"
var="pr"
iterationStatusVar="ite"
id="table"
rows="8" >
<rich:column width="auto">
<f:facet name="header">Imię</f:facet>
<h:outputText value="#{pr.imie}" />
</rich:column>
<rich:column>
<a4j:commandLink styleClass="no-decor"
render="editGrid"
execute="#this"
oncomplete="#{rich:component('editPane')}.show()">
<h:graphicImage library="img" name="edit.gif" alt="Edycja"/>
<a4j:param value="#{ite.index}"
assignTo="#{administrator.wybranaOsoba}" />
<f:setPropertyActionListener target="#{administrator.edytujOsobe}"
value="#{pr}" />
</a4j:commandLink>
<a4j:commandLink styleClass="no-decor"
execute="#this"
render="#none"
oncomplete="#{rich:component('confirmPane')}.show()">
<h:graphicImage library="img" name="delete.gif" alt="Usuń"/>
<a4j:param value="#{ite.index}"
assignTo="#{administrator.wybranaOsoba}" />
<f:setPropertyActionListener target="#{administrator.edytujOsobe}"
value="#{pr}" />
</a4j:commandLink>
</rich:column>
<f:facet name="footer">
<rich:dataScroller page="#{administrator.numerStrony}" />
</f:facet>
</rich:dataTable>
<a4j:jsFunction name="remove"
action="#{administrator.usunOsobe()}"
render="table"
execute="#this"
oncomplete="#{rich:component('confirmPane')}.hide();" />
<a4j:jsFunction name="edycja"
action="#{administrator.aktualizacjaWybranejOsoby()}"
render="table"
execute="#this"
oncomplete="#{rich:component('editPane')}.hide();" />
<rich:popupPanel id="statPane" autosized="true">
<h:graphicImage library="img" name="ai.gif" alt="Czekaj"/>
Proszę czekać...
</rich:popupPanel>
<rich:popupPanel id="confirmPane" autosized="true">
Czy na pewno usunać?
<a4j:commandButton value="Tak" onclick="remove();
return false;" />
<a4j:commandButton value="Nie"
onclick="#{rich:component('confirmPane')}.hide();
return false;" />
</rich:popupPanel>
<rich:popupPanel header="Edycja Osoby"
id="editPane"
domElementAttachment="parent" width="180" height="420">
<h:panelGrid columns="1" id="editGrid">
<h:panelGroup >
<h:outputText value="Imię" /><br />
<h:inputText value="#{administrator.edytujOsobe.imie}" >
<f:validateLength maximum="32" minimum="3"/>
</h:inputText>
</h:panelGroup>
</h:panelGrid><br/>
<a4j:commandButton value="Aktualizuj"
onclick="edycja(); return false;"/>
<a4j:commandButton value="Anuluj"
onclick="#{rich:component('editPane')}.hide();
return false;" />
</rich:popupPanel>
</h:form>
if you can change it then make your Aktualizuj a4j-link a little bit easier. Just try that:
<a4j:commandButton value="Aktualizuj"
onclick="#{rich:component('editPane')}.hide();"
action="#{administrator.aktualizacjaWybranejOsoby()}" render="table"/>
and put an a4j:region about your inputText and your link to send only the required values:
<rich:popupPanel header="Edycja Osoby"
id="editPane"
domElementAttachment="parent" width="180" height="420">
<a4j:region>
<h:panelGrid columns="1" id="editGrid">
<h:panelGroup >
<h:outputText value="Imię" /><br />
<h:inputText value="#{administrator.edytujOsobe.imie}" >
<f:validateLength maximum="32" minimum="3"/>
</h:inputText>
</h:panelGroup>
</h:panelGrid><br/>
<a4j:commandButtonvalue="Aktualizuj" onclick="# {rich:component('editPane')}.hide();"action="#{administrator.aktualizacjaWybranejOsoby()}" render="table"/>
<a4j:commandButton value="Anuluj"
onclick="#{rich:component('editPane')}.hide();
return false;" />
</a4j:region>
</rich:popupPanel>
I also add a render="table" to the Aktualizuj a4j:link to update the value in the datatable

PrimeFaces login attempt (example) failure

I am testing the PrimeFaces example avaible at http://www.primefaces.org/showcase/ui/dialogLogin.jsf . I correctly imported PrimeFaces and JSF 2.1 in Eclipse Dyamic web project, but after filling the form when I try to do the login I get the following error:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.el.MethodNotFoundException: Method not found: classi.LoginBean#ee03ec.login()
javax.faces.webapp.FacesServlet.service(FacesServlet.java:229)
root cause
org.apache.myfaces.view.facelets.el.ContextAwareMethodNotFoundException: javax.el.MethodNotFoundException: Method not found: classi.LoginBean#ee03ec.login()
org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:104)
javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)
javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:418)
javax.faces.component.UICommand.broadcast(UICommand.java:103)
javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
root cause
javax.el.MethodNotFoundException: Method not found: classi.LoginBean#ee03ec.login()
org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:225)
org.apache.el.parser.AstValue.invoke(AstValue.java:253)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)
javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:418)
javax.faces.component.UICommand.broadcast(UICommand.java:103)
javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.21 logs.
Apache Tomcat/7.0.21
LoginBean.java is:
package classi;
import java.awt.event.ActionEvent;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
#ManagedBean(name="loginBean")
#SessionScoped
public class LoginBean
{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void login(ActionEvent actionEvent) {
RequestContext context = RequestContext.getCurrentInstance();
FacesMessage msg = null;
boolean loggedIn = false;
if(username != null &&&& username.equals("admin") && password != null && password.equals("admin")) {
loggedIn = true;
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);
} else {
loggedIn = false;
msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials");
}
FacesContext.getCurrentInstance().addMessage(null, msg);
context.addCallbackParam("loggedIn", loggedIn);
}
}
login.xhtml is:
<?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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h:outputLink id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login">
<p:graphicImage value="/images/login.png" />
</h:outputLink>
<p:growl id="growl" showDetail="true" life="3000" />
<p:dialog id="dialog" header="Login" widgetVar="dlg">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}"
id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}"
id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login" update=":growl"
actionListener="#{loginBean.login}"
oncomplete="handleLoginRequest(xhr, status, args)"/>
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<script type="text/javascript">
function handleLoginRequest(xhr, status, args) {
if(args.validationFailed || !args.loggedIn) {
jQuery('#dialog').effect("shake", { times:3 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
</body>
</html>
You have a bad import, replace :
import java.awt.event.ActionEvent;
with
import javax.faces.event.ActionEvent;
Also, is that &&&& working?! Maybe you have a special compiler if it doesn't give you error :)
if(username != null &&&& username.equals("admin") && password != null && password.equals("admin"))