I am using sorting in p:datatable, and last column is edit .
its working fine till sorting is pressed. as soon as I do sorting it behave unusual.
On editing it giving wrong object.
belwo is my datatable.
<h:form>
<h:inputHidden value="#{countryBean.initList}" />
<p:dataTable id="existingCountry1" var="countryLang" value="#{countryBean.myexistingCountryList}" style="width: 100%" styleClass="role_detail_section"
rowStyleClass="activity_white, activity_blue" cellspacing="0" cellpadding="0" border="0" rows="6" paginator="true">
<p:column width="30%" headerText="Country " sortBy="countryName">
<h:outputLabel value="${countryLang.countryName}" />
</p:column>
<p:column width="30%" headerText="Country Code " >
<h:outputLabel value="${countryLang.countryCode}" />
</p:column>
<p:column headerText="Edit" >
<p:commandLink id="editCommandLinkId"
action="#{countryBean.editCountryByCountryCode(countryLang.countryCode,true)}" title="Edit" styleClass="edit_icon" onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
</p:column>
</p:dataTable>
suppose I edited for US, then it will show data for AU like that.
for sorting I am using belwo technique
private ArrayList<Country> myexistingCountryList;
public String getInitList() {
myexistingCountryList= getExistingCountryList();
return null;
}
public ArrayList<Country> getExistingCountryList() {
try {
existingCountryList = new ArrayList<Country>();
existingCountryList.addAll(getCountryService().getExistingCountry());
} catch (ServiceException e) {
e.printStackTrace();
errorLogger.error("Error while getExistingCountryList in service layer", e);
}
There are to many mistakes in your code.
Instead of $ use #
Instead of sortBy="countryName" write sortBy="#{countryLang.countryName}"
So basicly
change this
<p:column width="30%" headerText="Country " sortBy="countryName">
<h:outputLabel value="${countryLang.countryName}" />
</p:column>
to this
<p:column width="30%" headerText="Country " sortBy="#{countryLang.countryName}">
<h:outputLabel value="#{countryLang.countryName}" />
</p:column>
Related
I am working on #ViewScoped annotation in JSF2.0. Below is the code what I had written. It is not working as I expected. Please review it and let me know if any changes are required to get the exact output that what am thinking of.
Here is my Controller SearchController.java
package com.s2tech.jsfapp.controllers;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.s2tech.jsfapp.helper.SearchHelper;
import com.s2tech.jsfapp.managedbean.SearchManagedBean;
#ManagedBean(name ="searchController")
#ViewScoped
public class SearchController implements Serializable{
public SearchController(){
private static final long serialVersionUID = 1L;
SearchHelper searchHelper;
private List<SearchManagedBean> employeeList=new ArrayList<SearchManagedBean>();
public List<SearchManagedBean> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<SearchManagedBean> employeeList) {
this.employeeList = employeeList;
}
public void getEmployee(SearchManagedBean searchManagedBean) {
searchHelper=new SearchHelper();
employeeList = searchHelper.getEmployee(searchManagedBean);
//return "search.xhtml";
//return Constants.searchPage;
// return null;
}
Below is my view search.xhtml
<h:body style="background-color:skyblue;">
<ui:include src="mainMenu.xhtml"></ui:include>
<h:form prependId="false">
<table>
<tr style="display:block;margin-top:10px;width:100%;margin-left:40%">
<td style="width:40%">
<p:outputLabel for="firstName" value="First Name:" style="font-weight:bold" />
<p:inputText id="firstName" value="#{searchManagedBean.firstName}" required="true" requiredMessage="please enter First Name"> </p:inputText>
<p:message id="firstNameMsg" for="firstName" showDetail="true" ></p:message>
</td>
<td style="width: 20%"></td>
<td style="width:40%;">
<p:outputLabel for="lastName" value="Last Name:" style="font-weight:bold"/>
<p:inputText id="lastName" value="#{searchManagedBean.lastName}" required="true" requiredMessage="please enter Last Name" />
<p:message id="lastNameMsg" for="lastName" showDetail="true" ></p:message>
</td>
</tr>
<tr style="display:block;margin-top:10px;width:100%;margin-left:78%">
<td style="width:40%"> <p:commandButton value="Search" action="#{searchController.getEmployee(searchManagedBean)}" update="firstNameMsg lastNameMsg emailMsg phoneMsg dataTable"/></td>
</tr>
</table>
</h:form>
<p:dataTable id="dataTable" var="emp" rendered="#{not empty searchController.employeeList}" value="#{searchController.employeeList}" rowStyleClass="table table-striped table-hover table-bordered" resizableColumns="true" resizeMode="expand" scrollWidth="50%" scrollHeight="150" >
<p:column headerText="First Name">
<h:outputText value="#{emp.firstName}"/>
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{emp.lastName}"/>
</p:column>
<p:column headerText="Email">
<h:outputText value="#{emp.email}"/>
</p:column>
<p:column headerText="Phone">
<h:outputText value="#{emp.phone}"/>
</p:column>
<p:column headerText="Edit">
<p:commandLink value="Edit" action="#{searchController.getEditForm(emp)}" style="margin-left:40px;color:blue;"></p:commandLink>
</p:column>
</p:dataTable>
</h:body>
</html>
My question is that after entering first name and last name, when I click on submit button it need to hit controller's getEmployee() method and it needs to display data table values from controller's getEmployeeList(). Here eventhough using ViewScoped bean Iam not getting output. Any suggestions??
I know this ask is repeated, but none response help me to solve this problem.
I'm trying to delete a row from a primefaces datatable with a commandButton and a confirmDialog, this doesn't work because the backBean isn't getting the values. When I'm trying to delete this show me a null pointer exception. well see my code if you can help me.
This is my XHTML:
<h:form id="principalForm">
<p:menubar>
<p:menuitem value="Nuevo" icon="ui-icon-plusthick" oncomplete="PF('wdlgIngresar').show();"/>
</p:menubar>
<p:dataTable id="dtpacientes" value="#{beanPersona.listPersona}" var="per"
paginator="true" rows="15" rowsPerPageTemplate="15,20,30" paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
selectionMode="single" selection="#{beanPersona.currPersona}" rowKey="#{per.id}">
<p:ajax event="rowSelect" listener="#{beanPersona.onRowSelect}" update=":dlgVer" oncomplete="PF('wdlgVer').show()" />
<p:column headerText="Id" sortBy="#{per.id}" filterBy="#{per.id}">
<h:outputText value="#{per.id}" />
</p:column>
<p:column headerText="Nombre" sortBy="#{per.nombres} #{per.apellidos}" filterBy="#{per.nombres} #{per.apellidos}">
<h:outputText value="#{per.nombres} #{per.apellidos}" />
</p:column>
<p:column headerText="Correo" sortBy="#{per.correo}" filterBy="#{per.correo}">
<h:outputText value="#{per.correo}" />
</p:column>
<p:column headerText="Edad" >
<h:outputText value="#{beanPersona.getEdad(per.nacimiento)}" />
</p:column>
<p:column headerText="Sexo" >
<h:outputText value="#{beanPersona.getSexo(per.sexo)}" />
</p:column>
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash" update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();" actionListener="#{beanPersona.nullMethod}">
<f:setPropertyActionListener value="#{per}" target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- HERE beanPersona.currPersona.id HAVE THE CURRENT VALUE CORRECTLY-->
<p:confirmDialog id="deleteConfirmDialog" header="Atencion!" severity="alert" widgetVar="deleteConfirmation"
message="Desea eliminar paciente Nº #{beanPersona.currPersona.id} ?" >
<p:commandButton id="confirm" value="Sí" oncomplete="PF('deleteConfirmation').hide();"
update=":principalForm:dtpacientes" action="#{beanPersona.eliminar(beanPersona.currPersona)}" />
<p:commandButton id="decline" value="No" oncomplete="PF('deleteConfirmation').hide();"/>
</p:confirmDialog>
</h:form>
This is my Bean:
#ManagedBean
#ViewScoped
public class BeanPersona implements Serializable {
private Persona persona = new Persona();
private Persona currPersona = new Persona();
public BeanPersona() {
persona = new Persona();
currPersona = new Persona();
}
public Persona getCurrPersona() {
return currPersona;
}
public void setCurrPersona(Persona currPersona) {
this.currPersona = currPersona;
}
public Persona getPersona() {
return persona;
}
public void setPersona(Persona persona) {
this.persona = persona;
}
public void eliminar(Persona currPersona) {
if(currPersona != null) {
new Dml().delete(currPersona, currPersona.getId());
listar();
System.out.println("succefull delete !!!!");
} else if(this.currPersona != null){
new Dml().delete(this.currPersona, this.currPersona.getId());
this.currPersona = new Persona();
listar();
System.out.println("succefull delete this.currPersona!!!!");
} else {
System.out.println("currPersona is null !!!!");
}
}
public String nullMethod () {return null;}
}
currPersona still null when I throw the method
The attribute onclick is for client side behaviour like executing some JS or showing up a dialog etc. You are not defining an actionListener for your commandButton at all.
Try to remove the onclick completely and use a proper actionListener instead:
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash"
update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();"
actionListener="#{beanPersona.someActionListener}">
<f:setPropertyActionListener value="#{per}"
target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
I solved it, I just put process tag into "confirm" commandButton with value at "#this"
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash" update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();" actionListener="#{beanPersona.setCurrPersona(per)}">
<f:setPropertyActionListener value="#{per}" target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- HERE beanPersona.currPersona.id HAVE THE CURRENT VALUE CORRECTLY-->
<p:confirmDialog id="deleteConfirmDialog" header="Atencion!" severity="alert" widgetVar="deleteConfirmation"
message="Desea eliminar a paciente Nº #{beanPersona.currPersona.id} ?" closeOnEscape="true" >
<p:commandButton id="confirm" value="Sí" oncomplete="PF('deleteConfirmation').hide();"
update=":principalForm:dtpacientes" action="#{beanPersona.eliminar}" process="#this"/>
<p:commandButton id="decline" value="No" oncomplete="PF('deleteConfirmation').hide();"/>
</p:confirmDialog>
I am working with jsf 2.0 et Primefaces. i have a selectOneMenu that have dynamic values of datas that correspond to the user connected. I want that when i choose a data and click on the button view the list of emails related to the data selected will be shown on the dataTable.
<p:panel>
<p:selectOneMenu id="data" value="#{mailMB.database}" styleClass="auto" required="true" effect="fade" >
<f:selectItem itemLabel="Select Data" itemValue="" />
<f:selectItems value="#{dataMB.datas}" var="data" itemLabel="#{data.keyword}" itemValue="#{data.keyword}"/>
</p:selectOneMenu>
<p:commandButton value="View" action="#{mailMB.grabemails()}" ajax="true" update="datas" icon="ui-icon-circle-check" styleClass="ui-priority-primary" />
</p:panel>
<p:panel id="panelform" header="Emails List" >
<p:dataTable value="#{mailMB.emailsByData}" var="item" id="datas" rowsPerPageTemplate="5,10,15,20,25,30"
paginator="true" rows="10"
selectionMode="single" filteredValue="#{mailMB.filteredMails}" rowKey="#{item.id}"
selection="#{mailMB.selectedMail}">
<p:ajax event="rowSelect" update=":form:dataView , :form:confirmDelete, :form:viewButton" listener="#{dataMB.onRowSelect}"/>
<p:ajax event="rowToggle" />
<p:column style="width:2%" exportable="false">
<p:rowToggler />
</p:column>
<p:column sortBy="#{item.email}" filterBy="#{item.email}">
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
</p:dataTable>
</p:panel>
and this is my method in the managed Bean that returns the list of emails by data using the named query:
public List<Email> getEmailsByData() {
System.out.println("the database" + getDatabase());
return emailsByData = mailBusinessLocal.mails(getDatabase());
}
public List<Email> grabemails() {
return emailsByData = mailBusinessLocal.mails(database);
}
when i choose a data and click view nothing happens and the databate return null as it shown on the glassfish log.
You need to put your <p:selectOneMenu> inside a <h:form>. That's my first guess.
This project is made with Primefaces 3.5, JSF 2.0, Oracle database.
The view:
<h:form id="schedule" class="schedule">
// more JSF and forms and dialogs
<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
<h:form id="frmPatient">
<h:panelGrid id="findPatient" columns="1">
<h:panelGrid id="findPatientParameters" columns="2">
<h:outputLabel value="Firstname: " />
<p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
<h:outputLabel value="Patient Code: " />
<p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
<br />
<p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
</h:panelGrid>
<h:panelGrid id="findPatientDetails" columns="1">
<p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250"
scrollHeight="150" value="#{waitinglistBean.patients}"
rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}"
selectionMode="single" >
<f:facet name="header">
Click "Select" button after selecting a row to select patient.
</f:facet>
<p:column width="150" headerText="Code">
#{patient.PCode}
</p:column>
<p:column width="150" headerText="Family Name">
#{patient.PLname}
</p:column>
<p:column width="150" headerText="First Name">
#{patient.PFname}
</p:column>
<p:column headerText="Sex" >
#{patient.PSex}
</p:column>
<p:column headerText="Birthdate">
#{patient.PBorn}
</p:column>
<p:column headerText="Street">
#{patient.PStreet}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="Select" icon="ui-icon-search"
oncomplete="patientDialog.hide()"
update=":frmDialogs:frmWaiting:tabView:patientDetails"
process="patients"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
<h:form id="frmPatient">
<h:panelGrid id="findPatient" columns="1">
<h:panelGrid id="findPatientParameters" columns="2">
<h:outputLabel value="Firstname: " />
<p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
<h:outputLabel value="Patient Code: " />
<p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
<br />
<p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
</h:panelGrid>
<h:panelGrid id="findPatientDetails" columns="1">
<p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250"
scrollHeight="150" value="#{waitinglistBean.patients}"
rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}"
selectionMode="single" >
<f:facet name="header">
Click "Select" button after selecting a row to select patient.
</f:facet>
<p:column width="150" headerText="Code">
#{patient.PCode}
</p:column>
<p:column width="150" headerText="Family Name">
#{patient.PLname}
</p:column>
<p:column width="150" headerText="First Name">
#{patient.PFname}
</p:column>
<p:column headerText="Sex" >
#{patient.PSex}
</p:column>
<p:column headerText="Birthdate">
#{patient.PBorn}
</p:column>
<p:column headerText="Street">
#{patient.PStreet}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="Select" icon="ui-icon-search"
oncomplete="patientDialog.hide()"
update=":frmDialogs:frmWaiting:tabView:patientDetails"
process="patients"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
// more JSF and dialogshizzle
</h:form>
The backing bean:
#ManagedBean(name="waitinglistBean")
#ViewScoped
public class WaitinglistBean implements Serializable
{
private Patients patient;
private OrWaitinglist orWaitinglist;
private List<Patients> patients = new ArrayList<Patients>();
private String name;
private Integer pcode;
public WaitinglistBean() {
}
public void setSelectedPatient(Patients patient) {
this.patient = patient;
}
public Patients getSelectedPatient() {
return patient;
}
public OrWaitinglist getOrWaitinglist() {
return orWaitinglist;
}
public void setOrWaitinglist(OrWaitinglist orWaitinglist) {
this.orWaitinglist = orWaitinglist;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPcode() {
return pcode;
}
public void setPcode(Integer pcode) {
this.pcode = pcode;
}
public List<Patients> getPatients() {
PatientsDao patientsDao = new PatientsDaoImpl();
patients = patientsDao.getSearchPatient(name, pcode);
System.out.println(name + " " + pcode);
return patients;
}
public void createOrWaitinglist()
{
orWaitinglist.setPatients(patient);
}
So first a user enter a string: "Firstname" and an Integer: "Patient Code".
When he hits the "Search" button it fires the actionListener="#{patientBean.patients}
inside that commandbutton. The method needs 2 parameter, name and pcode which have their own setters/getters.
When I look in console it shows me the printout of these 2 parameters, and they are twice "null", so that means the parameters from the JSF pages were not passed to the backing bean, although the value of the inputText has been set to the backingbean set method: value="#{patientBean.name}"
My question now is why do I get these null-values. I've read several posts which use these setters, but still I get null-values.
after edit i still have the same problem;
for send value of input component in h:panelgrid to the backingbean use somthing like this:
<p:commandButton value="Search" process="#(frmPatient:findPatientParameters :input)"
actionListener="#{patientBean.patients}" update="patients"/>
I have a view scoped arrayList as bean. This is used to display the editable columns of dataTable. When the page is displayed initially and I try to update the table contents the update works fine, however when I try to update any column the second time the values which are changed do not reflect in the arrayList bean (verified in the action method using break point). The action method is also a managed bean with view scope.
<managed-bean>
<managed-bean-name>financialListBean</managed-bean-name>
<managed-bean-class>java.util.ArrayList</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
Below is the code for dataTable
<h:form id="myform">
<h:dataTable id="financialListBean1"
value="#{financialListBean}" var="varfinancialListBean"
styleClass="dataTableEx" headerClass="headerClass"
footerClass="footerClass"
rowClasses="rowClass1, rowClass2"
columnClasses="columnClass1" border="0" cellpadding="2"
cellspacing="0">
<h:column id="columnEx17">
<h:selectBooleanCheckbox styleClass="inputRowSelect"
id="rowSelect3"
value="#{varfinancialListBean.rowSelected}"></h:selectBooleanCheckbox>
<f:facet name="header"></f:facet>
</h:column>
<h:column id="amount1column">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Amount"
id="amount1text"></h:outputText>
</f:facet>
<h:inputText styleClass="small8Input" id="amount1"
value="#{varfinancialListBean.amount}" onkeypress="return only5DigitsEntry(this, event);" onkeyup="return checkRequiredFieldsForUpdateFinancialBtn(this.form, event);">
</h:inputText>
</h:column>
<h:column id="type1column">
<h:selectOneMenu styleClass="selectOneMenu" id="menu1" value="#{varfinancialListBean.type}">
<f:selectItem itemLabel="M" itemValue="M" />
<f:selectItem itemLabel="Y" itemValue="Y" />
<f:selectItem itemLabel="Z" itemValue="Z" />
<f:selectItem itemLabel="O" itemValue="O" />
<f:selectItem itemLabel="S" itemValue="S" />
</h:selectOneMenu>
<f:facet name="header">
<h:outputText styleClass="outputText" value="Type"
id="type1text"></h:outputText>
</f:facet>
</h:column>
<h:column id="recDate1column">
<f:facet name="header">
<h:outputText styleClass="outputText"
value="Recieve Date" id="recDate1text"></h:outputText>
</f:facet>
<h:inputText styleClass="outputText" id="recDate1"
value="#{varfinancialListBean.recDate}"
onclick="getClock($(this).attr('id'))" >
<f:convertDateTime pattern="MMM d, yyyy"/>
</h:inputText>
</h:column>
</h:dataTable>
<h:commandButton type="submit"
value="Update Financial Information"
styleClass="commandExButton" id="updateFinancialBtn"
action="#{pc_SocialServicesView.doFinancialUpdateBtnAction}">
<f:param name="mrn" value="#{pc_SocialServicesView.mrn}" />
</h:commandButton>
</h:form>
The action method:
public String doFinancialUpdateBtnAction() {
System.out.println("I am at doFinancialUpdateBtnAction");
try{
if(mrn.length()==0){
mrn=getFacesContext().getExternalContext().getRequestParameterMap().get("mrn");
}
setFinancialListBean(dba.updateFinancialAsistance
(getFinancialListBean(), mrn));
setErrorMsgBean("Updated successfully ...");
doInit(mrn);
}catch (Exception e) {
System.out.println("There is an exception at doFinancialUpdateBtnAction");
Log.out.error("Error in doFinancialUpdateBtnAction: "+e);
setErrorMsgBean("No record was updated ...");
e.printStackTrace();
}
return "";
}