java.lang.IllegalArgumentException: Setter not found for property class - jsf

I want to implement a table with row editing.
I found this exemple in the showcase, but I get this error evry time :
javax.servlet.ServletException: Setter not found for property class
java.lang.IllegalArgumentException: Setter not found for property
class
My xhtml
<a4j:status onstart="#{rich:component('statPane')}.show()"
onstop="#{rich:component('statPane')}.hide()" />
<h:form id="form">
<rich:dataScroller for="dataTableId" maxPages="8" />
<rich:extendedDataTable id="dataTableId" rows="200"
value="#{declarationReglementaireModel.detailCurrentDecReg.decReg.listLigneTa3SDTO}"
var="ligneTA3" frozenColumns="2"
style="height:300px; width:800px;" selectionMode="none">
<rich:column width="35px">
<h:panelGrid columns="1" cellpadding="2">
<a4j:commandLink class="lien_detail" render="editGrid"
execute="#this"
oncomplete="#{rich:component('editPane')}.show()">
<span class="icone icone-edit icone-align-center" />
<a4j:param value="1"
assignTo="#{modifDecRegTa3Model.currentLigneTa3Index}" />
<f:setPropertyActionListener target="#{modifDecRegTa3Model.editedRow}"
value="#{ligne}" />
</a4j:commandLink>
</h:panelGrid>
</rich:column>
<rich:column width="150px" sortBy="#{ligneTA3.idTitre}"
sortOrder="ascending">
<f:facet name="header">Référence Titre</f:facet>
<h:outputText value="#{ligneTA3.idTitre}">
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="a" />
</f:facet>
<h:outputText value="#{ligneTA3.vlColA}">
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="b" />
</f:facet>
<h:outputText value="#{ligneTA3.vlColB}">
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="c" />
</f:facet>
<h:outputText value="#{ligneTA3.vlColC}">
</h:outputText>
</rich:column>
<rich:dataScroller for="dataTableId" maxPages="8" />
<rich:popupPanel id="statPane" autosized="true">
Please wait...
</rich:popupPanel>
<rich:popupPanel header="Modifier ligne" id="editPane" domElementAttachment="parent" width="400" height="170">
<h:panelGrid columns="3" id="editGrid">
<h:outputText value="vlColA" />
<h:outputText value="#{modifDecRegTa3Model.editedRow.vlColA}" />
<h:panelGroup />
<h:outputText value="vlColB" />
<h:outputText value="#{modifDecRegTa3Model.editedRow.vlColB}" />
<h:panelGroup />
<h:outputText value="vlColC" />
<h:inputText value="#{cmodifDecRegTa3Model.editedRow.vlColC}" required="true" requiredMessage="Price is required" id="price"/>
</h:panelGrid>
<a4j:commandButton value="Store" action="#{rechercheDecRgltCtrl.validerModifications}" render="table" execute="editPane"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editPane')}.hide();}" />
<a4j:commandButton value="Cancel" onclick="#{rich:component('editPane')}.hide(); return false;" />
</rich:popupPanel>
</h:form>
</h:panelGrid>
</h:form>
My Model
#ManagedBean(name="modifDecRegTa3Model")
#SessionScoped
public class ModifDecRegTa3Model {
private static final long serialVersionUID = 1L;
private LigneTa3DTO currentElement;
private Integer selectedPage;
private int currentLigneTa3Index;
private LigneTa3DTO editedRow;
public ModifDecRegTa3Model() {
super();
}
public LigneTa3DTO getCurrentElement() {
return currentElement;
}
public void setCurrentElement(LigneTa3DTO currentElement) {
this.currentElement = currentElement;
}
public Integer getSelectedPage() {
return selectedPage;
}
public void setSelectedPage(Integer selectedPage) {
this.selectedPage = selectedPage;
}
public int getCurrentLigneTa3Index() {
return currentLigneTa3Index;
}
public void setCurrentLigneTa3Index(int currentLigneTa3Index) {
this.currentLigneTa3Index = currentLigneTa3Index;
}
public LigneTa3DTO getEditedRow() {
return editedRow;
}
public void setEditedRow(LigneTa3DTO editedRow) {
this.editedRow = editedRow;
}
}

