I want to delete selected row from data table when click on GraphicImage under CommandLink.
but it is don't work for me.
it gives error :-
/privilegepage.xhtml #66,21 action="#{privilegeManagedBean.deleteAction(p)}" Failed to parse the expression [#{privilegeManagedBean.deleteAction(p)}]
Bean:-Privilege
public class Privilege {
private int id;
private String privilege;
public Privilege() {
}
public Privilege(int id, String privilege) {
this.id = id;
this.privilege = privilege;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrivilege() {
return privilege;
}
public void setPrivilege(String privilege) {
this.privilege = privilege;
}
}
bean:- PrivilegeDao.java
public int deletePrivilege(int id) {
PreparedStatement preparedStatement = null;
String sqlprivilege;
Connection dbConnection = null;
int pinsert = 0;
try {
sqlprivilege = "delete privilege from privilege where id=?";
dbConnection = ConnectionDao.getDBConnection();
preparedStatement = dbConnection.prepareStatement(sqlprivilege);
preparedStatement.setInt(2, id);
if(preparedStatement.executeUpdate()==1)
pinsert=1;
else
pinsert=0;
System.out.println("privilege is delete :- ");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dbConnection != null) {
try {
dbConnection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return pinsert;
}
bean :-PrivilegeManagedBean
#ManagedBean(name = "privilegeManagedBean", eager = true)
#SessionScoped
/* #ManagedProperty(value="#param.id") */
public class PrivilegeManagedBean {
private int id;
private String privilege;
private PrivilegeDao pdao;
#SuppressWarnings("unused")
private List<Privilege> privilegeData;
private static int srno;
private int selectedRowIndex = -1;
public PrivilegeManagedBean() {
privilegeData = new ArrayList<Privilege>();
pdao = new PrivilegeDao();
srno = 0;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrivilege() {
return privilege;
}
public void setPrivilege(String privilege) {
this.privilege = privilege;
}
public void setPrivilegeData(List<Privilege> privilegeData) {
this.privilegeData = privilegeData;
}
public List<Privilege> getPrivilegeData() {
return this.privilegeData = pdao.getUserList();
}
public int getSelectedRowIndex() {
return selectedRowIndex;
}
public void setSelectedRowIndex(int selectedRowIndex) {
this.selectedRowIndex = selectedRowIndex;
}
public void addDataTableRow() {
pdao.addRow(this.id, this.privilege);
}
private static ArrayList<Privilege> privilegeList = new ArrayList<Privilege>();
public ArrayList<Privilege> getPrivilegeList() {
return privilegeList;
}
public void setPrivilegeList(ArrayList<Privilege> privilege) {
privilegeList = (ArrayList<Privilege>) pdao.getUserList();
}
public int addAction() {
Privilege privilegeitem = new Privilege(this.id, this.privilege);
privilegeList.add(privilegeitem);
return pdao.addPrivilege(this.privilege);
}
public int deleteAction() {
Privilege privilegeitem = new Privilege(this.id, this.privilege);
privilegeList.remove(privilegeitem);
System.out.println("delete Action...");
return pdao.deletePrivilege(this.id);
}
public int onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Privilege Edited",
((Privilege) event.getObject()).getPrivilege());
FacesContext.getCurrentInstance().addMessage(null, msg);
int pid = pdao.getPrivilegeId(this.privilege);
System.out.println("Privilege Name For Id :- " + this.privilege);
System.out.println("Privilege Id :- " + pid);
return pdao.updatePrivilege(pid, this.privilege);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Privilege Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
privilegeList.remove((Privilege) event.getObject());
}
public String deletePrivilege(Privilege privilege) {
privilegeList.remove(privilege);
return null;
}
public int getSrno() {
return ++srno;
}
}
Privilege.xhtml
<p:growl id="messages" showDetail="true" />
<p:dataTable value="#{privilegeDao.userList}" var="p"
id="datatbldispprivilege" style="width:500px" editable="true" lazy="true">
<f:facet name="header">
Privilege List
</f:facet>
<p:ajax event="rowEdit" listener="#{privilegeManagedBean.onEdit}"
update=":form1:messages" />
<p:ajax event="rowEditCancel"
listener="#{privilegeManagedBean.onCancel}" update=":form1:messages" />
<p:column headerText="Privileges Name">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{p.privilege}" name="privilegeoutputname" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{privilegeManagedBean.privilege}"
name="privilegeinputname" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options" style="width:100px">
<p:rowEditor>
</p:rowEditor>
</p:column>
<p:column headerText="Delete" style="width:100px">
<p:commandLink action="#{privilegeManagedBean.deleteAction(p)}"
update="#form">
<p:graphicImage value="/images/deleteicon.png" library="images"
onclick="if (!confirm('Are you sure you want to delete the current record?')) return false"
width="20px" height="20px" />
<f:param name="pname" value="#{p.name}" />
</p:commandLink>
</p:column>
</p:dataTable>
Your PrivilegeManagedBean#deleteAction don't accepts any arguments, but your JSF code passes the current iteration of the data table value to the method. So either don't pass anything to the method:
<p:commandLink action="#{privilegeManagedBean.deleteAction()}" update="#form">
or change the method signature of PrivilegeManagedBean#deleteAction.
you're trying to call the wrong method. action should be like this:
<p:commandLink action="#{privilegeManagedBean.deletePrivilege(p)}" update="#form">
Related
i am uploading multiple images through p:fileUpload and showing uploaded images in datagrid but after upload the blank panel is created inside datagrid
<p:panelGrid columns="1" layout="grid" style="width: 1000px">
<p:outputLabel value="Upload Images"></p:outputLabel>
<p:fileUpload mode="advanced" multiple="false"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" dragDropSupport="true"
update="messages,updimgsfields,carouselcomp" sizeLimit="100000"
fileUploadListener="#{drawingattachmnt.handleFileUpload}"></p:fileUpload>
<!-- <p:graphicImage id="gimPhoto" value="#{fileuploadSection.image}" /> -->
</p:panelGrid>
<p:fieldset id="updimgsfields" legend="Uploaded Images">
<p:dataGrid id="updimgsdatagrid" var="upldimg"
value="#{drawingattachmnt.uploadedimages}" columns="4">
<p:panel id="drawingattachmntpnl" header="#{upldimg.displayId}"
style="text-align:center">
<h:panelGrid columns="1" cellpadding="5"
style="width: 100%; height: 200px;">
<p:graphicImage value="#{upldimg.imgcontent}" cache="false"
stream="true">
<f:param id="imgId" name="photo_id" value="#{upldimg.id}" />
</p:graphicImage>
</h:panelGrid>
</p:panel>
<p:draggable for="drawingattachmntpnl" revert="true"
handle=".ui-panel-titlebar" stack=".ui-panel" />
</p:dataGrid>
</p:fieldset>
// file upload function inside bean
public void handleFileUpload(final FileUploadEvent event) throws IOException {
if (event.getFile().getContents() != null) {
final ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
BufferedImage uploadedImage = null;
byte[] imageBytes = null;
try {
final String imageType = event.getFile().getContentType() != null
|| event.getFile().getContentType().split("/") != null ? event.getFile().getContentType()
.split("/")[1] : "jpeg";
uploadedImage = ImageIO.read(event.getFile().getInputstream());
ImageIO.write(uploadedImage, imageType, byteArrOutputStream);
imageBytes = byteArrOutputStream.toByteArray();
updimg.setImgcontent(new DefaultStreamedContent(new ByteArrayInputStream(imageBytes), imageType));
updimg.setId(UUID.randomUUID().toString().substring(0, 8));
updimg.setDisplayId("FIG: ");
uploadedimages.add(updimg);
} catch (final IOException io) {
} finally {
try {
byteArrOutputStream.close();
// imageInputStream.close();
} catch (final IOException e1) {
e1.printStackTrace();
}
uploadedImage.flush();
}
final FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful", "File uploaded Successfully "));
}
// List POJO
import org.primefaces.model.StreamedContent;
public class UploadImage {
public String displayId;
public String id;
public StreamedContent imgcontent;
public UploadImage() {
}
public UploadImage(final String id, final String displayId, final StreamedContent imgcontent) {
this.id = id;
this.displayId = displayId;
this.imgcontent = imgcontent;
}
#Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final UploadImage other = (UploadImage) obj;
if (this.id == null ? other.id != null : !this.id.equals(other.id)) {
return false;
}
return true;
}
public String getDisplayId() {
return displayId;
}
public String getId() {
return id;
}
public StreamedContent getImgcontent() {
return imgcontent;
}
#Override
public int hashCode() {
int hash = 7;
hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
public void setDisplayId(final String displayId) {
this.displayId = displayId;
}
public void setId(final String id) {
this.id = id;
}
public void setImgcontent(final StreamedContent imgcontent) {
this.imgcontent = imgcontent;
}
}
I need to show images in datagrid dynamically, but i am getting blank image panel inside datagrid. what should be done ?
I have a problem selecting a row from a datatable in PrimeFaces. My selected object in the managed bean is null. For some reason, selected object from the datatable is not setting up correctly the property selectedItinerary in my managed bean.
<p:dataTable id="singleDT" value="#{travellerSearchFlightsManagedBean.searchList}" var="s" selectionMode="single" selection="#{travellerSearchFlightsManagedBean.selectedItinerary}" rowKey="#{s.iden}" >
<f:facet name="header">
Found itineraries
</f:facet>
<p:column headerText="Departure Location">
<h:outputText value="#{s.departureLocation}" />
</p:column>
<p:column headerText="Arrival Location">
<h:outputText value="#{s.arrivalLocation}" />
</p:column>
<p:column headerText="Departure Date">
<h:outputText value="#{s.departureDate}" />
</p:column>
<p:column headerText="Cost">
<h:outputText value="#{s.cost}" />
</p:column>
<p:column headerText="Stops">
<h:outputText value="#{s.stopPrint}" />
</p:column>
<f:facet name="footer">
<p:commandButton process="singleDT" value="Reserve itinerary" action="#{travellerSearchFlightsManagedBean.reserveFlight()}" />
</f:facet>
</p:dataTable>
and the managed bean is like this:
#Named(value = "travellerSearchFlightsManagedBean")
#RequestScoped
public class travellerSearchFlightsManagedBean{
#EJB
private itineraryTravellerFacadeLocal itineraryTravellerFacade;
#EJB
private itineraryFacadeLocal itineraryFacade;
#ManagedProperty(value="#{travellerLoginManagedBean}")
private travellerLoginManagedBean loginBean;
private String departureLocation;
private String arrivalLocation;
private Date departureDate;
private int departureHour;
private int departureMinute;
private int numPassengers;
private int maxStops;
private String economyOrBusiness;
private ArrayList<itineraryDTO> itinerariesList;
private ArrayList<itineraryTraveller> searchList;
private itineraryTraveller selectedItinerary;
private String stopPrint;
private static final Logger LOG = Logger.getLogger(travellerSearchFlightsManagedBean.class.getName());
public String getStopPrint() {
return stopPrint;
}
public travellerLoginManagedBean getLoginBean() {
return loginBean;
}
public void setLoginBean(travellerLoginManagedBean loginBean) {
this.loginBean = loginBean;
}
public void setStopPrint(String stopPrint) {
this.stopPrint = stopPrint;
}
public itineraryTraveller getSelectedItinerary() {
return selectedItinerary;
}
public void setSelectedItinerary(itineraryTraveller selectedItinerary) {
this.selectedItinerary = selectedItinerary;
}
public ArrayList<itineraryTraveller> getSearchList() {
return searchList;
}
public void setSearchList(ArrayList<itineraryTraveller> searchList) {
this.searchList = searchList;
}
public ArrayList<itineraryDTO> getItinerariesList() {
return itinerariesList;
}
public void setItinerariesList(ArrayList<itineraryDTO> itinerariesList) {
this.itinerariesList = itinerariesList;
}
public itineraryFacadeLocal getItineraryFacade() {
return itineraryFacade;
}
public String getEconomyOrBusiness() {
return economyOrBusiness;
}
public void setEconomyOrBusiness(String economyOrBusiness) {
this.economyOrBusiness = economyOrBusiness;
}
public void setItineraryFacade(itineraryFacadeLocal itineraryFacade) {
this.itineraryFacade = itineraryFacade;
}
public String getDepartureLocation() {
return departureLocation;
}
public void setDepartureLocation(String departureLocation) {
this.departureLocation = departureLocation;
}
public String getArrivalLocation() {
return arrivalLocation;
}
public void setArrivalLocation(String arrivalLocation) {
this.arrivalLocation = arrivalLocation;
}
public Date getDepartureDate() {
return departureDate;
}
public void setDepartureDate(Date departureDate) {
this.departureDate = departureDate;
}
public int getDepartureHour() {
return departureHour;
}
public void setDepartureHour(int departureHour) {
this.departureHour = departureHour;
}
public int getDepartureMinute() {
return departureMinute;
}
public void setDepartureMinute(int departureMinute) {
this.departureMinute = departureMinute;
}
public int getNumPassengers() {
return numPassengers;
}
public void setNumPassengers(int numPassengers) {
this.numPassengers = numPassengers;
}
public int getMaxStops() {
return maxStops;
}
public void setMaxStops(int maxStops) {
this.maxStops = maxStops;
}
public travellerSearchFlightsManagedBean() {
}
public void searchFlights(){
try{
int numPassengersEconomy=0;
int numPassengersBusiness=0;
if (economyOrBusiness.equals("Economy")){
numPassengersEconomy=numPassengers;
}else{
numPassengersBusiness=numPassengers;
}
searchList = new ArrayList<itineraryTraveller>();
itinerariesList= new ArrayList<itineraryDTO>();
int id=itineraryFacade.findItineraries(itinerariesList,departureLocation, arrivalLocation,departureDate,numPassengersEconomy, numPassengersBusiness);
searchList=itineraryFacade.listItineraries(maxStops,itinerariesList,arrivalLocation, departureLocation, numPassengersEconomy, numPassengersBusiness);
} catch(NullPointerException e) {}
}
public void reserveFlight(){
//if (){
try{
//status reserved when traveller reserves an itinerary
selectedItinerary.setStatus('r');
//set the userName from the user who reserved this itinerary before persist it in a shared among all users db
//persist the reserved itinerary in the db
itineraryTravellerFacade.create(selectedItinerary);
} catch(NullPointerException e) {}
}
}
I want to download file in my jsf page, and below is my jsf page
<h:form id="MyListForm">
<p:commandButton value="Attachments" icon="ui-icon-transferthick-e-w" actionListener="#{myTeam.downloadImageDialogue}"
style="font-size: 10px;font-weight: bolder;vertical-align: text-bottom;width: 80px;" >
</p:commandButton>
</h:form>
and my bean code is:
public void downloadImageDialogue() {
RequestContext.getCurrentInstance().openDialog("AttachmentDialog");
}
and my dilogue xhtml page is:
<h:body>
<h:form>
<p:dataTable var="Attachment" value="#{attachmentDialogView.attachmentList}" rows="10">
<p:column headerText="File Name">
<h:outputText value="#{Attachment.fileName}" />
</p:column>
<p:column headerText="Download Attachment">
<p:commandLink ajax="false" id="dwldLink" action="#{attachmentDialogView.downloadImage}">
<f:setPropertyActionListener value="#{Attachment.id.itemId}" target="#{attachmentDialogView.imageItemId}" />
<f:setPropertyActionListener value="#{Attachment.fileName}" target="#{attachmentDialogView.fileName}" />
<f:setPropertyActionListener value="#{Attachment.id.callId}" target="#{attachmentDialogView.callID}" />
<p:graphicImage value="images/dnld1.png" width="25" height="25"/>
<p:fileDownload value="#{attachmentDialogView.file}"/>
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
</h:body>
and bean code is:
#ManagedBean(name = "attachmentDialogView")
#ViewScoped
public class AttachmentDialogView implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Attachment> attachmentList;
private String imageItemId;
private String fileName;
private DefaultStreamedContent file;
String callID;
#ManagedProperty("#{myTeamService}")
private MyTeamService service;
#PostConstruct
public void init() {
attachmentList = service.getAttachmentList(service.getCallId());
}
public void downloadImage() {
Session session = HibernateUtil.getSessionFactory().openSession();
Attachment attachment = null;
byte[] bImage;
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
try {
if (getCallID() == null || getCallID().equals("")) {
RequestContext.getCurrentInstance().execute("PF('check_dialog').show()");
} else {
attachment = (Attachment) session.createCriteria(Attachment.class).add(Restrictions.eq("id.itemId", getImageItemId())).add(Restrictions.eq("id.callId", getCallID())).uniqueResult();
bImage = attachment.getFileData();
InputStream stream = new ByteArrayInputStream(bImage);
file = new DefaultStreamedContent(stream,externalContext.getMimeType(getFileName()),getFileName());
}
} catch (Exception ex) {
ex.printStackTrace();
}finally {
session.close();
}
}
public List<Attachment> getAttachmentList() {
return attachmentList;
}
public void setAttachmentList(List<Attachment> attachmentList) {
this.attachmentList = attachmentList;
}
public MyTeamService getService() {
return service;
}
public void setService(MyTeamService service) {
this.service = service;
}
public String getImageItemId() {
return imageItemId;
}
public void setImageItemId(String imageItemId) {
this.imageItemId = imageItemId;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public DefaultStreamedContent getFile() {
return file;
}
public void setFile(DefaultStreamedContent file) {
this.file = file;
}
public String getCallID() {
return callID;
}
public void setCallID(String callID) {
this.callID = callID;
}
}
here dilogue opens correctly but image will not opened please help me.
I am using primefaces For displaying a datagrid of datatables as follow -
Facelets page:
<h:form name="form">
<p:dataGrid value="#{routeEditingBean.routes}" var="route"
columns="1">
<p:column>
<h:outputText value="#{route.routeId}" />
</p:column>
<p:dataTable value="#{route.routeDetailses}" var="rd"
rowKey="rd.id.employeeId"
selection="#{routeEditingBean.selectedRouteDetails}">
<p:column>
<h:outputText value="#{rd.id.employeeId}" />
</p:column>
<p:column selectionMode="multiple">
</p:column>
</p:dataTable>
<p:commandLink process="#all"
actionListener="#{routeEditingBean.display()}">
<p:graphicImage library="images" name="add-car.jpg"></p:graphicImage>
</p:commandLink>
</p:dataGrid>
</h:form>
Backing-bean:
#ManagedBean
#ViewScoped
public class RouteEditingBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
List<RouteMaster> routes;
List<RouteDetails> selectedRouteDetails;
RouteMaster delrb;
public RouteEditingBean() {
// TODO Auto-generated constructor stub
routes = new ArrayList<RouteMaster>();
Session session = HibernateUtil.getSessionFactory().openSession();
org.hibernate.Transaction transaction = null;
try {
HttpSession httpsession = (HttpSession) FacesContext
.getCurrentInstance().getExternalContext()
.getSession(false);
LoginBean lb = (LoginBean) httpsession.getAttribute("loginBean");
transaction = session.beginTransaction();
Criteria c = session.createCriteria(RouteMaster.class);
List routeMasterList = c.list();
for (Iterator iterator = routeMasterList.iterator(); iterator
.hasNext();) {
RouteMaster routeMaster = (RouteMaster) iterator.next();
System.out.println(routeMaster.getRouteId());
c = session.createCriteria(RouteDetails.class);
c.add(Restrictions.eq("id.routeId", routeMaster.getRouteId()));
Set<RouteDetails> routeDetailses = new HashSet<RouteDetails>();
for (Iterator iterator1 = c.list().iterator(); iterator1
.hasNext();) {
RouteDetails rd = (RouteDetails) iterator1.next();
routeDetailses.add(rd);
}
routeMaster.setRouteDetailses(routeDetailses);
routes.add(routeMaster);
}
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
public List<RouteMaster> getRoutes() {
return routes;
}
public void setRoutes(List<RouteMaster> routes) {
this.routes = routes;
}
public RouteMaster getDelrb() {
return delrb;
}
public void setDelrb(RouteMaster delrb) {
this.delrb = delrb;
}
public List<RouteDetails> getSelectedRouteDetails() {
return selectedRouteDetails;
}
public void setSelectedRouteDetails(List<RouteDetails> selectedRouteDetails) {
this.selectedRouteDetails = selectedRouteDetails;
}
public void deleteEmployee(RouteMaster rm, RouteDetails rd) {
System.out.println(rm.getRouteId());
System.out.println(rd.getId().getEmployeeId());
}
public void display() {
System.out.println("Inside display");
if (selectedRouteDetails == null) {
System.out.println("No selection");
} else {
for (Iterator iterator = selectedRouteDetails.iterator(); iterator
.hasNext();) {
RouteDetails rd1 = (RouteDetails) iterator.next();
System.out.println(rd1.getId().getEmployeeId());
}
}
}
}
When form is Submitted then selected values are returning null. I want to get selected values for all dataTable in dataGrid. Please help.
can you try it this way
List<RouteDetails> selectedRouteDetails = new ArrayList<RouteDetails>();
or
public RouteEditingBean() {
selectedRouteDetails = new ArrayList<RouteDetails>();
.....
}
I'm starting with primefaces and I try use LazyModel in p:dataTable.
I already implemented the LazyModel, bean and jsf. The call's to bean and model occur's correctly and my bean return a list with elements, but my jsf show nothing.
Please, somebody know whats happen?
Bellow is my code:
JSF:
<ui:composition template="./newTemplate.xhtml">
<ui:define name="content">
content
<h:form>
<p:panel id="formFiltro">
<p:messages id="messages"/>
<h:panelGrid>
<h:outputLabel for="fieldConta" value="Número da Conta:"/>
<p:inputText id="fieldConta" value="#{log.nrConta}" label="Número da Conta">
<f:convertNumber integerOnly="true" type="number"/>
</p:inputText>
<!--<p:message for="fieldConta" />-->
<h:outputLabel for="fieldAgencia" value="Código da Agência:"/>
<p:inputText id="fieldAgencia" value="#{log.nrAgencia}" label="Código da Agência">
<f:convertNumber integerOnly="true" type="number"/>
</p:inputText>
<!--<p:message for="fieldAgencia" />-->
<center>
<p:commandButton ajax="false" value="Pesquisar" action="#{log.search}" />
</center>
</h:panelGrid>
</p:panel>
<p:dataTable var="l" value="#{log.lazyLogModel}" paginator="true" rows="5"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" id="logTable" lazy="true">
<p:column headerText="ID">
<h:outputText value="#{l.logId}" />
</p:column>
<p:column headerText="Agência">
<h:outputText value="#{l.logAgencia}" />
</p:column>
<p:column headerText="Conta">
<h:outputText value="#{l.logConta}" />
</p:column>
<p:column headerText="SO">
<h:outputText value="#{l.logSo}" />
</p:column>
<p:column headerText="Plugin">
<h:outputText value="#{l.logVersaoPlugin}" />
</p:column>
<p:column headerText="Tam F10">
<h:outputText value="#{l.logTamF10}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
My bean:
#ManagedBean(name="log")
#RequestScoped
public class consultaJsf implements Serializable {
private static final long serialVersionUID = 1L;
/**
* Creates a new instance of consultaJsf
*/
private List<TbLogLog> listaLog;
private LazyLogModel lazyLogModel;
private int nrConta;
private int nrAgencia;
public consultaJsf() {
try{
//this.listaLog = new ConsultarDados().getListLogAll();
}catch(Exception e){
e.printStackTrace();
}
}
#PostConstruct
public void init()
{
this.lazyLogModel = new LazyLogModel();
}
public List<TbLogLog> getListaLog()
{
return listaLog;
}
public int getNrConta()
{
return nrConta;
}
public void setNrConta(int nrConta)
{
this.nrConta = nrConta;
}
public int getNrAgencia()
{
return nrAgencia;
}
public void setNrAgencia(int nrAgencia)
{
this.nrAgencia = nrAgencia;
}
public LazyLogModel getLazyLogModel()
{
return this.lazyLogModel;
}
public String search() throws Exception
{
if(nrConta != 0)
this.listaLog = new ConsultarDados().getListLogByConta(nrConta);
else if(nrAgencia != 0)
this.listaLog = new ConsultarDados().getListLogByAgencia(nrAgencia);
return null;
}
}
My LazyModel:
public class LazyLogModel extends LazyDataModel<TbLogLog> {
private String nrConta;
private String cdAgencia;
#Override
public List<TbLogLog> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
List<TbLogLog> listaLog = null;
try{
listaLog = new ConsultarDados().getListLogAll(first, pageSize);
}catch(Exception e){
return null;
}
return listaLog;
}
/**
* #return the nrConta
*/
public String getNrConta() {
return nrConta;
}
/**
* #param nrConta the nrConta to set
*/
public void setNrConta(String nrConta) {
this.nrConta = nrConta;
}
/**
* #return the cdAgencia
*/
public String getCdAgencia() {
return cdAgencia;
}
/**
* #param cdAgencia the cdAgencia to set
*/
public void setCdAgencia(String cdAgencia) {
this.cdAgencia = cdAgencia;
}
}
Consult Method called by LazyModel:
private List<TbLogLog> getListLog(String hql, int firstResult, int sizePage) throws Exception {
List resultList = null;
try {
Session session = HubernateUtil.getSessionFactory().openSession();
if ((hql == null) || (hql.trim().length() == 0)) {
hql = QUERY_PESQUISAR_TODOS;
}
Query q = session.createQuery(hql);
if(firstResult > 0 )
q.setFirstResult(firstResult);
if(sizePage > 0)
q.setMaxResults(sizePage);
resultList = q.list();
} catch (HibernateException he) {
he.printStackTrace();
}
return resultList;
}
Everything work's fine, but my jsf don't show any result.
Thanks in advance.
Remove the init() in consultaJsf Class and update the getLazyLogModel() as follows
#ManagedBean(name="log")
#RequestScoped
public class consultaJsf implements Serializable {
private static final long serialVersionUID = 1L;
/**
* Creates a new instance of consultaJsf
*/
private List<TbLogLog> listaLog;
private LazyLogModel<TbLogLog> lazyLogModel;
private int nrConta;
private int nrAgencia;
public consultaJsf() {
try{
//this.listaLog = new ConsultarDados().getListLogAll();
}catch(Exception e){
e.printStackTrace();
}
}
public List<TbLogLog> getListaLog()
{
return listaLog;
}
public int getNrConta()
{
return nrConta;
}
public void setNrConta(int nrConta)
{
this.nrConta = nrConta;
}
public int getNrAgencia()
{
return nrAgencia;
}
public void setNrAgencia(int nrAgencia)
{
this.nrAgencia = nrAgencia;
}
public LazyLogModel<TbLogLog> getLazyLogModel()
{
if (lazyLogModel== null) {
lazyLogModel= new LazyDataModel<TbLogLog>() {
#Override
public List<TbLogLog> load(int first, int pageSize, String sortField,
SortOrder sortOrder, Map<String, String> filters) {
List<TbLogLog> listaLog = null;
try{
listaLog = new ConsultarDados().getListLogAll(first, pageSize);
}catch(Exception e){
return null;
}
return listaLog;
}
};
}
return listaLog;
}
public String search() throws Exception
{
if(nrConta != 0)
this.listaLog = new ConsultarDados().getListLogByConta(nrConta);
else if(nrAgencia != 0)
this.listaLog = new ConsultarDados().getListLogByAgencia(nrAgencia);
return null;
}
}