I have a dataTable but when I select a row nothing happens, I've tried calling p:dialog and nothing happened. I tried to redirect to another page with the selected data and also could not (this is my goal). What is missing in my code do. Below is my xhtml and bean.
xhtm:
<h:form id="form" style="font-size: 11pt">
<h3>Cancelar Processo de Portabilidade</h3>
<p:panel header="Consulta por Numeração" id="CancProcP1">
<h:panelGrid columns="3" style="margin-bottom:10px" cellpadding="5"
id="pgridTipoCanc1">
<p:selectOneRadio id="tipoCancela"
value="#{beanBuscarDadosCancPort.tipoBusca}">
<f:selectItem itemLabel="TN" itemValue="1" />
<f:selectItem itemLabel="Bilhete" itemValue="2" />
<f:selectItem itemLabel="Período" itemValue="3" />
<f:ajax render="pgridTipoCanc2" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"
id="pgridTipoCanc2">
<h:outputLabel for="tn" value="TN:"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '1'}" />
<h:inputText id="tn" value="#{beanBuscarDadosCancPort.tn}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '1'}" />
<h:outputLabel for="bilhete" value="Bilhete de Portabilidade:"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '2'}" />
<h:inputText id="bilhete"
value="#{beanBuscarDadosCancPort.srvProvId}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '2'}" />
<h:outputLabel for="dataInicial" value="Data Inicial"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
<p:calendar id="dataInicial"
value="#{beanBuscarDadosCancPort.dataInicial}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
<h:outputLabel for="dataFinal" value="Data Final"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
<p:calendar id="dataFinal"
value="#{beanBuscarDadosCancPort.dataFinal}"
rendered="#{beanBuscarDadosCancPort.tipoBusca == '3'}" />
</h:panelGrid>
<p:commandButton id="pesquisar"
action="#{beanBuscarDadosCancPort.pesquisar}"
value="Buscar" ajax="false" update="display" />
</p:panel>
</h:form>
<p:panel id="CancProcP2">
<h:form id="form2" style="font-size: 11pt">
<p:growl id="growl" showDetail="true"/>
<p:dataTable id="dataTable" var="valor"
value="#{beanBuscarDadosCancPort.listaNumeroPortado}"
paginator="true" rows="5" rowKey="#{valor.srvProvIdDoadoraAnterior}"
selection="#{beanBuscarDadosCancPort.selectedNumP}" selectionMode="single"
rowSelectListener="#{beanBuscarDadosCancPort.onRowSelect}"
onRowSelectUpdate="display growl"
onRowSelectComplete="carDialog.show()"
rowUnselectListener="#{beanBuscarDadosCancPort.onRowUnselect}"
onRowUnselectUpdate="growl"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="4,5,7"
style="max-width: 580px; min-width: 550px">
<f:facet name="header">
</f:facet>
<p:column selectionMode="single" style="width:18px" />
<p:column
style="max-width: 50px; min-width: 50px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Operadora Doadora" />
</f:facet>
<h:outputText value="#{valor.srvProvIdDoadoraAnterior}" />
</p:column>
<p:column
style="max-width: 40px; min-width: 40px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Bilhete" />
</f:facet>
<h:outputText value="#{valor.srvProvId}" />
</p:column>
<p:column
style="max-width: 40px; min-width: 40px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Data/Hora da Janela" />
</f:facet>
<h:outputText value="#{valor.dataJanelaPortabilidade}" />
</p:column>
<p:column
style="max-width: 40px; min-width: 40px; overflow: hidden">
<f:facet name="header">
<h:outputText value="Telefone" />
</f:facet>
<h:outputText value="#{valor.tn}" />
</p:column>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="teste"/>
</f:facet>
<h:outputText value="Model:" />
<h:outputText value="#{beanBuscarDadosCancPort.selectedNumP.srvProvIdDoadoraAnterior}" />
</h:panelGrid>
</p:dialog>
</h:form>
Bean
public class BuscarDadosCancelarPortBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<NumeroPortado> regSelecionado = null;
private String tipoBusca;
private String tn;
private String srvProvId;
private Date dataInicial;
private Date dataFinal;
private List<NumeroPortado> listaNumeroPortado = null;
NumeroPortado numPortato = new NumeroPortado();
private NumPortadoDataModel numModel;
private NumeroPortado selectedNumP;
#EJB
private ConsultasSpnService consultaOp;
public List<NumeroPortado> pesquisar(){
String busca = null;
//String busca = "tn";
//String parametro = "1133100038";
String parametro = null;
String parametro2 = null;
if(tipoBusca.equals("1")){
parametro = tn;
busca = "tn";
}else if(tipoBusca.equals("2")){
parametro = srvProvId;//bilhete
busca = "bilhete";
}else if(tipoBusca.equals("3")){
//DateFormat df = new SimpleDateFormat("dd/MM/yy");
//parametro = df.format(dataInicial);
//parametro2 = df.format(dataFinal);
//busca = "data";
}
if(listaNumeroPortado == null){
listaNumeroPortado = new ArrayList<NumeroPortado>();
listaNumeroPortado = consultaOp.listarNumerosPortados(busca, parametro, parametro2);
//Excluir depois de descobrir porque não está pegando estes campos da tabela
for(int i=0;i<listaNumeroPortado.size();i++){
if(tipoBusca.equals("1")){
listaNumeroPortado.get(i).setTn(parametro);
}else if(tipoBusca.equals("2")){
listaNumeroPortado.get(i).setSrvProvId(parametro);
}
}
//numModel = new NumPortadoDataModel(listaNumeroPortado);
}
return listaNumeroPortado;
}
public String getTn() {
return tn;
}
public void setTn(String tn) {
this.tn = tn;
}
public String getSrvProvId() {
return srvProvId;
}
public void setSrvProvId(String srvProvId) {
this.srvProvId = srvProvId;
}
public Date getDataInicial() {
return dataInicial;
}
public void setDataInicial(Date dataInicial) {
this.dataInicial = dataInicial;
}
public Date getDataFinal() {
return dataFinal;
}
public void setDataFinal(Date dataFinal) {
this.dataFinal = dataFinal;
}
public String getTipoBusca() {
return tipoBusca;
}
public void setTipoBusca(String tipoBusca) {
this.tipoBusca = tipoBusca;
}
public List<NumeroPortado> getListaNumeroPortado() {
return listaNumeroPortado;
}
public void setListaNumeroPortado(List<NumeroPortado> listaNumeroPortado) {
this.listaNumeroPortado = listaNumeroPortado;
}
public NumeroPortado getNumPortato() {
return numPortato;
}
public void setNumPortato(NumeroPortado numPortato) {
this.numPortato = numPortato;
}
public ConsultasSpnService getConsultaOp() {
return consultaOp;
}
public void setConsultaOp(ConsultasSpnService consultaOp) {
this.consultaOp = consultaOp;
}
public List<NumeroPortado> getRegSelecionado() {
return regSelecionado;
}
public void setRegSelecionado(List<NumeroPortado> regSelecionado) {
this.regSelecionado = regSelecionado;
}
public NumPortadoDataModel getNumModel() {
return numModel;
}
public void setNumModel(NumPortadoDataModel numModel) {
this.numModel = numModel;
}
public NumeroPortado getSelectedNumP() {
return selectedNumP;
}
public void setSelectedNumP(NumeroPortado selectedNumP) {
this.selectedNumP = selectedNumP;
}
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage("Line Selected", ((NumeroPortado) event.getObject()).getTn());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowUnselect(UnselectEvent event) {
FacesMessage msg = new FacesMessage("Line Unselected", ((NumeroPortado) event.getObject()).getTn());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String onRowSelectNavigate(SelectEvent event) {
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedNumP", event.getObject());
return "cancelarPortabilidade?faces-redirect=true";
}
}
I changed the rowSelectListener = "#{beanBuscarDadosCancPort.onRowSelect}" by rowSelectListener = "#{beanBuscarDadosCancPort.onRowSelectNavigate}" without success!
I got using only the tag
<p:ajax event="rowSelect" listener="# {beanConsultaPorNum.onRowSelectHeader}" /> between <p:dataTable...> </p:dataTable>.
Related
I have developed an approval screen(for user creation). There I have included two states which were approval and disapproval. Currently it takes the reading only as approval and it doesn't check disapproval. approval process is working fine for me. but I want to have disapproval part as well.
I want to improve my code to take separate readings for above mentioned two different states.
How can I get the approval and disapproval objects to two separate List??? Cant find example for two selection ways in primeface.
I want to know how do i get a column selection as approve and disapprove.
I have the following screen
I have the following datatable
<p:dataTable id="userApprovals" var="user" value="#{userApprovalBean.userApprovals}"
selection="#{userApprovalBean.selectedUser}"
widgetVar="usersTable"
rowKey="#{user.username}"
reflow="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
paginator="true" rows="10" style="margin-bottom:20px">
<f:facet name="header">
<h:commandLink style="float:right;">
<p:graphicImage name="/images/excel.png" width="24" />
<p:dataExporter type="xls" target="userApprovals" fileName="cars" />
</h:commandLink>
User Approval
<h:commandLink style="float:right;">
<p:graphicImage name="/images/pdf.png" width="24" />
<p:dataExporter type="pdf" target="userApprovals" fileName="cars" />
</h:commandLink>
<p:commandButton id="toggler" type="button" value="Columns"
style="width:100px;float:left;" icon="ui-icon-calculator" />
<p:columnToggler datasource="userApprovals" trigger="toggler" />
</f:facet>
<p:column sortBy="#{user.username}">
<f:facet name="header">
<h:outputText value="Username" />
</f:facet>
<h:outputText value="#{user.username}" />
</p:column>
<p:column sortBy="#{user.firstName}">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.firstName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Geneder" />
</f:facet>
<h:outputText value="#{user.gender}" />
</p:column>
<p:column style="width:160px;">
<f:facet name="header">
<h:outputText value="Address" />
</f:facet>
<h:outputText value="#{user.addressLine1}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="User Role" />
</f:facet>
<h:outputText value="#{user.userRole.userRoleDescription}" />
</p:column>
<p:column sortBy="#{user.entUser}">
<f:facet name="header">
<h:outputText value="Created User" />
</f:facet>
<h:outputText value="#{user.entUser}" />
</p:column>
<p:column styleClass="myTable">
<f:facet name="header">
<h:outputText value="Created Date" />
</f:facet>
<h:outputText value="#{user.entDate}" />
</p:column>
<p:column style="width:60px;float:center;" >
<f:facet name="header">
<h:outputText value="View" />
</f:facet>
<p:commandLink update=":form:documentPanel" oncomplete="PF('documentDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search">
<f:setPropertyActionListener value="#{user}" target="#{userApprovalBean.gridUser}" />
</p:commandLink>
</p:column>
<p:column selectionMode="multiple" style="width:55px;text-align:center">
</p:column>
<p:column selectionMode="multiple" style="width:55px;text-align:center">
</p:column>
<f:facet name="footer">
<p:commandButton process="userApprovals" update=":form:multiCarDetail"
icon="ui-icon-search" value="Selected Records" style="width:200px;height:22px"
oncomplete="PF('multiCarDialog').show()" />
</f:facet>
</p:dataTable>
I have the following Bean
public class UserApprovalBean {
private List<UserDetail> userApprovals;
private String recordStatus;
private List<UserDetail> selectedUser;
private UserDetail gridUser;;
private FacesContext context;
private UserDetail loggedUserDetail;
#PostConstruct
public void init(){
try {
context = FacesContext.getCurrentInstance();
userApprovals = UserApprovalDao.getInstance().findAllUserApproval();
//selectedUser.clear();
} catch (Exception e) {
e.printStackTrace();
}
}
public void submitData(){
context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
RequestContext context1 = RequestContext.getCurrentInstance();
boolean dataFill = true;
if (selectedUser.isEmpty()) {
message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Validation Error", "You need to select something....!");
FacesContext.getCurrentInstance().addMessage(null, message);
context1.addCallbackParam("loggedIn", dataFill);
}
else{
try{
for(UserDetail ud: selectedUser){
ud.setRecordStatus("ACTIVE");
ud.setApprovedUser(loggedUserDetail.getUsername());
ud.setApprovedDate(new Timestamp(System.currentTimeMillis()));
UserApprovalDao.getInstance().update(ud);
}
context.getApplication().getNavigationHandler()
.handleNavigation(context, null,
"/approveUserForm.xhtml?faces-redirect=true");
}
catch(Exception e){
e.printStackTrace();
}
}
}
public void refresh() {
HttpServletRequest req = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
context = FacesContext.getCurrentInstance();
if (req.getMethod().equalsIgnoreCase("GET")) {
try {
reload();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void reload() {
clear();
loadData();
}
private void clear() {
userApprovals.clear();
}
private void loadData() {
try {
userApprovals = UserApprovalDao.getInstance().findAllUserApproval();
loggedUserDetail = (UserDetail) context.getExternalContext()
.getSessionMap().get("user");
} catch (Exception e) {
e.printStackTrace();
}
}
public List<UserDetail> getUserApprovals() {
return userApprovals;
}
public void setUserApprovals(List<UserDetail> userApprovals) {
this.userApprovals = userApprovals;
}
public String getRecordStatus() {
return recordStatus;
}
public void setRecordStatus(String recordStatus) {
this.recordStatus = recordStatus;
}
public List<UserDetail> getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(List<UserDetail> selectedUser) {
this.selectedUser = selectedUser;
}
public UserDetail getGridUser() {
return gridUser;
}
public void setGridUser(UserDetail gridUser) {
this.gridUser = gridUser;
}
public UserDetail getLoggedUserDetail() {
return loggedUserDetail;
}
public void setLoggedUserDetail(UserDetail loggedUserDetail) {
this.loggedUserDetail = loggedUserDetail;
}
}
You can use p:selectBooleanCheckbox in approval and disapproval column with unique value objects and can easily get the approval and disapproval selection list using If condition
my Bean
#ManagedBean
#ViewScoped
public class OpenJobOrderBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<OpenJobOrderBean> smtOrder;
private int[] quantity;
private String department;
private String materialName;
private int materialQuantity;
public int[] getQuantity() {
return quantity;
}
public void setQuantity(int[] quantity) {
this.quantity = quantity;
}
public List<OpenJobOrderBean> getSmtOrder() {
try {
this.smtOrder = new OpenJobOrder().retrieveSMTMaterials();
} catch (Exception e) {
e.printStackTrace();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "", e.getMessage());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
return smtOrder;
}
public void setSmtOrder(List<OpenJobOrderBean> smtOrder) {
this.smtOrder = smtOrder;
}
}
<p:dataTable editable="true" editMode="cell" rendered="#{openJobOrderBean.department == 4}" id="qty" selection="#{openJobOrderBean.selectedMaterials}" rowKey="#{openJobOrderBean.materialId}"
rows="5" var="openJob" value="#{openJobOrderBean.smtOrder}" paginator="true" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" widgetVar="theWidget" >
<p:growl id="msgs" showDetail="true"/>
<f:facet name="header">
<h3>
Raw Materials for SMT
</h3>
</f:facet>
<p:ajax event="cellEdit" listener="#{openJobOrderBean.onCellEdit}" oncomplete="onCellEdit()" update=":mainform:msgs" />
<p:column selectionMode="multiple" style="text-align: center; width: 80px" headerText="Select Requested Materials" />
<p:column id="tmp" headerText="Quantity Requested(click to edit)" style="width: 150px; text-align: center" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{openJob.quantity}" id="output" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{openJob.quantity}" required="true" immediate="true" style="width:96%" rendered="true" >
<p:ajax event="keyup" update="output" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Material Name" sortBy="#{openJob.materialName}" filterBy="#{openJob.materialName}" style="width: 200px " >
<h:outputText value="#{openJob.materialName}" />
</p:column>
<p:column headerText="Available Quantity" >
<h:outputText value="#{openJob.materialQuantity}" />
</p:column>
<f:facet name="footer">
<p:commandButton oncomplete="PF('multimaterials').show()" value="Show" process="qty" update=":mainform:materialdetails" icon="ui-icon-check" />
</f:facet>
</p:dataTable>
Entity this is the entity
public List<OpenJobOrderBean> retrieveSMTMaterials() throws Exception {
List<OpenJobOrderBean> open = new ArrayList<>();
Connection connection = new DbConnection().getConnection();
// String query = String.format("Select * from RawMaterialsSMT");
PreparedStatement prs = connection.prepareStatement("select * from availablematerial where DepartmentId = 101");
ResultSet res = prs.executeQuery();
while (res.next()) {
OpenJobOrderBean opjo = new OpenJobOrderBean();
opjo.setMaterialName(res.getString("MaterialName"));
opjo.setMaterialQuantity(res.getInt("Quantity"));
opjo.setItemType(res.getString("ItemType"));
opjo.setMaterialUnit(res.getString("MaterialUnit"));
opjo.setSerialNo(res.getString("SerialNum"));
opjo.setMaterialId(res.getInt("MaterialId"));
open.add(opjo);
}
if (res != null) {
res.close();
}
if (prs != null) {
prs.close();
}
if (connection != null) {
connection.close();
}
return open;
}
pls if i have this el exception what can i do?
Caused by: java.lang.IllegalArgumentException: Cannot convert 45 of type class java.lang.String to class [I
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:424)
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:382)
at com.sun.el.parser.AstValue.setValue(AstValue.java:248)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
at javax.faces.component.UIInput.updateModel(UIInput.java:832)
... 55 more
i got an error on my datatable "Target Unreachable, 'null' returned null", it caused by one column with join with another table, normally i initiate everything in my beans, this is my code, someone can enlighten me please ?
#ManagedBean
#ViewScoped
public class locationBean extends LazyDataModel<Location> {
private Location selectedLocation;
private List<Location> locations;
private List<SelectItem> selectoneitemclient;
#PostConstruct
public void init() {
this.locations = new ArrayList<Location>();
this.selectoneitemclient = new ArrayList<SelectItem>();
this.selectedLocation = new Location();
}
public List<SelectItem> getSelectoneitemclient() {
ClientDao clientdao = new ClientDaoImpl();
List<Client> clients = clientdao.selectItems();
for (Client cl : clients) {
SelectItem selectitem = new SelectItem(cl.getCodecl(), cl.getNom());
this.selectoneitemclient.add(selectitem);
}
return selectoneitemclient;
}
public List<Location> getLocations() {
LocationDao locationdao = new LocationDaoImpl();
this.locations = locationdao.findAll();
return locations;
}
location.xhtml
<h:form id="formDataTable">
<p:dataTable var="location" value="#{locationBean.locations}" rowKey="#{location.codeloc}" paginatorPosition="bottom" paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{locationBean.selectedLocation}" id="tableLocation">
<p:ajax event="rowSelect" listener="#{locationBean.onRowSelect}" update=":formDisplay" oncomplete="PF('dialogLocationDisplay').show()" />
<f:facet name="header">
Listes des réservations
</f:facet>
<p:column headerText="Type client" filterBy="#{location.client.typecl}"
footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{location.client.typecl}" />
</p:column>
<p:column headerText="Nom" filterBy="#{location.client.nom}"
footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{location.client.nom}" />
</p:column>
<p:column headerText="Tel" filterBy="#{location.client.tel}"
footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{location.client.tel}" />
</p:column>
<p:column headerText="Email" filterBy="#{location.client.email}"
footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{location.client.email}" />
</p:column>
<p:column headerText="Date Debut" filterBy="#{location.datedebut}"
footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{location.datedebut}" />
</p:column>
<p:column headerText="Date Fin" filterBy="#{location.datefin}"
footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{location.datefin}" />
</p:column>
<p:column headerText="Gestion">
<p:commandButton id="btnUpdate" update=":formUpdate" oncomplete="PF('dialogLocationUpdate').show()" icon="ui-icon-pencil" title="modifier">
<f:setPropertyActionListener value="#{location}" target="#{locationBean.selectedLocation}"/>
</p:commandButton>
<p:commandButton id="btnDelete" update=":formDelete" oncomplete="PF('dialogLocationDelete').show()" icon="ui-icon-trash" title="supprimer">
<f:setPropertyActionListener value="#{location}" target="#{locationBean.selectedLocation}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
<h:form id="formUpdate">
<p:dialog header="modifier une reservation" widgetVar="dialogLocationUpdate" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="detailLocationUpdate" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Client: " />
<p:selectOneMenu value="#{locationBean.selectedLocation.client.codecl}">
<f:selectItem itemLabel="- Selectionner un client -" itemValue = "" />
<f:selectItems value="#{locationBean.selectoneitemclient}" />
</p:selectOneMenu>
<h:outputText value="Titre: " />
<p:inputText value="#{locationBean.selectedLocation.titre}" />
LocationDaoImpl.java
#Override
public List<Location> findAll() {
List<Location> listloc = null;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
String sql = "FROM Location l inner join fetch l.client";
try {
session.beginTransaction();
listloc = session.createQuery(sql).list();
session.beginTransaction().commit();
} catch (Exception e) {
if (session != null) {
session.close();
}
e.printStackTrace();
}
return listloc;
}
#Override
public boolean update(Location loc) {
boolean flag;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
Location locdb = (Location) session.load(Location.class, loc.getCodeloc());
locdb.setCodeloc(loc.getCodeloc());
locdb.setTitre(loc.getTitre());
locdb.setClient(loc.getClient());
locdb.setDatedebut(loc.getDatedebut());
locdb.setDatefin(loc.getDatefin());
locdb.setTotalttc(loc.getTotalttc());
session.update(locdb);
session.getTransaction().commit();
flag = true;
} catch (Exception e) {
flag = false;
if (session != null) {
session.close();
}
e.printStackTrace();
}
return flag;
}
Good day!
I'm using JSF 2.1 Primefaces 4.0 Glassfish 3.2.1
In my Form.xhtml, I have this code.
<h:form id="modDlgFormc">
<p:dialog id="modIDc" header="Criteria Info"
showEffect="fade" hideEffect="fade" modal="true"
resizable="false" widgetVar="modDlgc" closable="false"
position="center" visible ="#{Fame.modVisiblec}">
<p:messages id="pmsgCrit" closable="true"/>
<h:panelGrid id="criteriapGrid" columns="1">
<h:panelGrid id="critLabelId" columns="2">
<p:selectOneMenu id="fieldNameId" value="#
{Fame.fieldName}" var="fieldSelect">
<f:selectItem itemLabel="Select Field Name"
itemValue="" />
<f:selectItems value="#{Fame.fieldNameMap}" />
<p:ajax event="change" update="fieldNameId
operandId" listener="#{Fame.fieldNameChange}"/>
</p:selectOneMenu>
<p:selectOneMenu id="operandId" value="#{Fame.operator}" >
<f:selectItem itemLabel="Select Operand" itemValue="" />
<f:selectItems value="#{Fame.operandMap}" />
<p:ajax event="change" update="operandId valueId"
listener="#{Fame.operandChange}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="valueId" columns="2">
<c:if test="#{Fame.showValue == 'txt'}">
<h:outputLabel for="inputVal" value="Value : " style="font-weight: bolder"/>
<p:inputText id="inputVal" size="30" value="#{Fame.value}"/>
<c:if test="#{Fame.operator == 'Is Between'}">
<h:outputText value=""/>
<p:inputText size="30" value="#{Fame.value2}"/>
</c:if>
</c:if>
<c:if test="#{Fame.showValue == 'cal'}">
<h:outputLabel for="fromDateId" value="From : " style="font-weight: bolder"/>
<p:calendar id="fromDateId" value="#{Fame.date}" showButtonPanel="true" maxdate="#{Fame.maxDate}"/>
<c:if test="#{Fame.operator == 'Is Between'}">
<h:outputLabel for="toDateId" value="To : " style="font-weight: bolder"/>
<p:calendar id="toDateId" value="#{Fame.date2}" showButtonPanel="true" maxdate="#{Fame.maxDate}"/>
</c:if>
</c:if>
<c:if test="#{Fame.showValue == 'upload'}">
<h:outputText value=""/>
<p:commandButton value="UPLOAD" onclick="uconfirmation.show()" type="button" />
</c:if>
</h:panelGrid>
<h:panelGrid id="critBtnId" columns="4">
<p:commandButton id="addBtn" value="ADD" actionListener="#{Fame.saveCriteria}" update=":modDlgFormc:modIDc" rendered="#{empty Fame.editMode}" />
<p:commandButton value="SAVE" actionListener="#{Fame.updateCriteria}" update=":modDlgFormc:modIDc" rendered="#{not empty Fame.editMode}"/>
<p:commandButton value="CANCEL" actionListener="#{Fame.cancelCriteria}" update=":modDlgFormc" rendered="#{not empty Fame.editMode}"/>
<p:commandButton id="mCancelButtonc" value="CLOSE" update=":modDlgFormc:modIDc :wbookForm" actionListener="#{Fame.closealldialogsopen}"/>
</h:panelGrid>
<br/>
</h:panelGrid>
<center>
<h:panelGrid id="critDTable" columns="1">
<p:dataTable id="criteriaTbl" var="criteria" value="#{Fame.createdCriteria}" paginator="true" rows="5" rowIndexVar="rowIndex" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="{totalRecords} record(s) in {totalPages} page(s)">
<p:column headerText="WORKSHEET NAME">
#{criteria.wsheetName}
</p:column>
<p:column headerText="FIELD NAME">
#{criteria.fieldName}
</p:column>
<p:column headerText="OPERATOR">
#{criteria.operator}
</p:column>
<p:column headerText="VALUE">
#{criteria.value}
</p:column>
<p:column headerText="UPDATE">
<p:panelGrid>
<p:row>
<p:column style="vertical-align: top;border: none">
<p:commandButton actionListener="#{Fame.editCri(rowIndex)}" style="width:30px;text-align:center;border:none;background-color:transparent;" icon="ui-icon-pencil" update=":modDlgFormc" />
<p:commandButton actionListener="#{Fame.deleteCri(rowIndex)}" style="width:30px;text-align:center;border:none;background-color:transparent;" icon="ui-icon-close" update=":modDlgFormc" />
</p:column>
</p:row>
</p:panelGrid>
</p:column>
</p:dataTable>
</h:panelGrid>
</center>
</p:dialog>
</h:form>
My Main code
#ManagedBean(name = "Fame")
#SessionScoped
private FameCriteriaDAOImpl fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
private ArrayList<FameCriteriaBean> createdCriteria = new ArrayList();
public void saveCriteria() {
fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
try {
if (this.validate() == true) {
//String wsheetId = fameManagementDP.getWsheetId(group_Id, workbookName);
FameCriteriaBean bean = new FameCriteriaBean();
bean.setWsheetId(this.worksheetId);
bean.setFieldName(this.fieldName);
bean.setOperator(this.operator);
bean.setValue(this.value);
String actionStr = "inserted";
fameCriteriaDAOImpl.save(bean);
}
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
error(converter.getConvertedError(sqlEx.getMessage()));
} finally {
this.initialize();
this.initializeCreatedCriteria();
this.resetCriteria();
}
}
My Bean code.
public class FameCriteriaBean {
private String wsheetName = "";
private String wsheetId = "";
private String fieldName = "";
private String operator = "";
private String value = "";
public FameCriteriaBean(){
}
/**
* #return the fieldName
*/
public String getFieldName() {
return fieldName;
}
/**
* #param fieldName the fieldName to set
*/
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
/**
* #return the operator
*/
public String getOperator() {
return operator;
}
/**
* #param operator the operator to set
*/
public void setOperator(String operator) {
this.operator = operator;
}
/**
* #return the value
*/
public String getValue() {
return value;
}
/**
* #param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* #return the wsheetId
*/
public String getWsheetId() {
return wsheetId;
}
/**
* #param wsheetId the wsheetId to set
*/
public void setWsheetId(String wsheetId) {
this.wsheetId = wsheetId;
}
/**
* #return the wsheetName
*/
public String getWsheetName() {
return wsheetName;
}
/**
* #param wsheetName the wsheetName to set
*/
public void setWsheetName(String wsheetName) {
this.wsheetName = wsheetName;
}
}
Below is the scenario.
I choose a fieldName then the lists of operand was loaded. This is correct.
I click the button ADD, then a p:message appear that there is no operand selected. This is correct.
I had noticed that the fieldname value that I was selected when error appears was gone.
My question is how not to refresh the value of fieldNameId so that I can use it after an error is displayed in p:message.
I'm using SessionScoped for my java class because I'm using p:wizard in Form.xhtml.
Please help me to solve this.
Thank you and More Power! :)
What I did is this.
Please see updated Main class
#ManagedBean(name = "Fame")
#SessionScoped
private FameCriteriaDAOImpl fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
private ArrayList<FameCriteriaBean> createdCriteria = new ArrayList();
public void saveCriteria() {
fameCriteriaDAOImpl = new FameCriteriaDAOImpl();
if (!this.validate()) {
return;
}
try {
FameCriteriaBean bean = new FameCriteriaBean();
bean.setWsheetId(this.worksheetId);
bean.setFieldName(this.fieldName);
bean.setOperator(this.operator);
bean.setValue(this.value);
String actionStr = "inserted";
fameCriteriaDAOImpl.save(bean);
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
error(converter.getConvertedError(sqlEx.getMessage()));
} finally {
this.initialize();
this.initializeCreatedCriteria();
this.resetCriteria();
}
}
I'm using prime faces 3.4.2 and I'm trying to update an entity that contains a list of another object, using a row editing datatable. My problem is that when I validate the change , the simple attributes of the entity are updated in the database , but the list is not. I don't know how to save the whole object in the data base.
here you find the editing page :
`
<p:panel style="width:1000px; ;font: lighter 70.5% Arial, Helvetica, sans-serif ; " header="Informations Générales">
<p:growl id="growl" showDetail="true" sticky="true" style="font-size: small;" />
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Société" />
<p:inputText id="custSoc" value="#{CustomerCtrl.selectedCust.company}"/>
<h:outputLabel value="Secteur d'activité" />
<p:inputText id="custActivite" value="#{CustomerCtrl.selectedCust.secteurActivite}" />
<h:outputLabel value="Nom du propriétaire" />
<p:inputText id="custprop" value="#{CustomerCtrl.selectedCust.proprietaire}" />
</h:panelGrid>
<p:tabView id="tabView">
<p:tab title="Coordonnées">
<p:growl id="messages" showDetail="true"/>
<p:dataTable var="cu" value="#{CustomerCtrl.selectedCust.coordonnee}" id="carList" editable="true">
<f:facet name="header">
Coordonnées
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column colspan="5" headerText="Adresses" />
<p:column colspan="5" headerText="Contacts" />
</p:row>
<p:row>
<p:column headerText="Num" style="width:2cm"/>
<p:column headerText="Rue/Avenue" style="width:3cm"/>
<p:column headerText="Code postal" style="width:2cm" />
<p:column headerText="Ville" style="width:2.5cm" />
<p:column headerText="Pays" style="width:2.5cm" />
<p:column headerText="Fixe" style="width:2cm"/>
<p:column headerText="Mobile" style="width:2cm"/>
<p:column headerText="Fax" style="width:2cm"/>
<p:column headerText="E-mail" style="width:3.7cm"/>
<p:column headerText=" " />
</p:row>
</p:columnGroup>
<p:ajax event="rowEdit" listener="#{CustomerCtrl.onEdit}" update=":form:messages" />
<p:ajax event="rowEditCancel" listener="#{CustomerCtrl.onCancel}" update=":form:messages" />
<p:column headerText="Num">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.number}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.number}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Rue/Avenue">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.street}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.street}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Code postal">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.zipcode}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.zipcode}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Ville">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.city.text}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{cu.city.text}" style="width:100%">
<f:selectItems value="#{CustomerCtrl.cityList}" style="width:100%"
var="city"
itemLabel="#{city}"
itemValue="#{city}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Pays" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.country.text}" style="width:100%" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{cu.country.text}" style="width:100%">
<f:selectItems value="#{CustomerCtrl.countryList}" style="width:100%"
var="color"
itemLabel="#{color}"
itemValue="#{color}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Fixe">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.phone}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.phone}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Mobile" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.mobile}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.mobile}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Fax" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.fax}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.fax}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="E-mail" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.email}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.email}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:tab>
<p:tab title="Compte">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Login" />
<p:inputText id="userLogin" value="#{CustomerCtrl.selectedCust.login}" />
<h:outputLabel value="Mot de passe" />
<p:password id="userpass" value="#{CustomerCtrl.selectedCust.password}" />
</h:panelGrid>
</p:tab>
<p:tab title="Applications">
<h:panelGrid columns="2" cellpadding="5">
</h:panelGrid>
</p:tab>
<p:tab title="Interventions">
<h:panelGrid columns="2" cellpadding="5">
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
<br/>
`
and here is my managedbean :`#ManagedBean(name = "CustomerCtrl")
#ViewScoped
public class CustomerController implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int idSelected;
private Customer selectedCust ;
private Coordonnee selectedCoord = new Coordonnee();
private Coordonnee filteredCoord = new Coordonnee();
private List<Customer> filteredCusts;
private int cityId;
private int countryId;
private List<SelectItem> cityList = new ArrayList<SelectItem>();
private List<SelectItem> countryList = new ArrayList<SelectItem>();
private List<Customer> custmrs = new ArrayList<Customer>();
private List<Coordonnee> coordonnees = new ArrayList<Coordonnee>();
private Coordonnee selectedCustomerCoordonne;
#EJB
private SettingsBean settingBean;
public CustomerController() {
if (selectedCust != null) {
coordonnees = (List<Coordonnee>) settingBean.FindCoordonneeByCustomer(selectedCust.getId());
}
}
public void createCustomer() {
System.out.println("hello createCustomer");
System.out.println("selectedcust :"+selectedCust.getCompany());
System.out.println("selectedcustCoordonnee 1 :"+selectedCustomerCoordonne);
if(selectedCust==null){
System.out.println("entré");
selectedCust= new Customer();
System.out.println("nouvelle instance créé");
settingBean.createCustomer(selectedCust);
settingBean.createCoordonnee(selectedCustomerCoordonne);
System.out.println("Nouveau client " + selectedCust.getCompany() + " ajoutée");
}
else{
System.out.println("editer");
selectedCust.setCoordonnee(coordonnees);
settingBean.editCustomer(selectedCust);
System.out.println("client " + selectedCust.getCompany() + " édité");
}
}
public List<Customer> getCustmrs() {
custmrs = settingBean.findAllCustomers();
return custmrs;
}
public void setCustmrs(List<Customer> custmrs) {
this.custmrs = custmrs;
}
public void preRenderView() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(true);
}
public Customer getSelectedCust() {
if (selectedCust == null) {
selectedCust = (Customer) FacesContext.getCurrentInstance()
.getExternalContext().getSessionMap().get("selectedCust");
System.out.println("Par session");
if (selectedCust == null) {
selectedCust = new Customer();
selectedCust.setCoordonnee(new ArrayList<Coordonnee>());
} else
selectedCust.setCoordonnee(settingBean
.FindCoordonneeByCustomer(selectedCust.getId()));
}
return selectedCust;
}
public void setSelectedCust(Customer selectedCust) {
this.selectedCust = selectedCust;
}
public List<Customer> getFilteredCusts() {
return filteredCusts;
}
public void setFilteredCusts(List<Customer> filteredCusts) {
this.filteredCusts = filteredCusts;
}
public List<Coordonnee> getCoordonnees() {
if (selectedCust != null) {
coordonnees = (List<Coordonnee>) settingBean.FindCoordonneeByCustomer(selectedCust.getId());
}
return coordonnees;
}
public void setCoordonnees(List<Coordonnee> coordonnees) {
this.coordonnees = coordonnees;
}
public void setCustomerToEdit(Customer customerToEdit) {
}
public String removeCustomer() {
if (selectedCust != null) {
System.out.println("in delete");
String selected = selectedCust.getCompany();
System.out.println("supprimer " + selected + "");
custmrs.remove(selectedCust);
settingBean.removeCustomer(selectedCust);
System.out.println("client supprimé");
}
return "";
}
public String removeCustomercoordonnee() {
if (selectedCustomerCoordonne != null) {
System.out.println("coordonne in delete");
String selected = selectedCustomerCoordonne.getEmail();
System.out.println("supprimer " + selected + "");
settingBean.removeCustomerCoordonnee(selectedCustomerCoordonne);
System.out.println("coordonne supprimé");
}
return "";
}
public String editCustomer() {
if (selectedCust != null) {
FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().put("selectedCust", selectedCust);
System.out.println("selected "
+ FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().get("selectedCust"));
}
return "customeradd.xhtml?faces-redirect=true";
}
public int getCityId() {
return cityId;
}
public void setCityId(int cityId) {
this.cityId = cityId;
}
public int getCountryId() {
return countryId;
}
public void setCountryId(int countryId) {
this.countryId = countryId;
}
public List<SelectItem> getCityList() {
cityList = new ArrayList<SelectItem>();
List<City> Listcity = settingBean.findAllCity();
for (City c : Listcity) {
cityList.add(new SelectItem(c.getId(), c.getText()));
}
return cityList;
}
public void setCityList(List<SelectItem> cityList) {
this.cityList = cityList;
}
public List<SelectItem> getCountryList() {
cityList = new ArrayList<SelectItem>();
List<Country> Listcountry = settingBean.findAllCountry();
for (Country c : Listcountry) {
countryList.add(new SelectItem(c.getId(), c.getText()));
}
return countryList;
}
public void setCountryList(List<SelectItem> countryList) {
this.countryList = countryList;
}
public int getIdSelected() {
return idSelected;
}
public void setIdSelected(int idSelected) {
this.idSelected = idSelected;
}
public Coordonnee getSelectedCustomerCoordonne() {
return selectedCustomerCoordonne;
}
public void setSelectedCustomerCoordonne(
Coordonnee selectedCustomerCoordonne) {
this.selectedCustomerCoordonne = selectedCustomerCoordonne;
}
public Coordonnee getSelectedCoord() {
return selectedCoord;
}
public void setSelectedCoord(Coordonnee selectedCoord) {
this.selectedCoord = selectedCoord;
}
public Coordonnee getFilteredCoord() {
return filteredCoord;
}
public void setFilteredCoord(Coordonnee filteredCoord) {
this.filteredCoord = filteredCoord;
}
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Cliquer sur enregistrer pour valider la modification", ((Coordonnee) event.getObject()).getCustomer().getCompany());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Modification annulée", ((Coordonnee) event.getObject()).getCustomer().getCompany());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}`
Pleaaase help me to save the both objects.