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>
Related
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();
}
This question is a follow on from a previous question "InputText value null when disabled is true" however I can not add comments to it.
I am using jsf 2.2 and the both the disabled and readonly properties when set true, for the inputText and inputTextarea controls when included in a form is deleting data from the associated field in the database when the object is merged because the fields are null when the object is returned from the jsf page.
The purpose for setting these properties on a form's field is to display the data in the field but not allow the user to change it and save changes to other fields in the form.
What other way can this be achieved other than placing the fields outside of the form and complicate the page layout.
Graham
I solved the problem, it was caused by using #RequestScoped instead of #SessionScoped for my page controller bean.
What I was doing was using a edit link from a datatable passing the current product object to the doEditProduct method.
<h:dataTable id="viewProductsTable" value="#{productController.products}" var="_product"
styleClass="data-table" headerClass="table-header" rowClasses="table-row">
<h:column>
<f:facet name ="header">
<h:outputText value="Product Name" />
</f:facet>
<h:outputText value="#{_product.productName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Goal"/>
</f:facet>
<h:outputText value="#{_product.goal}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Details"/>
</f:facet>
<h:outputText value="#{_product.description}"/>
</h:column>
<h:column>
<h:form>
<h:commandLink value="Edit" action="#{productController.doEditProduct(_product)}"/>
</h:form>
</h:column>
</h:dataTable>
the productController.doEditProduct method then opened the edit page
public String doEditProduct(Product product) {
this.product = product;
return "edit-product.xhtml";
the edit page contained a simple edit form
<h:form id="addProductForm">
<h:panelGrid columns="2" columnClasses="top-alignment, top-alignment">
<h:outputLabel for="product-name" value="Product Name"/>
<h:outputText value="#{productController.product.productName}" id="product-name" />
<h:outputLabel for="goal" value="Goal" />
<h:inputTextarea value="#{productController.product.goal}" id="goal" rows="10" cols="100" />
<h:outputLabel for="details" value="Details" />
<h:inputTextarea value="#{productController.product.description}" id="details" rows="20" cols="100"/>
<f:facet name="footer">
<h:panelGroup style="padding-top: 15px; display: inline-block; float: right; white-space: nowrap">
<h:commandButton id="submit" value="Save" action="#{productController.updateProduct()}" class="button" />
<h:button id="Cancel" outcome="index.xhtml" value="Cancel" class="button"/>
</h:panelGroup>
</f:facet>
</h:panelGrid>
</h:form>
At this point the product data was displayed on the page. However when the save button was clicked and ran the update method
public String updateProduct() {
try {
log.log(Level.INFO, "Updating: {0}", product.getGoal());
productFacade.edit(product);
} catch (Exception e) {
log.log(Level.WARNING, e.toString());
String errorMessage = getRootErrorMessage(e);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "could not update product");
facesContext.addMessage(null, m);
return "";
}
return "index.xhtml";
Any field that had was disabled or readonly was set to null. In fact any non input field, anywhere on the page was set to null.
#RequestScope on the controller class meant that the class was being reinstantiated and thus the object stored in product was being assigned a new object in the PostConstruct method. The values in the editable fields were transferred to this new object and the non editable fields were set to null. Merging with the database meant that the data in the fields was deleted.
Using #SessionScoped means that the controller beans continues to exist across page requests. (I needed to remind myself about basic web page lifecycles)
Hope this helps anybody else that has this behaviour.
Graham
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.
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!
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