Hi,
As per SumRow listener documentation
"Method expression to execute before rendering summary row. (e.g. to calculate totals)."
<p:summaryRow listener="#{rBean.setSortProperty}" >
<p:column colspan="#{rBean.sortSpan}" style="text-align:right">
<h:outputText value="Total:" />
</p:column>
<c:forEach items="#{rBean.sumRow}" var="sumcol" >
<p:column >
<h:outputText value="#{sumcol}">
<f:convertNumber maxFractionDigits="2" locale="ru_RU"/>
</h:outputText>
</p:column>
</c:forEach>
the bean
private List<BigDecimal> sumRow =new ArrayList<>(); // sum row val holder
public void setSortProperty(Object o) { // filter value
if (o instanceof String) {
setSortVal((String) o);
try {
sumRowCalc();
} catch (NoSuchMethodException ex) {
Logger.getLogger(rangeBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(rangeBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(rangeBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(rangeBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void sumRowCalc() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
sumRow.clear();
......
In my case inner column values rendered before setSortProperty fires, for ex. first time I click on sort column it shows empty sumrow, next time click it shows values from previous execution
ps
ver. 5.3
Environment:
Hi,
Launching GlassFish on Felix platform
Info: Running GlassFish Version: GlassFish Server Open Source Edition 4.1.1 (build 1)
Info: Running on PrimeFaces 5.3
Info: Running on PrimeFaces Extensions 4.0.0
Info: Grizzly Framework 2.3.23
Info: Initializing Mojarra 2.2.12
SumRow rendered content before listener method fires
Please modify your post according to forum rules.Are you able to replicate the issue on showcase example.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/
___________________
Sudheer Jonna
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/
___________________
Sudheer Jonna
Hi,
I added my environment details in initial post.
I replicated showcase with subtle modifications as follows
<h:form>
<p:dataTable var="car" value="#{dtSummaryRowView.cars}" >
<p:ajax event="sort" listener="#{dtSummaryRowView.onsort}" id="sortev" async="true" >
<f:attribute name="event" value="event" />
</p:ajax>
<p:column headerText="Id" sortBy="#{car.id}">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year" sortBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand" sortBy="#{car.brand}">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color" sortBy="#{car.color}">
<h:outputText value="#{car.color}" />
</p:column>
<p:summaryRow listener="#{dtSummaryRowView.setSortProperty}">
<p:column colspan="3" style="text-align:right">
<h:outputText value="Total:" />
</p:column>
<c:forEach items="#{dtSummaryRowView.randomPrice}" var="sumcol" >
<p:column>
<h:outputText value="#{sumcol}">
</h:outputText>
</p:column>
</c:forEach>
</p:summaryRow>
</p:dataTable>
</h:form>
the bean
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import org.primefaces.event.data.SortEvent;
import service.Car;
@ApplicationScoped
@Named("dtSummaryRowView")
public class SummaryRowView implements Serializable {
private List<Car> cars;
//@ManagedProperty("CarService")
private CarService service=new CarService();
private List<String> testFire = new ArrayList<>();
@PostConstruct
public void init() {
cars = service.createCars(50);
testFire.add("I'm not initialized!");
}
public List<Car> getCars() {
return cars;
}
public void setService(CarService service) {
this.service = service;
}
public List<String> getRandomPrice() {
return testFire;
//return (int) (Math.random() * 100000);
}
public void setSortProperty(Object o) { // filter value
if (o instanceof String) {
testFire.add("set sort: "+(String)o);
}
}
public void onsort(SortEvent event) { //filter by
if(event!=null){
testFire.add("get column: "+(String)event.getSortColumn().getHeaderText()+" I'm Initialized");
}
}
}
So, first time table rendered not calling listener method setSortProperty, this is an issue.
I added my environment details in initial post.
I replicated showcase with subtle modifications as follows
<h:form>
<p:dataTable var="car" value="#{dtSummaryRowView.cars}" >
<p:ajax event="sort" listener="#{dtSummaryRowView.onsort}" id="sortev" async="true" >
<f:attribute name="event" value="event" />
</p:ajax>
<p:column headerText="Id" sortBy="#{car.id}">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year" sortBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand" sortBy="#{car.brand}">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color" sortBy="#{car.color}">
<h:outputText value="#{car.color}" />
</p:column>
<p:summaryRow listener="#{dtSummaryRowView.setSortProperty}">
<p:column colspan="3" style="text-align:right">
<h:outputText value="Total:" />
</p:column>
<c:forEach items="#{dtSummaryRowView.randomPrice}" var="sumcol" >
<p:column>
<h:outputText value="#{sumcol}">
</h:outputText>
</p:column>
</c:forEach>
</p:summaryRow>
</p:dataTable>
</h:form>
the bean
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import org.primefaces.event.data.SortEvent;
import service.Car;
@ApplicationScoped
@Named("dtSummaryRowView")
public class SummaryRowView implements Serializable {
private List<Car> cars;
//@ManagedProperty("CarService")
private CarService service=new CarService();
private List<String> testFire = new ArrayList<>();
@PostConstruct
public void init() {
cars = service.createCars(50);
testFire.add("I'm not initialized!");
}
public List<Car> getCars() {
return cars;
}
public void setService(CarService service) {
this.service = service;
}
public List<String> getRandomPrice() {
return testFire;
//return (int) (Math.random() * 100000);
}
public void setSortProperty(Object o) { // filter value
if (o instanceof String) {
testFire.add("set sort: "+(String)o);
}
}
public void onsort(SortEvent event) { //filter by
if(event!=null){
testFire.add("get column: "+(String)event.getSortColumn().getHeaderText()+" I'm Initialized");
}
}
}
So, first time table rendered not calling listener method setSortProperty, this is an issue.
jdk1.8.0_91.jdk
glassfish 4.1
Eclipse Persistence Services - 2.6.1.v20150605-31e8258
<version>6.0</version>
Luzhu paiay EVM pochinay.
glassfish 4.1
Eclipse Persistence Services - 2.6.1.v20150605-31e8258
<version>6.0</version>
Luzhu paiay EVM pochinay.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 40 guests