i am not able to get input text value in my bean
I have setted coverage bean as a session bean in my work flow but when i try to get value from input text it returns null
This id is in a pannel and that contains form with return false
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:form id="form2" >
<div class="contract-menubar-internal-9x90 coverage-prod-mid-panel">
<div class="cvrg-row-div-dimension">
<p:panel id="cvrg_panel">
<h:outputLabel value="Type : " styleClass="cvrg-labels" />
<p:selectOneMenu value="" styleClass="cvrg-inputs">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItem itemLabel="ELW" itemValue="1" />
<f:selectItem itemLabel="Maintenance" itemValue="2" />
<f:selectItem itemLabel="WT" itemValue="3" />
</p:selectOneMenu>
<h:outputLabel value="Damage Code : " styleClass="cvrg-labels" />
<p:inputText styleClass="cvrg-inputs">
</p:inputText>
<h:outputLabel value="Baumuster : " styleClass="cvrg-labels" />
<p:selectOneMenu value="" styleClass="cvrg-inputs">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItem itemLabel="207" itemValue="1" />
<f:selectItem itemLabel="221" itemValue="2" />
</p:selectOneMenu>
<h:outputLabel value="Class : "
styleClass="cvrg-labels cvrg-class-srch-label" />
<p:selectOneMenu value="" styleClass="cvrg-inputs">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItem itemLabel="S" itemValue="1" />
<f:selectItem itemLabel="C" itemValue="2" />
</p:selectOneMenu>
</p:panel>
<p:panel>
<div class="srch-cvrg-btn">
<p:commandButton value="Search" />
</div>
<div class="reset-cvrg-btn">
<p:commandButton value="Reset" id="reset_cvrg" update="cvrg_panel"
process="#this">
<p:resetInput target="cvrg_panel"></p:resetInput>
</p:commandButton>
</div>
</p:panel>
</div>
<p:commandButton value= "Save" styleClass="add-coverage-btn" action="#{coverageFlowManager.add}" ajax="false" > </p:commandButton>
<p:commandButton value="Add Coverage" styleClass="add-coverage-btn"
onclick="addCoverage()" />
<p:commandButton value="Save" styleClass="save-coverage-btn"
id="saveCoverage" action="#{productModel.saveCoverage}"
immediate="true" partialSubmit="true" />
<p:commandButton value="Cancel" styleClass="cancel-coverage-btn"
onclick="cancelCoverage()" />
<p:inputText id="type_inp1" value="#{coverageBean.type}" />
</div>
/**
*
*/
package com.daimler.contract.flow;
import java.util.*;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlInputText;
import org.springframework.security.core.context.SecurityContextHolder;
import com.daimler.contract.bean.CoverageBean;
import com.daimler.contract.bean.ProductBean;
import com.daimler.contract.entity.CoverageEntity;
import com.daimler.contract.entity.ProductEntity;
import com.daimler.contract.model.ProductModel;
import com.daimler.contract.service.CoverageService;
import com.daimler.contract.service.ProductService;
import com.mbcl.common.bean.User;
/**
* #author Jyoti
*
*/
public class CoverageFlowManager {
private CoverageService coverageService;
private ProductModel productModel;
private CoverageBean coverageBean;
HtmlInputText type;
public HtmlInputText getType() {
return type;
}
public void setType(HtmlInputText type) {
this.type = type;
}
public void setCoverageBean(CoverageBean coverageBean) {
this.coverageBean = coverageBean;
}
public static final String query = "select * from COVERAGE_MGT";
/**
* #return the coverageService
*/
public CoverageService getCoverageService() {
return coverageService;
}
/**
* #param coverageService the coverageService to set
*/
public void setCoverageService(CoverageService coverageService) {
this.coverageService = coverageService;
}
/**
* #return the productModel
*/
public ProductModel getProductModel() {
return productModel;
}
/**
* #param productModel the productModel to set
*/
public void setProductModel(ProductModel productModel) {
this.productModel = productModel;
}
public void showCMDataTable() {
String countryCode = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
.getCountryCode();
System.out.println("jyoti THROUGH DIFF");
List<CoverageEntity> cmDataTableEntity = coverageService.getCMDataTable(countryCode, query);
productModel.setCoverageEntityList(cmDataTableEntity);
//System.out.println("set in model"+pmDataModel.getPmList());
}
public String add()
{
System.out.println("Gaurav");
System.out.println(coverageBean.getType());
System.out.println(productModel.getCoverageEntityList().get(0).getId());
System.out.println(getType().getValue());
// productModel.getCoverageEntityList().add(productModel.getNewCoverage());
return null;
}
}
In your XHTML
<p:inputText id="type_inp1" value="#{coverageBean.type}" />
is mapped to
HtmlInputText type;
This is wrong. The value should map to variable of type String.
Changes:
private String type;
public String getType() {
return type;
}
public void setType(Stringtype) {
this.type = type;
}
Make above changes and try and it should work.
FYI - Use HtmlInputText for binding only. But you DO NOT need to Bind here.
Related
Hope you could help me
I am learning JSF and Primesface on my own.
I having trouble implementing the following JSF form, and make it work as I require it
Basically
I need to have one Form, and need to execute AJAX whenever a value change in the Form.
I am not able to make that Once Single Ajax call call for entrie form.
Rather I have to call it for every Data Input I have to call.
Second the Date Picker does not work or loses it formatting after selecting date.
Note I have not any additional Java Script... to the JSF.
Please refer additional image that I have attached
Further is that Possible to provide Single Ajax in case any inputs changes in the FORM, instead of each inputs tags.
What is difference between f:ajax and p:ajax
JSF 2.3 Dynamic Web Module 4.0 Redhat JBOSS 7.2 Java 1.8 Primefaces
7.0
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:form styleClass="fill" id="tinputForm">
<div style="color: #FFF; padding-left: 70px"><strong >INPUT PANEL</strong></div>
<hr/>
<h:panelGroup layout="block" styleClass="CustomWell" >
<h:outputLabel value="Server-Class"/>
<h:panelGroup layout="block" styleClass="radio">
<h:selectOneRadio value = "#{sideBarInputsBean.serverClass}" layout="pageDirection" >
<f:selectItem itemValue = "Gateway" itemLabel = "Gateway" />
<f:selectItem itemValue = "Facing Server" itemLabel = "Facing Server" />
<f:selectItem itemValue = "Server Facing" itemLabel = "Server Facing" />
<f:selectItem itemValue = "Central Server" itemLabel = "Central Server" />
<!-- <p:ajax listener="#{sideBarInputsBean.printSelectedCRadioButton()}" /> -->
<f:ajax event="click" listener="#{sideBarInputsBean.printSelectedCRadioButton()}" execute="#form" render="#form :tinputForm" />
</h:selectOneRadio>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup layout="block" styleClass="CustomWell" >
<h:outputLabel value="Choose a Parameter:"/>
<h:panelGroup layout="block" styleClass="radio">
<h:selectOneRadio value = "#{sideBarInputsBean.parameter}" layout="pageDirection" >
<f:selectItem itemValue = "IISLOG" itemLabel = "IIS Log Counter" />
<f:selectItem itemValue = "ASPNET" itemLabel = "ASP DOT Net Counters" />
</h:selectOneRadio>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup layout="block" styleClass="CustomWell" >
<h:outputLabel value="Select a Server:"/>
<h:panelGroup rendered="#{sideBarInputsBean.serverClass == 'Gateway'}">
<h:panelGroup layout="block" >
<h:selectOneMenu id="CLGWServer" value="#{sideBarInputsBean.serverName}" styleClass="mymenu">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{dataForSideBarInputBean.clientGatewayList}" />
<f:ajax event="change" listener="#{sideBarInputsBean.printSelectedCRadioButton()}" execute="#form" render="#form :tinputForm" />
</h:selectOneMenu>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup rendered="#{sideBarInputsBean.serverClass == 'Facing Server'}">
<h:panelGroup layout="block" >
<h:selectOneMenu id="CFASServer" value="#{sideBarInputsBean.serverName}" styleClass="mymenu">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{dataForSideBarInputBean.clientFacingList}" />
<f:ajax event="change" listener="#{sideBarInputsBean.printSelectedCRadioButton()}" execute="#form" render="#form :tinputForm" />
</h:selectOneMenu>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup layout="block" styleClass="CustomWell" >
<h:panelGroup layout="block" styleClass="datepick">
<p:outputLabel value="Date:" />
<p:datePicker id="DateSelector" value="#{sideBarInputsBean.selectedDate}" showIcon="true" showTime="true" pattern="dd.MM.yyyy">
<f:ajax event="dateSelect" listener="#{sideBarInputsBean.printSelectedCRadioButton()}" execute="#form" render="#form :tinputForm" />
</p:datePicker>
</h:panelGroup>
</h:panelGroup>
</h:form>
Bean Code.
package cdv.mrdataanalytics.bean;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Named;
#Named("sideBarInputsBean")
#SessionScoped
public class SideBarInputsBean implements Serializable {
private static final long serialVersionUID = 1L;
private String serverClass="Gateway";
private String parameter="IISLOG";
private String serverName="";
private Date selectedDate;
public String getServerClass() {
return this.serverClass;
}
public void setServerClass(String strClass) {
this.serverClass = strClass;
}
public String getParameter() {
return this.parameter;
}
public void setParameter(String strClass) {
this.parameter = strClass;
}
public String getServerName() {
return this.serverName;
}
public void setServerName(String strClass) {
this.serverName = strClass;
}
public Date getSelectedDate() {
return this.selectedDate;
}
public void setSelectedDate(Date date7) {
this.selectedDate = date7;
}
public void printSelectedCRadioButton() throws IOException{
System.out.println("Selected value = "+this.getServerClass());
System.out.println("Parameter value = "+this.getParameter());
System.out.println("ServerName = "+this.getServerName());
System.out.println("SelectedDate = "+this.getSelectedDate());
//ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
//ec.redirect(ec.getRequestContextPath() + "/next.xhtml?action=add");
}
}
This question already has answers here:
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
(5 answers)
Closed 6 years ago.
I have an selectOneMenu and when Its value at 0, I want to "Add" button does not show up. I have rendered for this situation. Here is code ;
<p:panelGrid id="pnlRegister" columns="6" style="width: 95%" >
<p:inputText id="name" class=" width100" value="#{register.name}" />
<p:selectOneMenu id="numberOfChild" value="#{register.numberOfChild}" >
<p:ajax listener="#{register.listenNumberOfChild()}" update="pnlRegister" />
<f:selectItem itemValue="0" itemLabel="0" />
<f:selectItem itemValue="1" itemLabel="1" />
<f:selectItem itemValue="2" itemLabel="2" />
<f:selectItem itemValue="3" itemLabel="3" />
<f:selectItem itemValue="4" itemLabel="4" />
<f:selectItem itemValue="5" itemLabel="5" />
</p:selectOneMenu>
<p:commandButton id="addPerson" value="Add" actionListener="#{register.openPersonDialog(1)}" rendered="#{register.visibleAddPersonButton}" >
<p:ajax event="dialogReturn" update="pnlPerson" />
</p:commandButton>
And Bean code;
public void listenNumberOfChild() {
if (numberOfChild == 0) {
visibleAddPersonButton = false;
} else {
visibleAddPersonButton = true;
}
System.out.println("ListenerNumberOfChild " + numberOfChild);
}
</panelGrid>
Now problem is, when I change numberOfChild, listener works uptades pnlRegister as expected. However server does not keep inputText values. For example before listener works, I write register.name as "John". After listener works, it does not keep it and it gets as null. I hope I could tell what I'm trying and what is problem. So do you have any suggestion ? Also I tried RequestContext.getCurrentInstance().update but same problem occured.
This is how I made it work:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:head>
<title>pfaces</title>
</h:head>
<h:form>
<p:panelGrid id="pnlRegister" columns="3" style="width: 95%">
<p:inputText id="name" value="#{register.name}"/>
<p:selectOneMenu id="numberOfChild" value="#{register.numberOfChild}">
<p:ajax process="name numberOfChild"
listener="#{register.listenNumberOfChild()}" update="pnlRegister"/>
<f:selectItem itemValue="0" itemLabel="0"/>
<f:selectItem itemValue="1" itemLabel="1"/>
<f:selectItem itemValue="2" itemLabel="2"/>
</p:selectOneMenu>
<p:commandButton id="addPerson" value="Add"
rendered="#{register.visibleAddPersonButton}"/>
</p:panelGrid>
</h:form>
<h:body>
</h:body>
</f:view>
</html>
and the backing bean:
package biz.tugay.jsfexampla;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class Register {
private boolean visibleAddPersonButton = false;
private int numberOfChild = 0;
private String name;
public boolean isVisibleAddPersonButton() {
return visibleAddPersonButton;
}
public void setVisibleAddPersonButton(boolean visibleAddPersonButton) {
this.visibleAddPersonButton = visibleAddPersonButton;
}
public int getNumberOfChild() {
return numberOfChild;
}
public void setNumberOfChild(int numberOfChild) {
this.numberOfChild = numberOfChild;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void listenNumberOfChild() {
visibleAddPersonButton = numberOfChild != 0;
System.out.println("ListenerNumberOfChild " + numberOfChild);
}
}
Here, you can see it in action: https://youtu.be/IQN3HAejhcM
hello everyone I'm trying to build a webpage with two oneMenu the second one depending on the second one. My XHTML file is below as well as my bean.
when I try to create a new "structureAttache" I have the following problem
TemplateStructureAttache.xhtml #40,139 value="#{structureBean.structureAttache.intituleStructure}": Target Unreachable, 'structureAttache' returned null
and when I use the method initStruc to create a new structureAttache then I call it in the listener of my first ajax, I succeed to create a structureAttache but when I do it for the second time, it seems like the value already exit in the DB and it refuses please help me to solve this issue
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dresen.dresen.Beans;
import com.dresen.dresen.ServiceInterface.IArrondissementService;
import com.dresen.dresen.ServiceInterface.IStructureService;
import com.dresen.dresen.entities.Arrondissement;
import com.dresen.dresen.entities.StructureAttache;
import com.dresen.dresen.entities.CategorieStructure;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import com.dresen.dresen.ServiceInterface.ICategorieStructureService;
import com.dresen.dresen.ServiceInterface.IDepartementService;
import com.dresen.dresen.entities.Departement;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
/**
*
* #author Vivien Saa
*/
#ManagedBean
#ViewScoped
public class StructureBean implements Serializable{
#ManagedProperty(value = "#{IStructureService}")
private IStructureService iStructureService;
#ManagedProperty(value = "#{IArrondissementService}")
private IArrondissementService iArrondissementService;
#ManagedProperty(value = "#{ICategorieStructureService}")
private ICategorieStructureService iCategorieStructureService;
#ManagedProperty(value ="#{IDepartementService}")
private IDepartementService iDepartementService;
private long idDepartement;
private long idArrondissement;
private long idCategorieStructure;
private StructureAttache structureAttache;
private List<Arrondissement> listArrondissement;
private List<Departement> listDepartement;
private List<CategorieStructure> listCategorieStructure;
private Arrondissement arrondissement = new Arrondissement();
private CategorieStructure CategorieStructure = new CategorieStructure();
public StructureBean() {
structureAttache = new StructureAttache();
idDepartement = 0L;
idArrondissement = 0L;
idCategorieStructure = 0L;
}
public ICategorieStructureService getiCategorieStructureService() {
return iCategorieStructureService;
}
public void setiCategorieStructureService(ICategorieStructureService iCategorieStructureService) {
this.iCategorieStructureService = iCategorieStructureService;
}
public long getIdDepartement() {
return idDepartement;
}
public void setIdDepartement(long idDepartement) {
this.idDepartement = idDepartement;
}
public IDepartementService getiDepartementService() {
return iDepartementService;
}
public void setiDepartementService(IDepartementService iDepartementService) {
this.iDepartementService = iDepartementService;
}
public List<Departement> getListDepartement() {
return iDepartementService.findAllDepartement();
}
public void setListDepartement(List<Departement> listDepartement) {
this.listDepartement = listDepartement;
}
public long getIdCategorieStructure() {
return idCategorieStructure;
}
public void setIdCategorieStructure(long idCategorieStructure) {
this.idCategorieStructure = idCategorieStructure;
}
public List<CategorieStructure> getListCategorieStructure() {
return iCategorieStructureService.findAllCategorieStructure();
}
public void setListCategorieStructure(List<CategorieStructure> listCategorieStructure) {
this.listCategorieStructure = listCategorieStructure;
}
public IStructureService getiStructureService() {
return iStructureService;
}
public void setiStructureService(IStructureService iStructureService) {
this.iStructureService = iStructureService;
}
public IArrondissementService getiArrondissementService() {
return iArrondissementService;
}
public void setiArrondissementService(IArrondissementService iArrondissementService) {
this.iArrondissementService = iArrondissementService;
}
public long getIdArrondissement() {
return idArrondissement;
}
public void setIdArrondissement(long idArrondissement) {
this.idArrondissement = idArrondissement;
}
public StructureAttache getStructureAttache() {
return structureAttache;
}
public void setStructureAttache(StructureAttache structureAttache) {
this.structureAttache = structureAttache;
}
public List<Arrondissement> getListArrondissement() {
return iArrondissementService.findArrondissementByIdDepart(idDepartement);
}
public void setListArrondissement(List<Arrondissement> listArrondissement) {
this.listArrondissement = listArrondissement;
}
public Arrondissement getArrondissement() {
return arrondissement;
}
public void setArrondissement(Arrondissement arrondissement) {
this.arrondissement = arrondissement;
}
public CategorieStructure getCategorieStructure() {
return CategorieStructure;
}
public void setCategorieStructure(CategorieStructure CategorieStructure) {
this.CategorieStructure = CategorieStructure;
}
public void initStruc() {
structureAttache = new StructureAttache();
}
public StructureAttache createStructure(){
System.out.println("vvsssssssssvsssssssssssssssssssssssvv why don't you work");
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.createStructureAttache(structureAttache);
}
public StructureAttache findStructureById(){
return iStructureService.findStructureAttacheById(structureAttache.getId());
}
public StructureAttache updateStructure(){
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.updateStructureAttache(structureAttache);
}
public List<StructureAttache> findAllStructure(){
return iStructureService.findAllStructureAttache();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Application de gestion du personnel des services déconcentrés du MINESEC EXTREME NORD</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<h:body>
<div id="menu">
<ui:include src="Menu.xhtml"/>
</div>
<f:view>
<p:dialog widgetVar="dlg" header=" Enregistrer une nouvel nouvelle Structure d'attache " hideEffect="explode" showEffect="explode" modal="true">
<h:form id="formAjouter" >
<p:panelGrid id="panelAjouter" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<p:commandButton value="Enregistrer" action="#{structureBean.createStructure()}" oncomplete="PF('dlg').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="dl" header=" Modifier une structure d'attache" hideEffect="fold" showEffect="explode" resizable="true">
<h:form id="formModifier" enctype="multipart/form-data">
<p:panelGrid id="panelGModifier" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<h:inputHidden id="number" value="#{structureBean.structureAttache.id}" />
<p:commandButton value="Modifier" action="#{structureBean.updateStructure()}" oncomplete="PF('dl').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
</f:view>
<f:view>
<h:form id='tableForm'>
<p:dataTable value="#{structureBean.findAllStructure()}" var="item" paginator="true" rows="10" paginatorTemplate=" {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} " id="table" rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{structureBean.structureAttache}" rowKey="#{item.id}">
<f:facet name="header">
La liste des Structures d'attache
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Structure"/>
</f:facet>
<h:outputText value="#{item.intituleStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Code/Abréviation Structure"/>
</f:facet>
<h:outputText value="#{item.codeStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Arrondissement"/>
</f:facet>
<h:outputText value="#{item.arrondissement.intituleArrondissement}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Département"/>
</f:facet>
<h:outputText value="#{item.arrondissement.departement.intituleDepartement}"/>
</p:column>
</p:dataTable>
<p:toolbar>
<f:facet name="left">
<p:commandButton type="push" onclick="PF('dlg').show();" value="Nouvelle Structure" icon="ui-icon-disk">
<p:ajax update=":formAjouter:panelAjouter" resetValues="true" />
</p:commandButton>
<p:commandButton onclick="PF('dl').show()" value="Modifier Structure" update=":formModifier:panelGModifier" icon="ui-icon-arrowrefresh-1-w"/>
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<p:commandButton type="push" title="Save" image="ui-icon-disk" />
<p:commandButton type="push" title="Update" icon="ui-icon-arrowrefresh-1-w"/>
<p:commandButton type="push" title="Print" image="ui-icon-print"/>
</f:facet>
</p:toolbar>
</h:form>
</f:view>
</h:body>
</html>
You can use a method to initialize your attributes as you would like to, then through an AJAX or and actionListener, you call the method that will do the job before you try to use the attribute.
I have 2 dialogs. In the 1st dialog user writes modulename and I need to pass my modulename to the second dialog and set this modulename value to bean called #{paramController.parameter.modulename}
Please, give me some ideas how to get parameter from one bean and set it to another bean?
</p:inputText>
<p:outputLabel value="Description" for="moduledescription" />
<p:inputTextarea id="moduledescription" rows="4" cols="53" autoResize="false" value="#{modulesController.selected.moduledescription}"/>
<p:outputLabel value="Database Name :" for="moduledbname" />
<p:selectOneMenu id="moduledbname" value="#{modulesController.selected.moduledbname}" style="width:342px">
<f:selectItem itemLabel="Select Connection" itemValue="" noSelectionOption="true" />
<f:selectItems var="con" value="#{sqlserverController.itemsAvailableSelectOne}" itemValue="#{sqlserverController.getSqlserver(conName)}" />
<p:ajax update="#this"/>
</p:selectOneMenu>
<p:outputLabel value="Value :" for="modulevalue" />
<p:inputTextarea id="modulevalue" rows="8" cols="53" autoResize="false" value="#{modulesController.selected.modulevalue}"/>
</p:panelGrid>
<p:commandButton actionListener="#{modulesController.create}" icon="ui-icon-check" value="Save" update="display,:ModulesListForm:datalist,:growl" oncomplete="handleSubmit(args,'ModulesCreateDialog');"/>
<p:commandButton id="btnAdd" value="Add Parameter" icon="ui-icon-plusthick" onclick="PF('dlg1').show();">
</p:commandButton>
<p:commandButton value="Cancel" icon="ui-icon-closethick" onclick="ModulesCreateDialog.hide()"/>
<br/>
</h:panelGroup>
<br/>
<h:form id="ParamForm">
<p:dialog id="AddParamDlg" header="Add Parameter" widgetVar="dlg1" minHeight="40">
<h:panelGroup id="displayParam">
<p:panelGrid columns="2">
<p:outputLabel value="Parameter Name :" for="paramname2" />
<p:inputText id="paramname2" value="#{paramController.parameter.paramname}" style="width:332px" title="#{bundleModules.CreateModulesTitle_modulename}" >
</p:inputText>
<p:outputLabel value="Default Value :" for="defaultvalue2" />
<p:inputText id="defaultvalue2" value="#{paramController.parameter.defaultvalue}" style="width:332px" title="#{bundleModules.CreateModulesTitle_modulename}"/>
<p:outputLabel value="Module Name :" for="parammodulename2" />
<p:selectOneMenu id="parammodulename2" value="#{paramController.parameter.modulename}" style="width:342px">
<f:selectItem itemLabel="Select Module Name" itemValue="" noSelectionOption="true" />
<f:selectItems var="con" value="#{modulesController.itemsAvailableSelectOne}" itemValue="#{modulesController.getModules(paramname)}" />
<p:ajax update="#this"/>
</p:selectOneMenu>
</p:panelGrid>
<p:commandButton action="#{paramController.addNewParameter}" value="Add" update="displayParam, :ModulesCreateForm:ParamForm" onclick="PF('dlg1').hide()" />
</h:panelGroup>
</p:dialog>
</h:form>
</h:form>
First of all you have a nested tag <h:form>.....<h:form> ... </h:form> </h:form>. You need to get rid of this.
SampleManagedBean1.java
#ManagedBean(name="SampleManagedBean1")
#ViewScoped
public class SampleManagedBean1 {
private String mModuleName = "";
public String getModuleName() {
return mModuleName;
}
public void setModuleName(String moduleName) {
this.mModuleName = moduleName;
}
/**
* invoke this API from UI to set value in this bean
*
* #param moduleName
*/
public void setValueOfModuleName(String moduleName) {
this.mModuleName = moduleName;
}
/**
* Invoke this API from UI to get value from this bean
*
* #return
*/
public String getValueOfModuleName() {
return mModuleName;
}
}
SampleManagedBean2.java
#ManagedBean(name="SampleManagedBean2")
#ViewScoped
public class SampleManagedBean2 {
private String mModuleName = "";
public String getModuleName() {
return mModuleName;
}
public void setModuleName(String moduleName) {
this.mModuleName = moduleName;
}
/**
* invoke this API from UI to set value in this bean
*
* #param moduleName
*/
public void setValueOfModuleName(String moduleName) {
this.mModuleName = moduleName;
}
/**
* Invoke this API from UI to get value from this bean
*
* #return
*/
public String getValueOfModuleName() {
return mModuleName;
}
}
From UI
SampleManagedBean2.setValueOfModuleName(SampleManagedBean1.getValueOfModuleName);
As I understood you have two beans, one for dialog 1 and the second for dialog2.
You can pass the "paramController.parameter" (stored in first bean) as a parameter for method (method inside second bean) which shows dialog2.
I'm a beginner in primefaces framework, I want that my commandButton verify if the selected item is "All" to call a specific method allBooks() , and if another item is choosen: to call another method : loadBook()
<p:selectOneMenu value="#{bookBean.selectedBook.id}">
<f:selectItem itemLabel="Select a book :" itemValue="" />
<f:selectItem itemLabel="All" />
<f:selectItems value="#{bookBean.selectedBooksItems}" />
<p:ajax execute="bookSelect" event="change" listener="#{bookBean.loadBook}" />
</p:selectOneMenu>
<p:commandButton id="validate" action="#{bookBean.requestBook}" value="Validate"/>
Do it in your actionListener method
<p:selectOneMenu value="#{bookBean.selection}">
<f:selectItem itemLabel="Select a book :" itemValue="#{null}" />
<f:selectItem itemLabel="All" itemValue="#{'ALL'}" />
<f:selectItems value="#{bookBean.options}" />
<p:ajax/>
</p:selectOneMenu>
<p:commandButton actionListener="#{bookBean.loadButtonActionListener}" value="Load"/>
public void loadButtonActionListener(ActionEvent event){
if(this.selection.equals("ALL")) {
this.allBooks();
} else {
this.loadBook(this.selection);
}
}
commandButton ajaxified by default so this snippet work as you expect:
<h:form>
<p:selectOneMenu value="#{myBean.selected}">
<f:selectItem itemLabel="ALL" itemValue="ALL" />
<f:selectItem itemLabel="NONE" itemValue="NONE" />
</p:selectOneMenu>
<p:commandButton value="Validate" actionListener="#{myBean.doAction}" />
</h:form>
here is declared bean:
#Named
#RequestScoped
public class MyBean {
private String selected;
public MyBean() {
}
public String getSelected() {
return selected;
}
public void setSelected(String selected) {
this.selected = selected;
}
public void doAction() {
if (selected.equals("ALL")) {
System.out.println("ALL Called!");
} else if (selected.equals("NONE")) {
System.out.println("NONE Called");
}
}
}
UPDATE:
if you want to add ajax change event to selectOneMenu just nest this line in selectOneMenu element
<p:ajax listener="#{myBean.doAction}" />