This is probably related to your bad attribute :
<a4j:commandLink class="lien_detail" />
There is no attribute class for the component a4j:commandLink you should use styleClass instead.

Related

JSF h:commandButton is not working inside h:DataTable

I'm trying to delete a specific data in a table, i try to get the column id by using commandButton but it doesn't work, i tried to just show a message in the console when the button is clicked but no luck at all, i tried also some solutions that were offered in this community but it didn't work for me.
Ps: i tried to use ViewScoped instead of request, but it didnt work too.
Here is a part of my code:
<f:view>
<h:form>
<h:commandButton
value="Afficher les demandes"
action="#{demandeBean1.listedemandes}"
styleClass="btn btn-success" />
</h:form>
<h:form>
<h:dataTable
value="#{demandeBean1.demandes}"
var="demande"
styleClass="table table-bordered"
cellspacing="4"
width="60%"
rowClasses="paire,impaire"
headerClass="titre">
<h:column>
<f:facet name="header">
<h:outputText value="Date de demande" />
</f:facet>
<h:outputText value="#{demande.dateDmd}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date de debut" />
</f:facet>
<h:outputText value="#{demande.dateDbtAbs}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date de fin" />
</f:facet>
<h:outputText value="#{demande.dateFinAbs}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Nombre de jours" />
</f:facet>
<h:outputText value="#{demande.nbrJr}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<h:outputText value="#{demande.type}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<h:outputText value="#{demande.status}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Action" />
</f:facet>
<h:commandButton
value="Supprimer"
styleClass="btn btn-danger"
actionListener="#{demandeBean1.supprimer(demande.idDmd)}">
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
</f:view>
My Bean:
#Named
#RequestScoped
public class DemandeBean implements Serializable {
private int idDmd;
private Date dateDbtAbs;
private Date dateDmd;
private Date dateFinAbs;
private int nbrJr;
private String status;
private String type;
private List<Demande> demandes;
public DemandeBean() {}
public void supprimer(int id) {
System.out.println("It works"); //this is not displaying
}
}

Filtered jsf outputtext

I would like to know how to filter so that only the patents of vehicles that are available appear.
<p:column headerText="Patent car">
<h:outputText value="#{v.fkcar.patent}"/>
</p:column>
In the database there is a table called State with 2 income
id_state 1 ---- name_state Available and id_state 2 ---- name_state Not available
What I need is that only the patents of the vehicles that have the State in Available are shown
The State table has its respective Bean
I hope you can help me: D
Entry code Rent
<h:head>
<title>Realizar Alquiler</title>
<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
<h2>Realizar Alquiler</h2>
<h:form id="fv">
<h:panelGrid columns="1" styleClass="panelGridCenter">
<h:outputText value="Precio"/>
<p:inputText value="#{alquilerBean.precio}" required="true"/>
<p:outputLabel for="datetime" value="Fecha" />
<p:calendar id="datetime" value="#{alquilerBean.fecha3}" pattern="MM/dd/yyyy HH:mm:ss" required="true"/>
Cliente
<p:selectOneMenu value="#{alquilerBean.cliente.idCliente}">
<f:selectItems value="#{clienteBean.cliente}" var="e" itemLabel="#{e.rut}" itemValue="#{e.idCliente}"/>
</p:selectOneMenu>
Patente
<p:selectOneMenu value="#{alquilerBean.vehiculo.idVehiculo}">
<f:selectItems value="#{vehiculoBean.vehiculos}" var="o" itemLabel="#{o.patente}" itemValue="#{o.idVehiculo}"/>
</p:selectOneMenu>
¿Entregado?
<p:selectOneMenu value="#{alquilerBean.entregado.idEntregado}">
<f:selectItems value="#{entregadoBean.entregado}" var="o" itemLabel="#{o.nombreEntregado}" itemValue="#{o.idEntregado}"/>
</p:selectOneMenu>
<br/>
<h:outputText value=""/>
<p:commandButton actionListener="#{alquilerBean.crear()}" value="Agregar Alquiler" update="fv"/>
</h:panelGrid>
<br/>
<p:dataTable value="#{alquilerBean.alquiler}" var="v" emptyMessage="No hay registros" >
<p:column headerText="Fecha">
<h:outputText value="#{v.fecha}"/>
</p:column>
<p:column headerText="Precio">
<h:outputText value="#{v.precio}"/>
</p:column>
<p:column headerText="Entregado">
<h:outputText value="#{v.fkEntregado.nombreEntregado}"/>
</p:column>
<p:column headerText="Rut Cliente">
<h:outputText value="#{v.fkCliente.rut}"/>
</p:column>
<p:column headerText="Patente Auto"
<h:outputText value="#{v.fkVehiculo.patente}"/>
</p:column>
</p:column>
<f:facet name="footer">
Se han alquilado #{alquilerBean.alquiler.size()} Vehiculos.
</f:facet>
</p:dataTable>
</h:form>
<br/>
<h:form>
<h:commandLink action="index">
<h:graphicImage value="resources/images/atras2.png" />
</h:commandLink>
</h:form>
</h:body> </html>
Here is the state bean code.
private int id_entregado;
private String nombre_entregado;
public EntregadoBean() {
}
public String crear(){
Entregado e = new Entregado();
e.setNombreEntregado(nombre_entregado);
entregadoFacade.create(e);
return "#";
}
public List<Entregado> getEntregado(){
return entregadoFacade.findAll();
}
public EntregadoFacadeLocal getEntregadoFacade() {
return entregadoFacade;
}
public void setEntregadoFacade(EntregadoFacadeLocal entregadoFacade) {
this.entregadoFacade = entregadoFacade;
}
public int getId_entregado() {
return id_entregado;
}
public void setId_entregado(int id_entregado) {
this.id_entregado = id_entregado;
}
public String getNombre_entregado() {
return nombre_entregado;
}
public void setNombre_entregado(String nombre_entregado) {
this.nombre_entregado = nombre_entregado;
}
}

