Свойство Bean загружается только после обновления страницы
officeProductionBean.officeName загружается только после того, как я вручную обновил страницу. Я использую аннотации @Managedbean и @SessionScoped с Primefaces 5.3.
xhtml page Значение, переданное с другой страницы
<f:metadata>
<f:viewParam name="id" value="#{officeProductionBean.officeCode}" />
</f:metadata>
<h:form>
<p:dataTable value="#{officeProductionBean.officeProductions}" var="officeProductions">
<f:facet name="header">
<h:outputText value="Office Production for: #{officeProductionBean.officeName}"/>
</f:facet>
<p:column headerText="Total" >
<h:outputText value="#{officeProductions.total}" />
</p:column>
<p:column headerText="Volume" >
<h:outputText value="#{officeProductions.volume}">
<f:convertNumber type="currency" currencySymbol="$" />
</h:outputText>
</p:column>
<p:column headerText="Closing Date" >
<h:outputText value="#{officeProductions.closingDate}" />
</p:column>
</p:dataTable>
</h:form>
боб
@ManagedBean
@SessionScoped
public class OfficeProductionBean implements Serializable {
private static final long serialVersionUID = 1L;
[clip]
public List<OfficeProduction> getOfficeProductions() throws ClassNotFoundException, SQLWarning, SQLException {
Connection connect = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (SQLException ex) {
System.out.println("in exec");
System.out.println(ex.getMessage());
}
officeProductions = new ArrayList<>();
PreparedStatement ps = connect.prepareStatement("CALL OfficeMonthlyProduction(?);");
ps.setString(1, officeCode);
ResultSet rs = ps.executeQuery();
barModel = new BarChartModel();
ChartSeries office = new ChartSeries();
while (rs.next()) {
total = rs.getString("Total");
volume = rs.getString("Volume");
officeName = rs.getString("officename");
closingDate = rs.getString("Closing Date");
OfficeProduction officeProduction = new OfficeProduction(total, volume, closingDate, officeName);
officeProductions.add(officeProduction);
// Set data points for chart
office.set(closingDate, Integer.parseInt(total));
}
office.setLabel(officeName + " Production");
barModel.addSeries(office);
barModel.setTitle("Monthly Production");
barModel.setLegendPosition("ne");
Axis xAxis = barModel.getAxis(AxisType.X);
xAxis.setLabel("Month");
Axis yAxis = barModel.getAxis(AxisType.Y);
yAxis.setLabel("# of Transactions");
rs.close();
ps.close();
connect.close();
return officeProductions;
}
public BarChartModel getBarModel() {
return barModel;
}
// Only one office name. Using it so I can populate form.
public String getOfficeName() {
return officeName;
}
public String getOfficeCode() {
return officeCode;
}
public void setOfficeCode(String officeCode) {
this.officeCode = officeCode;
}
OfficeProduction Bean
package beans;
import java.text.DecimalFormat;
public class OfficeProduction {
private String total;
private String volume;
private String closingDate;
private String officeName;
public OfficeProduction(String total, String volume, String closingDate, String officeName) {
this.total = total;
this.volume = volume;
this.closingDate = closingDate;
this.officeName = officeName;
}
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public String getVolume() {
// Rather have done this in Presentation layer, but Primefaces is giving me a hard time.
String volumeCurrency = DecimalFormat.getCurrencyInstance().format(Double.parseDouble(volume));
return volumeCurrency;
}
public void setVolume(String volume) {
this.volume = volume;
}
public String getClosingDate() {
return closingDate;
}
public void setClosingDate(String closingDate) {
this.closingDate = closingDate;
}
public String getOfficeName() {
return officeName;
}
public void setOfficeName(String officeName) {
this.officeName = officeName;
}
}