RichFaces 4 dataTable edit issue - jpa

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

Related

multiple forms on page submitting to first form?

I have three forms in one page, each calls a different backing bean, but when i use a form other than the first one the call goes three times to the first form, each form persists into a DB.Table and the persistence is being done three times when i click the commandButtons, is this bad practice or am I missing something in my code ?
<h:form id="ciclista-form" >
<div id="ciclista-link"><h1>Crear Ciclista</h1></div>
// inputTexts ... .. .
<h:commandButton action="#{ciclistaBean.guardarCiclista()}" value="Guardar Ciclista" class="ciclista-form-btn"/>
</h:form>
<h:form id="Etapa-form" > Etapa-form -->
<div id="Etapa-link"><h1>Crear Etapa</h1></div> -->
// input texts . ..
<h:commandButton action="#{etapaBean.guardarEtapa()}" value="Guardar Etapa" class="carrera-form-btn"/> -->
</h:form> Etapa-form -->
<h:form id="carrera-form" > <!-- carrera-form -->
<div id="carrera-link"><h1>Crear carrera</h1></div>
// input texts . . .
<h:commandButton action="#{carreraBean.guardarCarrera()}" value="Guardar Carrera" class="etapa-form-btn" />
</h:form> <!-- carrera-form -->
all calls go to first form, why is this ?
The snipped you show seems ok, what type are your beans? What scope do they have? Have they dependencies to another?
I tried to follow you idea with following code, it works in my setup...
<h:body>
<h:form id="ciclista-form">
<div id="ciclista-link">
<h1>Crear Ciclista</h1>
<h:inputText value="#{ciclistaBean.text}"/>
</div>
<h:commandButton action="#{ciclistaBean.guardarCiclista()}" value="Guardar Ciclista" class="ciclista-form-btn" />
</h:form>
<h:form id="Etapa-form">
<div id="Etapa-link">
<h1>Crear Etapa</h1>
<h:inputText value="#{etapaBean.text}"/>
</div>
<h:commandButton action="#{etapaBean.guardarEtapa()}" value="Guardar Etapa" class="carrera-form-btn" />
</h:form>
<h:form id="carrera-form">
<div id="carrera-link">
<h1>Crear carrera</h1>
<h:inputText value="#{carreraBean.text}"/>
</div>
<h:commandButton action="#{carreraBean.guardarCarrera()}" value="Guardar Carrera" class="etapa-form-btn" />
</h:form>
</h:body>
with three independend #RequestScoped beans
#ManagedBean(name = "ciclistaBean")
#RequestScoped
public class SO26836137_F1 {
private String text;
public void guardarCiclista() {
System.out.println("Form 1 submitted: " + text);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
#ManagedBean(name = "etapaBean")
#RequestScoped
public class SO26836137_F2 {
private String text;
public void guardarEtapa() {
System.out.println("Form 2 submitted: " + text);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
#ManagedBean(name = "carreraBean")
#RequestScoped
public class SO26836137_F3 {
private String text;
public void guardarCarrera() {
System.out.println("Form 3 submitted: " + text);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

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.

Passing id parameters to form for load dynamically content in JSF

I have as follows:
I have a datatable that prints a historic of mobiles assigned in a determined moment to a list of users, that datatable prints both: assigned and non-assigned, when the administrator wants to edit a particular assignment can change date of assignment, date of expired, number of line, mobile, etc... Well, I make a query for that which only shows mobiles and lines to edit to this user that are NO assigned in that moment for anyone and show the line and terminal that is assign for that user in that moment for if I want to edit some fields relative to his number and terminal and not have to assign another mobile or line because if I do that, line and mobile assigned for that user will not appear for edit and I would be obligated to choose another one.
That's it but I don't know how to load that list of mobiles and list based in the code of assignment to make the filter for my query when it shows up the modal bootstrap form selects retrieve this data according to this code, that's it the code:
asignacion.jsf
<h:dataTable columnClasses="codigo, fechaini, fechafin, terminal, usuario, numero, perfil, asignado" class="table table-striped table-bordered bootstrap-datatable datatable" value="${listaTerminales.listaAsigMovil_2}" var="o">
<h:column class="hide">
<f:facet name="header">
<h:outputText value="Codigo"/>
</f:facet>
<h:outputText value="${o.codigo}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Fecha Asignación"/>
</f:facet>
<h:outputText value="${o.fechaIniStr}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Fecha Baja"/>
</f:facet>
<h:outputText value="${o.fechaFinStr}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Terminal"/>
</f:facet>
<h:inputHidden class="idTerminal" value="${o.codigoTerminal.codigo}" />
<h:outputText value="${o.codigoTerminal.marca} ${o.codigoTerminal.modelo}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Usuario"/>
</f:facet>
<h:outputText value="${o.dni.dni}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Número"/>
</f:facet>
<h:outputText value="${o.codigoNumero.numero}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Perfil"/>
</f:facet>
<h:inputHidden class="idPerfil" value="${o.codigoPerfil.codigo}" />
<h:outputText value="${o.codigoPerfil.descripcion}"/>
</h:column>
<c:if test="${rol == 'administrador'}">
<h:column>
<f:facet name="header">
<h:outputText value="Asignado"/>
</f:facet>
<h:outputText value="${o.asignado}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Acciones"/>
</f:facet>
<a data-toggle='modal' href='#asig-movil' class='btn btn-success edit'>
<i class='icon3-edit icon-white'></i>Editar</a>
</h:column>
</c:if>
</h:dataTable>
<!-- start modal -->
<div class="hide fade modal" id="asig-movil">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Editar Datos</h3>
</div>
<h:form class="form-horizontal well" id="form-asig-movil">
<div class="modal-body">
<fieldset>
<h:inputHidden id="codigo-form" value="#{terminalesBean.codigoAsig}">
</h:inputHidden>
<h:inputHidden id="dni-form" value="#{listaTerminales.dni}"></h:inputHidden>
<h4>Asignado: </h4><h:selectOneRadio layout="lineDirection" id="asignado-form" value="#{listaTerminales.codAsignado}">
<f:selectItem id="y" itemLabel="SI" itemValue="S"/>
<f:selectItem id="n" itemLabel="NO" itemValue="N"/>
</h:selectOneRadio>
<h4>Número de Teléfono: </h4><h:selectOneMenu class="validate[required]" id="numero-form" value="#{listaTerminales.codigoNumero}">
<f:selectItems var="l" itemLabel="#{l.numero}" itemValue="#{l.codigo}" value="#{lineasBean.listaLineasNoAsig}" />
</h:selectOneMenu>
<h4>Terminal: </h4><h:selectOneMenu class="validate[required]" id="terminal-form" value="#{listaTerminales.codigoTerminal}">
<f:selectItems var="t" itemLabel="#{t.marca} #{t.modelo}" itemValue="#{t.codigo}" value="#{terminalesBean.terminalesMovilAndAsig}" />
</h:selectOneMenu>
<h4>Perfil </h4><h:selectOneMenu class="validate[required]" id="perfil-form" value="#{listaTerminales.codigoPerfil}">
<f:selectItems var="p" itemLabel="#{p.descripcion}" itemValue="#{p.codigo}" value="#{perfilBean.listaPerfiles}" />
</h:selectOneMenu>
<h4>Fecha asignación: </h4><h:inputText class="validate[required]" id="fechaini-form" value="#{listaTerminales.fechaAsig}"></h:inputText>
<h4>Fecha finalización: </h4><h:inputText class="validate[required]" id="fechafin-form" value="#{listaTerminales.fechaFin}"></h:inputText>
</fieldset>
</div>
<div class="modal-footer">
Cancelar
<p:commandButton id="okInsertar" onclick="if($('#form-asig-movil').validationEngine('validate')===false){return false;}"
styleClass="btn btn-primary ok" value="Ok" action="#{listaTerminales.modificar()}"
oncomplete="checkCRUD(xhr, status, args)">
</p:commandButton>
</div>
</h:form>
</div>
<!-- end modal -->
terminalesBean.java
package app.bean;
import app.dao.TerminalFacade;
import app.entity.Terminal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;
/**
*
* #author Usuario
*/
#ManagedBean
#RequestScoped
#ViewScoped
public class terminalesBean {
#EJB
private TerminalFacade termFac;
private int codigo;
private String fecha_alta;
private Date fecha_alta_date;
private String marca;
private String modelo;
private String configuracion;
private int sn;
private List<Terminal> terminales;
private int codigoAsig;
public int getCodigo(){
return this.codigo;
}
public void setCodigo(int codigo){
this.codigo = codigo;
}
public String getFechaAlta(){
SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
if(fecha_alta_date!=null)
return formatoFecha.format(fecha_alta_date);
return null;
}
public void setFechaAlta(String fecha){
SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
try {
this.fecha_alta_date = formatoFecha.parse(fecha);
this.fecha_alta = fecha;
} catch (ParseException ex) {
Logger.getLogger(lineasBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
public String getMarca(){
return this.marca;
}
public void setMarca(String marca){
this.marca = marca;
}
public String getModelo(){
return this.modelo;
}
public void setModelo(String modelo){
this.modelo = modelo;
}
public String getConfiguracion(){
return this.configuracion;
}
public void setConfiguracion(String configuracion){
this.configuracion = configuracion;
}
public int getSN(){
return this.sn;
}
public void setSN(int sn){
this.sn = sn;
}
public void setCodigoAsig(int codigoAsig){
this.codigoAsig = codigoAsig;
}
public int getCodigoAsig(){
return this.codigoAsig;
}
public List<Terminal> getTerminales(){
terminales = (List<Terminal>)termFac.findAll();
return this.terminales;
}
public List<Terminal> getTerminalesFijoAndAsig(){
terminales = (List<Terminal>)termFac.findByFijoAndAsig(this.codigoAsig);
return this.terminales;
}
public List<Terminal> getTerminalesMovilAndAsig(){
terminales = (List<Terminal>)termFac.findByMovilAndAsig(this.codigoAsig);
return this.terminales;
}
public void setTerminales(List<Terminal> terminales){
this.terminales = terminales;
}
public void borrar(){
Terminal t = new Terminal();
t = termFac.find(codigo);
termFac.delete(t);
}
public void insert(){
Terminal t;
t =(Terminal)termFac.findbysn(sn);
if(t == null && this.sn != 0){
t = new Terminal();
//t.setCodigo(codigo);
t.setFechaAlta(new Date());
t.setConfiguracion(configuracion);
t.setMarca(marca);
t.setModelo(modelo);
t.setSn(sn);
termFac.insert(t);
}
else{
t.setConfiguracion(configuracion);
t.setMarca(marca);
t.setModelo(modelo);
t.setSn(sn);
termFac.edit(t);
}
RequestContext reqCtx = RequestContext.getCurrentInstance();
reqCtx.addCallbackParam("codigo", t.getCodigo());
reqCtx.addCallbackParam("fecha_alta", t.getFechaAltaStr());
reqCtx.addCallbackParam("marca", t.getMarca());
reqCtx.addCallbackParam("modelo", t.getModelo());
reqCtx.addCallbackParam("configuracion", t.getConfiguracion());
reqCtx.addCallbackParam("sn", t.getSn());
}
public terminalesBean() {
}
}
What I want is pass the ${o.codigo} parameter to method setCodigAsig() for then make the filter in method getTerminalesMovilAndAsig() and in the modal load load the content with ids "numero-form" and "terminal-form", how can I do this when click Edit in each row of the datatable and load modal form of this content dynamically according with this code?
Regards!

Show message of confirmation

I want to display a message to confirm creation of a group but I cannot diplay it.
group.xhtml:
<h:form id="grp">
<h:panelGrid columns="2">
<h:outputText value="Titre:"></h:outputText>
<p:inputText value="#{gpeBean.titre}"></p:inputText>
<p:commandButton id="btn_save"
value="Créer"
actionListener="#{gpeBean.test}">
</p:commandButton>
</h:panelGrid>
</h:form>
</center>
</h:panelGrid>
<h:form id="cr" rendered = "#{gpeBean.created}">
<h:outputText value="#{gpeBean.message}"/>
</h:form>
my bean :
#ManagedBean(name = "gpeBean")
#RequestScoped
public class GroupeBean implements Serializable{
GroupDAO daoGrp = new GroupDaoImpl();
UserDAO dao = new UserDaoImpl();
private String titre;
public String message = "";
private boolean created = false;
public String test(ActionEvent event){
Groupe p = new Groupe();
p.setTitre(this.titre);
daoGrp.Nouveau_groupe(p);
created = true;
this.setMessage("Groupe crée!");
return "p1";
}}
when I click button to execute method test, message is not displayed.
You use #ViewScoped in your bean.
Xhtml:
<h:form id="grp">
<h:panelGrid columns="2">
<h:outputText value="Titre:"></h:outputText>
<p:inputText value="#{gpeBean.titre}"></p:inputText>
<p:commandButton update=":grp:cr" id="btn_save"
value="Créer"
actionListener="#{gpeBean.test}">
</p:commandButton>
</h:panelGrid>
<p:outputPanel id="cr">
<h:outputText rendered="#{gpeBean.created}" value="#{gpeBean.message}"/>
</p:outputPanel >
</h:form>

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.