Displaying Error Message after selecting multiple check box for edit

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

Passing parameters between xhtml

I'm trying to pass a parameter between two xhtml, I have the next code for the first xhtm
<h:dataTable value="#{ofertaController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_idoferta}"/>
</f:facet>
<h:outputText value="#{item.idoferta}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_fechaInicio}"/>
</f:facet>
<h:outputText value="#{item.fechaInicio}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_fechaFin}"/>
</f:facet>
<h:outputText value="#{item.fechaFin}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_descripcion}"/>
</f:facet>
<h:outputText value="#{item.descripcion}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_precioInicial}"/>
</f:facet>
<h:outputText value="#{item.precioInicial}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_precioFinal}"/>
</f:facet>
<h:outputText value="#{item.precioFinal}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_negocioCif}"/>
</f:facet>
<h:outputText value="#{item.negocioCif}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<h:commandLink action="#{ofertaController.prepareView}" value="#{bundle.ListOfertaViewLink}"/>
<h:outputText value=" "/>
<h:commandLink action="#{ofertaController.prepareEdit}" value="#{bundle.ListOfertaEditLink}"/>
<h:outputText value=" "/>
<h:commandLink action="#{ofertaController.destroy}" value="#{bundle.ListOfertaDestroyLink}"/>
<h:link outcome="/cupon/compra" value="Comprar">
<f:param name="idOferta" value="#{item.idoferta}" />
</h:link>
</h:column>
</h:dataTable>
As you can see I have a:
<h:link outcome="/cupon/compra" value="Comprar">
<f:param name="idOferta" value="#{item.idoferta}" />
</h:link>
And I get the next url:
http://localhost:8080/agrupados/faces/cupon/compra.xhtml?idOferta=1
This idOferta=1 I want to use it in a Managed bean but always, it appears as null, why?. The xhtml which I linked before is this one:
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="#{bundle.CreateCuponLabel_email}" for="email" />
<h:inputText id="email" value="#{cuponController.selected.email}" title="#{bundle.CreateCuponTitle_email}" required="true" requiredMessage="#{bundle.CreateCuponRequiredMessage_email}"/>
</h:panelGrid>
<br />
<h:commandLink action="#{cuponController.create}" value="#{bundle.CreateCuponSaveLink}" />
<br />
<br />
<h:commandLink action="#{cuponController.prepareList}" value="#{bundle.CreateCuponShowAllLink}" immediate="true"/>
<br />
<br />
<h:link outcome="/index" value="#{bundle.CreateCuponIndexLink}"/>
<br/>
<h:commandButton id="compra" value="COMPRAR" action="#{compra.addCompra}" />
</h:form>
And the ManagedBean is this one where is the addCompra:
#ManagedBean(name="compra")
#RequestScoped
public class Compra {
#EJB
private NegocioFacade negocioFacade;
#EJB
private OfertaFacade ofertaFacade;
#ManagedProperty(value = "#{param.idOferta}")
private String idOferta;
//(String)
public Compra() {
}
public void addCompra(){
System.out.println(idOferta);
FacesContext fc=FacesContext.getCurrentInstance();
String idoferta=ofer(fc);
System.out.println(idoferta);
}
public String ofer(FacesContext fc){
Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
return params.get("idOferta");
}
}
What can I do?, how can I get this idOferta=1?. Thanks so much for all guys
you can use f:viewParam like this:
<f:metadata>
<f:viewParam name="idOferta" value="#{compra.idOferta}" />
</f:metadata>
just don't forget to add the getter-setter methods for idOferta to class compra, and remove the #ManagedProperty annotation.

