JSF ajax validation don't validate items with required true - ajax

I have a datatable, a column with h:commandlink for edit (ajax request), the detail show in jquery dialog, everything ok, in the edit form i have h:commandlink (ajax request) for save, if i make changes eg, drop a value in input required, and push submit, jsf don't validate this input, and don't show the message "this input is required"
<div id="container">
<button id="create-user" >Create new user</button>
<h:dataTable value="#{gasweb.lsProveedor}" var="tabpro" id="example" class="display dataTable" >
<h:column>
<f:facet name="id">
<h:outputLabel value="Id"/>
</f:facet>
<h:outputText value="#{tabpro.proveedor_id}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Cedula"/>
</f:facet>
<h:outputText value="#{tabpro.cedula_ruc}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="NombreComercial"/>
</f:facet>
<h:commandLink value="#{tabpro.nombre_comercial}" actionListener="#{gasweb.doEditProveedor2}" class="labrir" >
<f:param name="pproveedor_id" value="#{tabpro.proveedor_id}" />
<f:ajax execute="#this" render=":forma:editgrid" >
</f:ajax>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Razon Social"/>
</f:facet>
<h:outputText value="#{tabpro.razon_social}"/>
</h:column>
</h:dataTable>
</div>
<div id="divformap" title="Proveedor">
<h:inputHidden value="#{gasweb.newRecord}" id="txtnewrecord" />
<h:inputHidden value="#{gasweb.ruc_proveedor_ori}" id="txtcedulaori" />
<h:panelGrid columns="2" id="editgrid" >
<h:outputLabel value="Id :" />
<h:outputText id="txtid" value="#{gasweb.proveedor.proveedor_id}" />
<h:outputLabel value="Ruc :" />
<h:inputText id="txtcedula" value="#{gasweb.proveedor.cedula_ruc}" size="20" class="text ui-widget-content ui-corner-all" />
<h:outputLabel value="Nombr Comercial :" />
<h:inputText id="txtnombre" value="#{gasweb.proveedor.nombre_comercial}" required="true" size="80" class="text ui-widget-content ui-corner-all"/>
<h:outputLabel value="Razón Social :" />
<h:inputText id="txtrazon" value="#{gasweb.proveedor.razon_social}" size="80" class="text ui-widget-content ui-corner-all"/>
<h:outputLabel value="Dirección :" />
<h:inputText id="txtdireccion" value="#{gasweb.proveedor.direccion}" size="80" class="text ui-widget-content ui-corner-all"/>
<h:outputLabel value="Telefono :" />
<h:inputText id="txttelefono" value="#{gasweb.proveedor.telefono}" size="20" class="text ui-widget-content ui-corner-all"/>
<h:outputLabel value="Estado :" />
<h:outputText id="txtestado" value="#{gasweb.proveedor.estado}" />
<h:commandButton id="aceptar" value="Aceptar" actionListener="#{gasweb.doGrabaProveedor}" >
<f:param name="pproveedor_id2" value="#{gasweb.proveedor.proveedor_id}" />
<f:ajax render="bProveedor" execute="#form" onevent="resetFocus" />
</h:commandButton>
<h:outputText id="bProveedor" value="#{gasweb.bProveedorExiste}" />
</h:panelGrid>
</div>
My managed bean
public class GasperWebMB implements Serializable{
private List<Contribuyente> lsContribuyente;
private List<Proveedor> lsProveedor;
private Contribuyente contribuyente;
private Proveedor proveedor;
private Declara serdec;
private FacesContext fc = FacesContext.getCurrentInstance();
private Boolean newRecord;
private String ruc_proveedor_ori;
private String bProveedorExiste;
//#ManagedProperty("#param.pproveedor_id")
//private Integer pproveedor_id;
//private HttpServletRequest request;
public GasperWebMB(){
serdec = new Declara();
contribuyente = new Contribuyente();
proveedor = new Proveedor();
lsContribuyente = serdec.getAllContribuyente();
lsProveedor = serdec.getAllProveedor();
newRecord = true;
log("creado");
//request.getHeader(ruc_proveedor_ori);
}
public String getbProveedorExiste() {
return bProveedorExiste;
}
public void setbProveedorExiste(String bProveedorExiste) {
this.bProveedorExiste = bProveedorExiste;
}
public String getRuc_proveedor_ori() {
log(ruc_proveedor_ori);
return ruc_proveedor_ori;
}
public void setRuc_proveedor_ori(String ruc_proveedor_ori) {
log(ruc_proveedor_ori);
this.ruc_proveedor_ori = ruc_proveedor_ori;
}
public Boolean getNewRecord() {
log(newRecord);
return newRecord;
}
public void setNewRecord(Boolean newRecord) {
log(newRecord);
this.newRecord = newRecord;
}
public List<Proveedor> getLsProveedor() {
log(lsProveedor);
return lsProveedor;
}
public void setLsProveedor(List<Proveedor> lsProveedor) {
log(lsProveedor);
this.lsProveedor = lsProveedor;
}
public Proveedor getProveedor() {
log(proveedor);
return proveedor;
}
public void setProveedor(Proveedor proveedor) {
log(proveedor);
this.proveedor = proveedor;
}
public List<Contribuyente> getLsContribuyente() {
return lsContribuyente;
}
public void setLsContribuyente(List<Contribuyente> lsContribuyente) {
this.lsContribuyente = lsContribuyente;
}
public Contribuyente getContribuyente() {
return contribuyente;
}
public void setContribuyente(Contribuyente contribuyente) {
this.contribuyente = contribuyente;
}
public String doEditContribuyente(){
Map<String, String> params = fc.getExternalContext().getRequestParameterMap();
contribuyente = serdec.getContribuyenteById(Integer.parseInt(par));
newRecord = false;
ruc_proveedor_ori = proveedor.getCedula_ruc();
return "FContribuyente";
}
public String doGrabaContribuyente(){
System.out.println("grabar " + contribuyente.getCedula_ruc()+ " id " + contribuyente.getContribuyente_id());
serdec.updContribuyente(contribuyente);
return "lisContribuyente";
}
public String doEditProveedor(){
System.out.println("Entra");
Map<String, String> params = fc.getExternalContext().getRequestParameterMap();
String par = params.get("pproveedor_id");
System.out.println("pro" + par);
proveedor = serdec.getProveedorById(Integer.parseInt(par));
newRecord = false;
System.out.println("va a salir");
return "editprov";
}
public void doGrabaProveedor(ActionEvent event){
System.out.println("gra"+proveedor.getNombre_comercial()+" new "+ newRecord);
Proveedor xpro = serdec.getProveedorByRuc(proveedor.getCedula_ruc());
if (xpro != null && !proveedor.getCedula_ruc().equals(ruc_proveedor_ori)){
System.out.println("Ya existe");
bProveedorExiste = xpro.getNombre_comercial();
//FacesContext.getCurrentInstance().validationFailed();
FacesMessage fmes = new FacesMessage("El Ruc "+proveedor.getCedula_ruc()+" ya se encuentra registrado para otro proveedor");
fc.addMessage(null, fmes);
//fc.addMessage("Proveedor ya existe", fmes);
//return "sucess";
return;
}
if (newRecord){
proveedor.setEstado("A");
//serdec.insProveedor(proveedor);
}
else {
//serdec.updProveedor(proveedor);
}
System.out.println("Si graba");
//return "sucess";
}
public void doEditProveedor2(ActionEvent event){
/*Map<String, String> params = fc.getExternalContext().getRequestParameterMap();
String par = params.get("pproveedor_id");
proveedor = serdec.getProveedorById(Integer.parseInt(par));
newRecord = false;
return "FProveedor";*/
String pproveedor_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("pproveedor_id");
proveedor = serdec.getProveedorById(Integer.parseInt(pproveedor_id));
newRecord = false;
System.out.println("si edit2 param "+ pproveedor_id + " new "+ newRecord);
System.out.println("si edit2 proveedor "+ proveedor.getNombre_comercial() + " new "+ newRecord);
}
private void log(Object object) {
String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
System.out.println("Bean " + methodName + ": " + object);
}
}
In this code, dropped the jquery dialog and show detail in div

