Good evening from Sweden!
I try to get a primefaces datatable to refresh. I tried various hints and solutions but nothing is working.
The button triggers a search in the DB and if I refresh the paga manually or if I use the tables sorting-function the result is shown.
Means the code in the backing bean works. But no automatic refresh directly after the button is clicked..
The bean scope is Session.
Here is the page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<ui:composition template="/templates/BasicTemplate.xhtml">
<ui:define name="content">
<h:form id="src_res">
<h2>Sök klass,undervisningsgrupp eller individ</h2>
<b>Sökord</b>: <h:inputText id="sw" value="#{smsb.searchword}"/>
<p:outputLabel value="Lärare"></p:outputLabel>
<h:selectOneListbox size="1" id="teacher" value="#{smsb.searchteacher}" >
<f:selectItems value="#{smsb.teachers}"/>
</h:selectOneListbox>
<p:commandButton action="#{smsb.searchgrp_user}" value="Sök!" update="src_list"/>
<p:dataTable id="src_list" value="#{smsb.searchresult}" var="obj" >
<p:column width="20%" sortBy="#{obj.groupname}">
<f:facet name="header" >
<h:outputText value="Beteckning"/>
</f:facet>
<h:outputText value="#{obj.groupname}"/>
</p:column>
<p:column width="10%">
<f:facet name="header" >
<h:outputText value="typ"/>
</f:facet>
<h:outputText value="#{obj.klass}"/>
</p:column>
<p:column width="10%" sortBy="#{obj.teacher}">
<f:facet name="header" >
<h:outputText value="lärare"/>
</f:facet>
<h:outputText value="#{obj.teacher}"/>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
Any help or hints?
With regards
Ralf
EDIT
Hello and thanx for the offer to help!
As you guessed searchresult is a list and the Getter is defined by
List<sbasUserList> searchresult;
public List<sbasUserList> getSearchresult() {
return searchresult;
}
search_grp is a method of the backing bean:
public String searchgrp_user(){
//FacesContext context = FacesContext.getCurrentInstance();
ObjectContainer db = this.connBD("sms");
ObjectSet<sbasUserList> res;
this.searchresult = new ArrayList<sbasUserList>() ;
Query query=db.query();
query.constrain(sbasUserList.class);
query.descend("groupname").constrain(this.searchword).like();
query.descend("type").constrain('P').or(query.descend("type").constrain('M'));
query.descend("teacher").constrain(searchteacher).contains();
res = query.execute();
this.searchresult.addAll(res);
System.out.println(this.searchresult.size());
db.close();
return "";
}
The table is filled with the right dat if i update manually the browser. (F5) but certainly would like to have this done automatically.
Sorry folks! The glassfish server I was using wasn't setup right. It showed not all of the errors in the log file. I did a complete new setup of the whole IDE (new Eclipse, new glassfish server, thanx BalusC for the incredible tutorial!!!) and I found all errors. Now it works like it should!
Regards
Ralf
Related
I want to export a data table in csv,pdf format in primefaces 4.0 .For that I used following code :
<p:dataTable var="valuesTable" value="#{userBean.groupResultList}"
paginator="false" id="valuesTable" resizableColumns="true"
rendered="#{not empty userBean.groupResultList}">
<p:column headerText="Group" id="grp"> #{valuesTable.groupName}</p:column>
<p:column headerText="Technical Knowledge" id="tk">
#{valuesTable.tkValue}
</p:column>
<p:column headerText="Project Management" id="pm">
#{valuesTable.pmValue}
</p:column>
<p:column headerText="Growth" id="ga">
#{valuesTable.gaValue}
</p:column>
<f:facet name="footer">
<h:commandLink>
<p:graphicImage value="/images/xml.jpeg" width="20" height="20" />
<p:dataExporter target="valuesTable" type="xml" fileName="Data_XML" />
</h:commandLink>
</f:facet>
</p:dataTable>
Data table displays correct data in each cell when I run the application.
But when I try to export it in csv or pdf format, rather then exporting actual numbers (or values of the object) it is exporting "#{valuesTable.groupName}" "#{valuesTable.tkValue}" ,"#{valuesTable.pmValue}" ,"#{valuesTable.gaValue}" for each object in csv file.
CSV file Content :
#{valuesTable.groupName} #{valuesTable.tkFormatedValue} #{valuesTable.pmFormatedValue} #{valuesTable.gaFormatedValue}
Data Table Content :
Group Name Technical Knowledge Project Management Growth
India .8 .7 1.0
I don not know why it is exporting the data table in this way..
Please Help
Thanks
I had a similar problem once with the dataTable exporter.
You have to use an outputText like this:
<h:outputText value="#{valuesTable.tkValue}"/>
inside all the column tags, in order to see the values properly.
Your column would become:
<p:column headerText="Technical Knowledge" id="tk">
<h:outputText value="#{valuesTable.tkValue}"/>
</p:column>
Replace all your columns and try that!
Hope it helps!
And also I think the headers are not ok. You have to use an f:facet tag like this:
<p:column id="tk">
<f:facet name="header">
<h:outputText value="Technical Knowledge" />
</f:facet>
<h:outputText value="#{valuesTable.tkValue}"/>
</p:column>
Now you should also see the headers in the export CSV file.
DataTable export is not working in Primefaces 4.0
Step 1: You need to add jars for exporting csv ,pdf file .
itext-1.1.4.jar
Step 2: DataExplorar.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<p:panel header="Generate Report ">
<div>
<h:commandLink>
<p:graphicImage value="/images/pdf.png"
style="width:30px; hight:30px;" />
<p:dataExporter type="pdf" target="tb1"
fileName="fileName" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/excel.png"
style="width:25px; hight:30px;" />
<p:dataExporter type="xls" target="tb1"
fileName="fileName" />
</h:commandLink>
</div>
</p:panel>
I am trying to write a simple pdf export functionality using primefaces p:dataExporter. My Code is as below
my development environment is JSF-2.0, Primefaces-3.4.2, Eclips- JUNO, GlassFish
xhtml page
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
>
<h:head>
<title>Pdf Export</title>
</h:head>
<h:body>
<h:form id="myForm" >
<p:dataTable id="tableId" var="car" value="#{tableBean.carsSmall}">
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
</p:dataTable>
<h:commandLink ajax="false" >
<p:graphicImage library="images" name="pdf.png" width="40" height="40" />
<p:dataExporter target="tableId" type="pdf" fileName="car"></p:dataExporter>
</h:commandLink>
</h:form>
</h:body>
</html>
my dataTable is populated correctly there is no issue there but when I click for Export nothing happens. Console also doesn't give any message. I have kept iTextpdf-5.4.0.jar and poi-3.2-FINAL.jar in my webapp library. Do I need to do anything else here? Please give me some idea what I am missing?
EDIT-1
I tried using iTextpdd-2.1.7 as suggested in the comment below but still the same problem exist and I am not able to export to pdf.
When I click export the console gives me warning message as below. Is this warning message creating any problem in the export
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context
/{project name}, because request parameters have already been read, or
ServletRequest.getReader() has already been called
EDIT-2
Today I tried the same code in RAD-Wehsphere/iText 2.1.7 and Export is working fine in that environment. I am able to export dataTable in the pdf file. There must be something that is missing in the Eclips- JUNO, GlassFish environment.
TIA
launcher.xhtml
this form uses "thing"
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:custom="http://java.sun.com/jsf/composite/components">
<h:form id="form">
<p:panelGrid
id="pgid"
columns="2">
<h:outputText value="title"/>
<h:outputText value="#{bean.value}"/>
</p:panelGrid>
<custom:thing
via="#{bean.via1}"
viaListener="#{bean.via2Listener()}"
vias="#{bean.vias1}">
</h:form>
thing.xhtml
<p:selectOneMenu
process="#this"
value="#{cc.attrs.via}">
<p:ajax
listener="#{cc.attrs.viaListener}"
update="form:pgid"
/>
<f:selectItems value="#{cc.attrs.vias}"/>
</p:selectOneMenu>
faces can´t find form:pgid. tried with and without prepending "form". thanks
Relative client IDs (those not starting with :) are searched relative to the parent NamingContainer component, which is in your case the composite component itself. So it's looking for form:pgid in the context of <cc:implementation>.
You need to prefix the client ID with : (the default NamingContainer separator character) to make it absolute to the view root.
<p:ajax ... update=":form:pgid" />
See also:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
This question already has answers here:
Binding attribute causes duplicate component ID found in the view
(2 answers)
Closed 7 years ago.
I have a XHTML page which on submission goes back to itself.
The backing bean is session scoped. On the redirect to itself the page renders the h:datatable twice and gives me duplicate id error.I can visually see the table being rendered twice as well next to each other.
** xhtml page :**
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:form >
<h:dataTable binding="#{ecole.dataTable}" value="#{ecole.getEcoleList()}" var="c"
border="0" width="100%" cellpadding="0" cellspacing="0"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
<h:column>
<f:facet name="header">
ID
</f:facet>
#{c.idEcole}
</h:column>
<h:column>
<f:facet name="header">
Nom
</f:facet>
#{c.nomEcole}
</h:column>
<h:column>
<f:facet name="header">
Description
</f:facet>
#{c.desc_ecl}
</h:column>
<h:column>
<f:facet styleclass="options-width" name="header">
Options
</f:facet>
<h:commandLink action="#{ecole.editEcoleItem()}" title="Edit" >
<h:graphicImage style="border:0" url="/icones/b_edit.png" />
</h:commandLink>
<h:commandLink title="Delete"
onclick="return confirm('Voulez-vous confirmer la suppression?') ;"
action="#{ecole.deleteEcole(c)}"
>
<h:graphicImage style="border:0" url="/icones/b_drop.png" />
</h:commandLink>
</h:column>
</h:dataTable>
<!-- end product-table................................... -->
</h:form>
</f:view>
this is error message shown :
java.lang.IllegalStateException: Component ID j_id15:j_id16:j_id29 has already been found in the view. See below for details.
+id: null
type: javax.faces.component.UIViewRoot#1abe6f6
+id: javax_faces_location_HEAD
type: javax.faces.component.UIPanel#c84a5d
+id: j_id4
type: javax.faces.component.UIOutput#18a5776
+id: j_id22
type: javax.faces.component.UIOutput#1742dcc
+id: j_id19
...
The binding attribute should bind to a request scoped bean or just be removed altogether and be replaced by a better alternative, depending on the concrete functional requirement.
If I get the functional requirement right of being able to retrieve the current item in the editEcoleItem() method, then you can just pass it directly as method argument, exactly as you did in deleteEcole(). This way you can just remove the binding attribute altogether. That's the JSF 2.0 / EL 2.2 way. Perhaps you were focusing too much on old JSF 1.x examples. You shouldn't do that when developing with JSF 2.x.
See also:
A JSF 2.0 CRUD example
How can I pass selected row to commandLink inside dataTable?
I am new to Java Web. I am using netbeans 7.0.1 and glassfish 3 to develop a web application. I am almost through with all data input and Now I want to create reports & graph. Requirement is to create charts (pie/bar/line based on user selection) with dynamic data (from database / datatable user can apply filters on data). I tried using Primefaces but it gives below error with simple example given in primeface show case:
javax.faces.event.AbortProcessingException:
/pages/analyst/analyse.xhtml #65,151
actionListener="#{analysis.bar()}": java.lang.NoClassDefFoundError:
org/primefaces/component/chart/series/ChartSeries
I have a jsf page that holds datatable backed by managedbean of viewscope. below is my code:
page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<ui:composition template="./../../WEB-INF/Templates/VUTemplate.xhtml">
<ui:define name="menu">
<h:form id="home">
<p:menu>
<p:menuitem value="Home Page" url="../home.xhtml" />
</p:menu>
</h:form>
</ui:define>
<ui:define name="content">
<h:form id="form" prependId="false">
<p:growl id="growl" showDetail="true"/>
<p:barChart id="basic" value="#{analysis.categoryModel}" legendPosition="ne"
title="Basic Bar Chart" min="0" max="200" style="height:300px"/>
<p:dataTable id="table" var="var" widgetVar="wbTable"
value="#{analysis.list}"
paginator="true" rows="10"
paginatorPosition="bottom"
emptyMessage="No data found with given criteria"
>
<f:facet name="header">
World Bank Open Data Analysis
</f:facet>
<p:column filterBy="#{var.regionFullName}" sortBy="#{var.regionFullName}"
headerText="Region" footerText="Enter starting characters" >
<h:outputText value="#{var.regionFullName}" />
</p:column>
<p:column filterBy="#{var.countryFullName}" sortBy ="#{var.countryFullName}"
headerText="Country" footerText="Enter starting characters" >
<h:outputText value="#{var.countryFullName}" />
</p:column>
<p:column filterBy="#{var.indcatorTypeName}" sortBy ="#{var.indcatorTypeName}"
headerText="Indicator Type" footerText="Enter starting characters" >
<h:outputText value="#{var.indcatorTypeName}" />
</p:column>
<p:column filterBy="#{var.indicatorName}" sortBy ="#{var.indicatorName}"
headerText="Indicator" footerText="contains" filterMatchMode="contains">
<h:outputText value="#{var.indicatorName}" />
</p:column>
<p:column filterBy="#{var.year}" sortBy ="#{var.year}"
headerText="Year" footerText="starts with">
<h:outputText value="#{var.year}" />
</p:column>
<p:column filterBy="#{var.dataValue}" sortBy ="#{var.dataValue}"
headerText="Data Value" footerText="starts with" >
<h:outputText value="#{var.dataValue}" />
</p:column>
</p:dataTable>
<h:panelGrid id="command" columns="6" cellpadding="4" >
<p:commandButton id="line" value="Line" actionListener="#{analysis.line()}" process="#this :form:table" update="result table" >
</p:commandButton>
<p:commandButton id="bar" value="Bar" actionListener="#{analysis.bar()}" process="#this :form:table" update="result table" >
</p:commandButton>
</h:panelGrid>
<p:messages id="result" showDetail="true" autoUpdate="true"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
backbean
import ejb.VwdataFacade;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import model.Vwdata;
import org.primefaces.component.chart.series.ChartSeries;
import org.primefaces.model.chart.CartesianChartModel;
#ManagedBean
#ViewScoped
public class Analysis implements Serializable{
private List<Vwdata> list;
private #EJB VwdataFacade wsvc; //entity services
private CartesianChartModel categoryModel;
public Analysis() {
}
public CartesianChartModel getCategoryModel() {
return categoryModel;
}
#PostConstruct
public void init() {
list = wsvc.findAll();
}
public List<Vwdata> getList() {
// list = wsvc.findAll();
return list;
}
public void line(){
}
public void bar(){
createCategoryModel();
}
private void createCategoryModel() {
categoryModel = new CartesianChartModel();
ChartSeries yaxis = new ChartSeries();
yaxis.setLabel("Label");
yaxis.set("2004",120);
yaxis.set("2005",130);
yaxis.set("2006",140);
yaxis.set("2007",110);
categoryModel.addSeries(yaxis);
}
}
If I place call createCategoryModel in the constructor or init method, I cant even view the page which otherwise was working perfectly without chart code. Any help will be highly appreciated. Thanks
java.lang.NoClassDefFoundError: org/primefaces/component/chart/series/ChartSeries
The mentioned class was introduced in PrimeFaces 3.0 and was thus not available in PrimeFaces 2.x and older.
Given the fact that the PrimeFaces 3.0 specific XML namespace http://primefaces.org/ui and all the <p:xxx> tags in your code did apparently not result in a Facelets compile error, that can only mean that you've both PrimeFaces 2.x and 3.x libraries in your webapp's runtime classpath wherein the 2.x one got precedence in classloading.
Get rid of the offending old PrimeFaces 2.x library from your webapp's runtime classpath and this problem should then disappear.