JSF Primefaces datatable in cell editMode not sending the edited value to the managed bean

I have two primefaces dataTables. The first show the instances of a MainEntity.
The second one show a list of Words (just strings) associated with the selected MainEntity on the first datatable.
The printscreen illustrates what I mean.
My problem is, when I edit a string on the Word List, my listener method won't receive the new value. In fact, when I call the event.getNewValue() method, I get old value.
What am I missing?
I'm using JavaServer Faces 2.2, Primefaces 5.0 and Spring Framework 4.0.3.
Thanks in advance for any help.
The code for the xhtml, the managed bean and the MainEntity are as follows:
mainEntity.xhtml:
<h:body>
<h:form id="mainEntityForm">
<p:panelGrid columns="1" fullPage="true" id="dashboard">
<f:facet name="header">
<h2>MainEntity Table</h2>
</f:facet>
<p:panel>
<f:facet name="header">
MainEntity List
<p:commandButton value="New MainEntity"
actionListener="#{mainEntityController.createMainEntityDialog}"
styleClass="header-button">
<p:ajax event="dialogReturn" update=":mainEntityForm:mainEntityTable" />
</p:commandButton>
</f:facet>
<p:dataTable id="mainEntityTable" var="mainEntity" value="#{mainEntityController.mainEntities}"
editable="true" editMode="cell" widgetVar="cellMainEntity"
selectionMode="single" selection="#{mainEntityController.selectedMainEntity}"
rowKey="#{mainEntity.id}" tableStyle="width:auto">
<p:ajax event="rowSelect" update=":mainEntityForm:stringGrid :mainEntityForm:entityAGrid :mainEntityForm:entityBGrid" />
<p:ajax event="cellEdit" listener="#{mainEntityController.onEditMainEntity}" update=":mainEntityForm:mainEntityTable" />
<p:column headerText="ID">
<h:outputText value="#{mainEntity.id}" />
</p:column>
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="nameOutput" value="#{mainEntity.name}" />
</f:facet>
<f:facet name="input">
<h:inputText id="atyInput" value="#{mainEntity.qty}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Commands">
<p:commandButton title="Remove MainEntity" icon="ui-icon-trash"
actionListener="#{mainEntityController.deleteMainEntity(mainEntity)}"
update=":mainEntityForm:mainEntityTable" />
</p:column>
</p:dataTable>
</p:panel>
<p:panelGrid fullPage="true" id="mainEntityDetail">
<f:facet name="header">
<p:row>
<p:column colspan="4">
<h2>MainEntity Detail</h2>
</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<p:panel>
<f:facet name="header">
Word List
<p:commandButton value="New Word"
actionListener="#{mainEntityController.addNewWord()}"
styleClass="header-button"
update=":mainEntityForm:wordGrid">
</p:commandButton>
</f:facet>
<p:dataTable id="wordGrid" var="word"
value="#{mainEntityController.selectedMainEntity.wordList}"
tableStyle="width:auto" editable="true" editMode="cell" widgetVar="cellWord">
<p:ajax event="cellEdit" listener="#{mainEntityController.onEditWord}" />
<p:column headerText="Word">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="wordOutput" value="#{word}" />
</f:facet>
<f:facet name="input">
<h:inputText id="wordInput" value="#{word}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Commands">
<p:commandButton title="Remove Word"
icon="ui-icon-trash"
actionListener="#{mainEntityController.removeWord(word)}"
update=":mainEntityForm:wordGrid" />
</p:column>
</p:dataTable>
</p:panel>
</p:column>
</p:row>
</p:panelGrid>
</p:panelGrid>
</h:form>
</h:body>
MainEntityController.java (managed bean):
#ManagedBean
#SessionScoped
public class MainEntityController {
//...
private MainEntity selectedMainEntity;
public List<MainEntity> mainEntities;
//...
public MainEntity getSelectedMainEntity(){
return selectedMainEntity;
}
public void setSelectedMainEntity(MainEntity mainEntity){
this.selectedMainEntity = mainEntity;
}
//...
public void onEditWord(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
// THE PROBLEM IS HERE
// I NEVER ACTUALLY REACH THIS CODE
// newValue is always equal to oldValue!
FacesContext context = FacesContext.getCurrentInstance();
String word = context.getApplication().evaluateExpressionGet(context, "#{word}", String.class);
System.out.println(newValue);
System.out.println(word);
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Word Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
MainEntity.java:
#Entity
public class MainEntity {
#Id
private String id;
#ElementCollection(fetch=FetchType.EAGER)
#CollectionTable(
name="MainEntity_Word",
joinColumns = #JoinColumn(name = "id", referencedColumnName="id")
)
#Column(name = "word")
private Set<String> wordList;
//...
public void addWord(String word) {
this.wordList.add(word);
}
public void removeWord(String word) {
this.wordList.remove(word);
}
public Set<String> getWordList() {
return wordList;
}
public void setWordList(Set<String> wordList) {
this.wordList = wordList;
}
}
Change
<h:inputText id="wordInput" value="#{word}" />
to
<p:inputText id="wordInput" value="#{word}" />
or
<h:inputText id="wordInput" value="#{word}" >
<p:ajax event="change" process="#this"/>
</h:inputText>
You need to ajaxify the input component, and at last update the outputText component.
Edited:
change this column :
<p:column headerText="Word" >
<p:cellEditor>
<f:facet name="output">
<h:outputText id="wordOutput" value="#{word}" />
</f:facet>
<f:facet name="input">
<h:inputText id="wordInput" value="#{word}" />
</f:facet>
</p:cellEditor>
</p:column>
to
<p:column headerText="Word" >
<p:cellEditor>
<f:facet name="output">
<h:outputText id="wordOutput" value="#{word}" />
</f:facet>
<f:facet name="input">
<p:inputText id="wordInput" value="#{word}" >
<p:ajax event="change" update="wordOutput" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
Edit 2 :
From Chapter 24 Introduction to the Java Persistence API
If an entity instance be passed by value as a detached object, such as
through a session bean’s remote business interface, the class must
implement the Serializable interface.
I finally got it working.
I suspected of the String immutable nature and what I did was to encapsulate the 'word' in a class like the following:
public class Word {
private String word;
Word (String word) {
this.setWord(word);
}
public String getWord() {
return this.word;
}
public void setWord(String word) {
this.word = word;
}
}
After that, I also had to create a set inside the managed bean (controller) to hold the set of words, like 'private Set managedWordList;'.
I also changed the getter for the list, inside the managed bean, to convert from the String set to a Word set like:
public Set<Word> getWordList() {
if (this.selectedMainEntity != null){
this.wordList = new HashSet<Word>();
for (String word : this.selectedMainEntity.getWordList()) {
this.wordList.add(new Word(word));
}
}
return this.wordList;
}
Finally, I changed the dataTable to reference the new set. From:
<p:dataTable ... value="#{mainEntityController.selectedMainEntity.wordList}"... />
To:
<p:dataTable ... value="#{mainEntityController.wordList}"... />
And only then I got it to work as I expected.

Resources