you must either put <h:messages /> or <h:message /> at html page.
h:messages – Output all messages in current page.
h:message – Output a single message for a specific component.
1- in your case, try put <h:messages /> at the top page or inside the edit form.
2- or u can to put <h:message /> for each required input such as
<h:message for="txtnombre" style="color:red" /> after/before the input.

Related

Issue in Object creation concurrently in java web

I have developed maven web project using spring primefaces and run on jboss 5.0 server.
The Application is cloud based and multiple users can access concurrently.
My issue is when create objects concurrently sometimes refer previous object.this is ok with sequentially. But, when called same method in parallel it run as ambiguous way. Is it issue in primefaces?
depositController method:
#ManagedBean(name = "depositController")
#ViewScoped
public class DepositController {
public void depositAcc(ActionEvent actionEvent) {
try {
validate = true;
TrxnObj tempTrxnObj = trxnObj;
if (requiredFieldValidate()) {
this.mobileNoVerify();
if (validate) {
this.amountValidate();
}
} else {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("Please Enter the Required Fields");
context.addMessage("ad", message);
return;
}
if (!validate) {
return;
}
if (isRCP) {
if (null == userManager) {
userManager = (UserManager) SpringUtil.getApplicationContext().getBean("userManager");
}
merchant = userManager.getMerchantDetails(AppConstants.TRXN_CODE_WALLET_CASH_IN_WEB, merchantID);
if (null == commonManager) {
commonManager = (CommonManager) SpringUtil.getApplicationContext().getBean("commonManager");
}
//insert txn id
WSRequest request = new WSRequest();
request.setMerchantId(merchantID);
request.setMerchantOutletCode(merchantOutletCode);
request.setCustomerMobileNumber(tempTrxnObj.getMobileNo());
request.setMobileNumber(merchant.getMobileNumber());
request.setPinCode(merchant.getPinCode());
request.setTransactionAmount(tempTrxnObj.getAmount().doubleValue());
if(branchCode!=null && !branchCode.equals("")){
request.setUserName(userId+"-"+branchCode);
}else{
request.setUserName(userId);
}
if (tempTrxnObj.getNote() == null || tempTrxnObj.getNote().isEmpty()) {
request.setNote("Cash In at " + merchantID + " for " + tempTrxnObj.getMobileNo());
} else {
request.setNote(tempTrxnObj.getNote());
}
request.setMerchantTransactionId(getRCPTransactionRef());
CashInRequest cashInRequest = new CashInRequest();
cashInRequest.setWsRequest(request);
CashInResponse cashInResponse = commonManager.callCashInService(cashInRequest);
if (cashInResponse.getWsResponse().getResponseCode() == AppConstants.WS_TRXN_WEB_RES_SUCCESS) {
FacesContext.getCurrentInstance().addMessage("ad", new FacesMessage("Transaction Success: " + cashInResponse.getWsResponse().getResponse()));
receiptObj.setValues(this.trxnObj, locationShortCode, customerName);
recieptPrintEnabled = true;
receiptObj.setRefNumber(cashInResponse.getWsResponse().getReference());
receiptObj.setCusName(userControlObj.getMwtUserWalletDetails().getName());
receiptObj.setUtilityType("CASH IN");
receiptObj.setAccountNumber(userControlObj.getMwtUserWallet().getMobileNo());
receiptObj.setNote("Accepted payment for CASH IN.Thank You.");
reset();
} else {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("Transaction Failed");
context.addMessage("ad", message);
}
}
}catch(Exception e){
log.error(e,e)
}
}
DepositAcc.xhtml:
<p:messages id="msgs" for="ad" globalOnly="true"/>
<h:panelGrid columns="9" cellpadding="5" id="add_edit" styleClass="add-form">
<h:outputLabel for="mobileNo" value="*Confirm Mobile No:"/>
<p:inputText id="mobileNo" value="#{depositController.mobileNoCnfrm}" required="true" disabled="#{depositController.trxnObj.mobileNo == null}">
</p:inputText>
<p:message for="mobileNo" display="icon"/>
<h:outputLabel for="amount" value="*Deposit Amount:"/>
<p:inputText id="amount" value="#{depositController.trxnObj.amount}" onkeyup="$(this).val(addCommas($(this).val()))" required="true" disabled="#{depositController.trxnObj.mobileNo == null}">
<f:convertNumber maxFractionDigits="2"
groupingUsed="true"
pattern="#,##0.00"/>
</p:inputText>
<p:message for="amount" display="icon"/>
<h:outputLabel for="amountCnfrm" value="*Confirm Amount:"/>
<p:inputText id="amountCnfrm" value="#{depositController.amountCnfrm}" onkeyup="$(this).val(addCommas($(this).val()))" required="true" disabled="#{depositController.trxnObj.mobileNo == null}">
<f:convertNumber maxFractionDigits="2"
groupingUsed="true"
pattern="#,##0.00"/>
</p:inputText>
<p:message for="amountCnfrm" display="icon"/>
<h:outputLabel for="location" value="*Branch Location:" rendered="#{!depositController.isRCP}"/>
<p:inputText id="location" value="#{depositController.location}" required="true" disabled="true" style="width: 200px" rendered="#{!depositController.isRCP}">
</p:inputText>
<p:message for="location" display="icon" rendered="#{!depositController.isRCP}"/>
<h:outputLabel for="note" value="Note:"/>
<p:inputTextarea id="note" value="#{depositController.trxnObj.note}" disabled="#{depositController.trxnObj.mobileNo == null}"
rows="4" cols="20" counter="counter" maxlength="100"
counterTemplate="({0}/100)">
</p:inputTextarea>
<h:outputText id="counter"/>
<p:message for="note" display="icon"/>
</h:panelGrid>
<h:panelGrid columns="3" cellpadding="5" id="btns" styleClass="add-btn">
<p:commandButton value="Deposit" ajax="true" update=":add:addFields :add:btns :list :dialog" actionListener="#{depositController.depositAcc}"
disabled="#{!depositController.depositEnable}"/>
<p:commandButton value="Reset" update="addFields btns" process="#this"
disabled="#{!depositController.depositEnable}"
actionListener="#{depositController.reset}"/>
<p:commandButton value="View Receipt" onclick="dlg.show()"
disabled="#{!depositController.recieptPrintEnabled}"/>
</h:panelGrid>
</p:fieldset>
</h:form>

PrimeFaces 6.0 - InputText Ajax event + CommandButton Event Yields NULL Bean Fields

I want to trigger a method when a text field is blurred, and so I added an Ajax onblur event to this text field, and it works.
The problem I am having is with the commandButton that submits a bean with NULL fields.
When I get rid of the inputText Ajax event, the form submission works as usual.
The .xhtml file:
`
<h:head>
<title>Saisie Cotisations</title>
</h:head>
<h:body>
<h3>Saisie Cotisation</h3>
<h:form id="formulaire">
<h:panelGroup>
<p:panelGrid columns="2" id="panelMenage" >
<p:outputLabel value="N° Appartement" for="appart" />
<p:inputNumber id="appart" value="#{saisieBean.menage.numAppart}" decimalPlaces="0" emptyValue="empty" size="3" thousandSeparator="" >
<p:ajax event="blur" listener="#{saisieBean.chargerMenage}" update="panelMenage panelCotisation" />
</p:inputNumber>
<p:outputLabel value="Nom" for="nom" />
<p:inputText id="nom" value="#{saisieBean.menage.nom}" disabled="#{saisieBean.lectureSeule}" >
</p:inputText>
<p:outputLabel value="Prenom" for="prenom" />
<p:inputText id="prenom" value="#{saisieBean.menage.prenom}" disabled="#{saisieBean.lectureSeule}" >
</p:inputText>
<p:outputLabel value="Adresse E-Mail" for="email" />
<p:inputText id="email" value="#{saisieBean.menage.email}" disabled="#{saisieBean.lectureSeule}" >
</p:inputText>
</p:panelGrid>
</h:panelGroup>
<br />
<h:panelGroup>
<p:panelGrid columns="2" id="panelCotisation" >
<p:outputLabel value="Type Cotisation" />
<p:selectOneMenu value="#{saisieBean.menage.cotisation.id}" disabled="#{saisieBean.lectureSeule}" >
<f:selectItems value="#{saisieBean.typesCotisation}" var="tc" itemValue="#{tc.id}" itemLabel="#{tc.intitule}" />
</p:selectOneMenu>
<p:outputLabel value="Mois" />
<p:selectOneMenu value="#{saisieBean.mois}" disabled="#{saisieBean.lectureSeule}" >
<f:selectItems value="#{saisieBean.listeMois}" />
</p:selectOneMenu>
<p:outputLabel value="Annee" />
<p:inputNumber value="#{saisieBean.menage.cotisation.annee}" decimalPlaces="0" thousandSeparator="" disabled="#{saisieBean.lectureSeule}" />
<p:outputLabel value="Montant" />
<p:inputNumber value="#{saisieBean.menage.cotisation.montant}" decimalPlaces="2" disabled="#{saisieBean.lectureSeule}" />
</p:panelGrid>
</h:panelGroup>
<br />
<p:commandButton value="Soumettre" actionListener="#{saisieBean.exec}" process="#form" update="#form" immediate="false" ></p:commandButton>
</h:form>
</h:body>
`
The Bean:
package ma.syndic.bean;
import java.io.Serializable;
import java.text.DateFormatSymbols;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.view.ViewScoped;
import ma.syndic.back.bean.Cotisation;
import ma.syndic.back.bean.Menage;
import ma.syndic.back.bean.TypeCotisation;
import ma.syndic.back.dao.bean.MenageDAO;
import ma.syndic.back.dao.bean.TypeCotisationDAO;
import org.joda.time.DateTime;
/**
*
* #author Mohamed ENNAHDI EL IDRISSI
* #date 13/11/2016
*/
#ManagedBean
#ViewScoped
public class SaisieBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5492998931983521852L;
private Menage menage;
private Cotisation cotisation;
private List<TypeCotisation> typesCotisation;
private String[] listeMois;
private String mois;
private boolean lectureSeule = true;
public SaisieBean() {
// TODO Auto-generated constructor stub
}
#PostConstruct
public void init() {
this.menage = new Menage();
this.cotisation = new Cotisation();
try {
this.typesCotisation = new TypeCotisationDAO().findAll();
} catch (Exception e) {
e.printStackTrace();
}
this.listeMois = new DateFormatSymbols().getMonths();
int i = new DateTime().monthOfYear().get();
this.mois = this.listeMois[ i - 1 ];
this.menage.getCotisation().setAnnee(new DateTime().year().get());
}
public void exec() {
System.out.println("Exec fired");
System.out.println("EMail: " + this.menage.getEmail());
}
public void chargerMenage() {
System.out.println("chargerMenage fired");
if (this.menage.getNumAppart() != null) {
this.lectureSeule = false;
try {
Menage m = new MenageDAO().find(this.menage);
if (m != null) {
this.menage = m;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public Menage getMenage() {
return menage;
}
public void setMenage(Menage menage) {
this.menage = menage;
}
public Cotisation getCotisation() {
return cotisation;
}
public void setCotisation(Cotisation cotisation) {
this.cotisation = cotisation;
}
public List<TypeCotisation> getTypesCotisation() {
return typesCotisation;
}
public void setTypesCotisation(List<TypeCotisation> typesCotisation) {
this.typesCotisation = typesCotisation;
}
public String[] getListeMois() {
return listeMois;
}
public void setListeMois(String[] listeMois) {
this.listeMois = listeMois;
}
public String getMois() {
return mois;
}
public void setMois(String mois) {
this.mois = mois;
}
public boolean isLectureSeule() {
return lectureSeule;
}
public void setLectureSeule(boolean lectureSeule) {
this.lectureSeule = lectureSeule;
}
}

Primefaces datatable duplicates data on deletion

im using hibernate 4, spring 4, lucene 3, primefaces 5, java 7.
I got a data table, which data is populated on the baking bean, the idea with the table is that it shows me some uncategorized words, and lets me categorizate them.
an example of the initial table looks normal for example
1 2 3 4 5
here is my page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:form id="form">
<p:growl id="msgs" showDetail="true" life="2000" />
<p:dataTable id="words" var="word"
value="#{wordCatalogatorController.unknownWords}" editable="true"
style="margin-bottom:20px">
<f:facet name="header">Row Editing</f:facet>
<p:ajax event="rowEdit"
listener="#{wordCatalogatorController.onRowEdit}" update=":form:msgs" />
<p:ajax event="rowEditCancel"
listener="#{wordCatalogatorController.onRowCancel}" update=":form:msgs" />
<p:column headerText="Palabra">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{word.word}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{word.word}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Tipo Palabra">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{word.wordType}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{word.wordType}" style="width:100%"
converter="#{wordTypeConverter}">
<f:selectItems value="#{wordCatalogatorController.wordTypes}"
var="man" itemLabel="#{man.wordType}" itemValue="#{man}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
</html>
the bean for this is:
#Controller
#Transactional
public class WordCatalogatorController {
private List<Word> unknownWords = new ArrayList<Word>();
private List<WordType> wordTypes = new ArrayList<WordType>();
public WordCatalogatorController(){
//inicializamos palabras desconocidas y tipos de palabras!
for(int i = 0 ; i < 6 ; i++){
unknownWords.add(new Word("" + i));
}
for(int i = 0 ; i < 4 ; i++){
wordTypes.add(new WordType("" + i));
}
}
public void onRowEdit(RowEditEvent event) {
Word currentWord = (Word) event.getObject();
unknownWords.remove(currentWord);
}
public void onRowCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Edit Cancelled",
((Word) event.getObject()).getWord());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if (newValue != null && !newValue.equals(oldValue)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
"Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
then after editing and saving the first row (1) the datatables updates with 1 2 2 3 4 5
Any ideas will be really apreciated!
here comes the code for pojo clases
#Entity
#Table(name="Word")
#Indexed
#AnalyzerDef(name = "searchtokenanalyzer",tokenizer = #TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
#TokenFilterDef(factory = StandardFilterFactory.class),
#TokenFilterDef(factory = LowerCaseFilterFactory.class),
#TokenFilterDef(factory = StopFilterFactory.class,params = {
#Parameter(name = "ignoreCase", value = "true") }) })
#Analyzer(definition = "searchtokenanalyzer")
public class Word {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private long wordId;
#Column(name="word")
#Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
#Analyzer(definition="searchtokenanalyzer")
private String word;
#ManyToMany(mappedBy="words")
private Collection<Danger> dangers = new ArrayList<Danger>();
#ManyToMany(mappedBy="words")
private Collection<Risk> risks = new ArrayList<Risk>();
#ManyToMany(mappedBy="words")
private Collection<Control> controls = new ArrayList<Control>();
#ManyToOne
#JoinColumn(name = "wordTypeId")
private WordType wordType;
public Word(String word, WordType wordType) {
super();
this.word = word;
this.wordType = wordType;
}
public Word(String word) {
super();
this.word = word;
}
#Override
public boolean equals(Object obj) {
if(obj instanceof Word){
return ((Word)obj).getWord().equalsIgnoreCase(this.getWord());
}else{
return false;
}
}
public Word() {
super();
}
public long getWordId() {
return wordId;
}
public void setWordId(long wordId) {
this.wordId = wordId;
}
#Entity
#Table(name = "WordType")
#Indexed
public class WordType {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long wordTypeId;
#Column(name = "wordType")
#Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
#Analyzer(definition = "searchtokenanalyzer")
private String wordType;
#Column(name = "description")
private String description;
#OneToMany(mappedBy = "wordType")
private Set<Word> words;
#Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (!(obj instanceof WordType)) {
return false;
} else {
WordType extenalWT = (WordType) obj;
if (this.wordType.equalsIgnoreCase(extenalWT.getWordType())
&& this.wordTypeId == extenalWT.getWordTypeId()) {
return true;
} else {
return false;
}
}
}
public WordType() {
}
public WordType(String wordType) {
this.wordType = wordType;
}
public long getWordTypeId() {
return wordTypeId;
}
public void setWordTypeId(long wordTypeId) {
this.wordTypeId = wordTypeId;
}
public String getWordType() {
return wordType;
}
public void setWordType(String wordType) {
this.wordType = wordType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<Word> getWords() {
return words;
}
public void setWords(Set<Word> words) {
this.words = words;
}
#Override
public String toString() {
return wordType;
}
}
For anyone else having this issue:
It seems to be an issue between the rowEditor and the table sorting. Having the correct update target on the ajax tag isn't an issue as the row is technically removed but the display gets messed up. You can get around this with just a touch of nastiness. You can force a filter during oncomplete for the ajax tag. This will get rid of the ghost duplicate record.
<p:ajax event="rowEdit"
listener="#{beanName.onRowEdit}"
update=":growl :messages :formName:tableId"
oncomplete="PF('tableWidgetVar').filter();" />
Finally the best solution was to implement the select event for the data table, and in the event have a dialog to pick the option, then refresh the table, this is the final xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="myForm">
<p:growl id="msgs" showDetail="true" life="2000" />
<p:panel header="Sale Item" style="width: 400px;">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel value="Texto" for="acSimple" />
<p:autoComplete id="acSimple"
value="#{wordCatalogatorController.texto}"
completeMethod="#{wordCatalogatorController.completeText}"
binding="#{wordCatalogatorController.autoCompleteText}" />
<p:commandButton value="Guardar actividad" id="save"
update=":myForm:msgs words"
binding="#{wordCatalogatorController.saveButton}"
actionListener="#{wordCatalogatorController.saveActivity}"
styleClass="ui-priority-primary" process="#this" />
</h:panelGrid>
<p:dataTable id="words" widgetVar="words" var="word"
value="#{wordCatalogatorController.unknownWords}" editable="true"
style="margin-bottom:20px" rowKey="#{word.word}"
selection="#{wordCatalogatorController.selectedWord}"
selectionMode="single" editMode="row">
<p:ajax event="rowSelect"
listener="#{wordCatalogatorController.changeClient}"
oncomplete="PF('activityDialog').show()"
update=":myForm:activityDialog" />
<f:facet name="header">Edicion de palabras</f:facet>
<p:column headerText="Palabra">
<h:outputText value="#{word.word}" />
</p:column>
<p:column headerText="Edicion">
<h:outputText value="Presione para catalogar la palabra" />
</p:column>
</p:dataTable>
</p:panel>
<p:dialog id="activityDialog" width="500px" height="600px"
header="Palabra a catalogar: #{wordCatalogatorController.selectedWord.word}"
widgetVar="activityDialog" modal="true" closable="false">
<h:panelGrid columns="2" cellpadding="5">
<p:selectOneMenu id="wordTypes"
value="#{wordCatalogatorController.selectedWordType}"
style="width: 150px;" converter="#{wordTypeConverter}">
<p:ajax
listener="#{wordCatalogatorController.wordTypeChangeListener}"
update=":myForm:words" />
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{wordCatalogatorController.wordTypes}" />
</p:selectOneMenu>
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
</html>

update dataTable depending on the value chosen in selectOneMenu

I'm using a selectOneMenu and i want to update datatable depending on what i choose on the combobox, i have two tables on the database:
Fournisseur
idFournisseur
raisonSociale
telephone..
and
Devis
idDevis
idFournisseur
devis.xhtml
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
<p:outputLabel for="console" value="Basic:" />
<p:selectOneMenu id="console" value="#{fournisseurBean.raisonSociale}">
<f:selectItems value="#{fournisseurBean.listeFournisseurs}" var="fournisseur" itemValue="#{fournisseur}" itemLabel="#{fournisseur.raisonSociale}" />
<p:ajax event="change" update="display" listener="#{fournisseurBean.getFournisseurByRaison()}" />
</p:selectOneMenu>
<p:dataTable id="display" var="listeDevis" value="#{devisBean.listeDevis}" editable="true" style="margin-bottom:10px">
<f:facet name="header">
Liste des devis
</f:facet>
<p:ajax event="rowEdit" listener="#{dtEditView.onRowEdit}" update=":form:msgs" />
<p:ajax event="rowEditCancel" listener="#{dtEditView.onRowCancel}" update=":form:msgs" />
<p:column headerText="Id devis">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeDevis.idDevis}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{listeDevis.idDevis}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Date devis">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{listeDevis.dateDevis}" /></f:facet>
<f:facet name="input"><p:inputText value="#{listeDevis.dateDevis}" style="width:100%" label="Year"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px" headerText="Modification">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
FournisseurBean.xhtml
package controller;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.event.ValueChangeEvent;
import model.services.FournisseurMetier;
import net.vo.Fournisseur;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
#Component
#Scope("view")
public class FournisseurBean {
#Autowired
private FournisseurMetier fournisseurMetier;
private List<Fournisseur> listeFournisseurs;
private List<String> listeRaisons;
private int idFournisseur;
private String raisonSociale;
private String rib;
private String adresse;
private Long telephone;
#PostConstruct
public void init() {
listeFournisseurs = fournisseurMetier.getAllFournisseurs();
listeRaisons = fournisseurMetier.getAllRaisonsSociales();
}
public List<Fournisseur> getListeFournisseurs() {
return listeFournisseurs;
}
public void insert()
{
Fournisseur fournisseur = new Fournisseur();
fournisseur.setIdFournisseur(getIdFournisseur());
fournisseur.setRaisonSociale(getRaisonSociale());
fournisseur.setRib(getRib());
fournisseur.setAdresse(getAdresse());
fournisseur.setTelephone(getTelephone());
fournisseurMetier.insert(fournisseur);
}
public void update()
{
Fournisseur fournisseuur = fournisseurMetier.getFournisseur(this.idFournisseur);
fournisseuur.setRaisonSociale(getRaisonSociale());
fournisseuur.setRib(getRib());
fournisseuur.setAdresse(getAdresse());
fournisseuur.setTelephone(getTelephone());
fournisseurMetier.update(fournisseuur);
}
public FournisseurMetier getFournisseurMetier() {
return fournisseurMetier;
}
public void setFournisseurMetier(FournisseurMetier fournisseurMetier) {
this.fournisseurMetier = fournisseurMetier;
}
public void setListeFournisseurs(List<Fournisseur> listeFournisseurs) {
this.listeFournisseurs = listeFournisseurs;
}
public int getIdFournisseur() {
return idFournisseur;
}
public void setIdFournisseur(int idFournisseur) {
this.idFournisseur = idFournisseur;
}
public String getRaisonSociale() {
return raisonSociale;
}
public void setRaisonSociale(String raisonSociale) {
this.raisonSociale = raisonSociale;
}
public String getRib() {
return rib;
}
public void setRib(String rib) {
this.rib = rib;
}
public Long getTelephone() {
return telephone;
}
public void setTelephone(Long telephone) {
this.telephone = telephone;
}
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
#Override
public String toString() {
return "FournisseurBean{" + "raisonSociale=" + raisonSociale + '}';
}
public void getFournisseurByRaison()
{
System.out.println(raisonSociale);
}
}
This method getFournisseurByRaison() shows me a reference to object Fournisseur not the attribute raisonSociale.
You can sue p:ajax as you mentioned in comments.
OR
Since you are using Primefaces you can also Update any component from ManagedBean itself using org.primefaces.context.RequestContext object.
For example:
Facelet:
<h:form id="form1">
<p:dataTable id="myTab">
...
</p:dataTable>
</h:form>
ManagedBean:
RequestContext reqCtx = Requestcontext.getCurrentInstance();
req.Ctx.update("form1:myTab");
this method getFournisseurByRaison() shows me a reference to object Fournisseur not the attribure raisonSociale
This is because you're setting the object as the value:
<!-- itemValue="#{fournisseur}" <= here is the object set as value -->
<f:selectItems value="#{fournisseurBean.listeFournisseurs}"
var="fournisseur"
itemValue="#{fournisseur}"
itemLabel="#{fournisseur.raisonSociale}" />
You should use an identifier or another field to be able to seek the selected fournisseur from the values of the list. This may be a starting approach:
<!-- itemValue="#{fournisseur.id}" <= or another unique identifier field -->
<f:selectItems value="#{fournisseurBean.listeFournisseurs}"
var="fournisseur"
itemValue="#{fournisseur.id}"
itemLabel="#{fournisseur.raisonSociale}" />
Then, in your bean:
public void getFournisseurByRaison() {
System.out.println(raisonSociale); //will print the user selected id or unique identifier
//access to devisBean and update the data in `devisBean.listeDevis` in there
}

PropertyNotFoundException for filter in Richfaces datatable

I am trying to add filtering to a rich:datatable but am having problems with the PropertyNotFoundException - using an example from the showcase (Richfaces 4) I have the following
<f:facet name="noData">
Nothing found
</f:facet>
<rich:column filter="#{mailerBean.firstNameFilterImpl}">
<f:facet name="header">
<h:outputText value="First Name" />
<h:inputText value="#{mailerBean.firstNameFilter}" id="input">
<a4j:ajax event="blur" render="dataTable" execute="#this" />
</h:inputText>
</f:facet>
<h:outputText value="#{person.firstName}" />
</rich:column>
The Bean contains
#ManagedBean
#SessionScoped
public class MailerBean implements Serializable {
............
public String getFirstNameFilter() {
return firstNameFilter;
}
public void setFirstNameFilter(String firstNameFilter) {
this.firstNameFilter = firstNameFilter;
}
public Filter<?> getFirstNameFilterImpl() {
return new Filter<Person>() {
public boolean accept(Person t) {
String firstName = getFirstNameFilter();
if (firstName == null || firstName.length() == 0 ||
firstName.toLowerCase().contains(t.getFirstName().toLowerCase())) {
return true;
}
return false;
}
};
The error I get is
javax.el.PropertyNotFoundException: /mailinglistpage.xhtml #66,67
filter="#{mailerBean.firstNameFilterImpl}": Property
'firstNameFilterImpl' not found on type
com.patcomsys.zuzz.mailer.web.MailerBean
The method is in the bean and it does return a Filter object - can you see anything wrong?
Thanks

Resources