开发者

troubles with primefaces linechart

I have two problems with primefaces <linechart> tag.

This is my backbean code :

public class LiveChartBean {
    private Integer primaryKey;


    public Integer getPrimaryKey() {
        return primaryKey;
    }


    public void setPrimaryKey(Integer primaryKey) {
        this.primaryKey = primaryKey;
    }


    public List<ChartData> getChartData() {
        return MonitoringManager.getChartData(3);
    }

}

And this is my JSF page code :

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<开发者_高级运维;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@taglib uri="http://primefaces.prime.com.tr/ui" prefix="p"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSF 'LiveChart.jsp' starting page</title>
</head>

<body>
    <f:view>
        <p:resources/>
            <h:form>
                <t:inputHidden id="primaryKey" value="#{ChartBean.primaryKey}" forceId="true" />
                <p:lineChart  live="true" value="#{ChartBean.chartData}" var="data"
                    xfield="#{data.index}">
                    <p:chartSeries  label="ResponseTime" value="#{data.data}" />
                </p:lineChart>
            </h:form>
        </f:view>
</body>
</html>

This is my faces-config entry :

<managed-bean>
  <managed-bean-name>ChartBean</managed-bean-name>
  <managed-bean-class>com.pardis.healthMonitor.LiveChartBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
   <property-name>primaryKey</property-name>
   <property-class>java.lang.Integer</property-class>
   <value>#{param.primaryKey}</value>
  </managed-property>
 </managed-bean>

I have passed primaryKey by url to jsf page it works fine and the setPrimaryKey method

called for the first time but after that I have two problems :

  1. It throws :

     javax.el.ELException: Can't set property 'primaryKey' 
    

    on class com.pardis.healthMonitor.LiveChartBean to value null.

  2. getChartData() method only called seven times!!!!


I think that question number 1 is because your bean is in request scope.

If you are using JSF2, you can write view instead of request in

<managed-bean-scope>view</managed-bean-scope>

If you are using JSF1.2 and RichFaces, you can use

<a4j:keepAlive name="ChartBean" />

read more about a4j:keepAlive here

If you use neither of above, consider using session scope and maybe removing the bean from the scope after using it with:

session.removeAttribute("ChartBean");


Thanks for your reply, but I think these problems are primefaces bugs!

The first problem can be solved by using the <t:savestate> tag.

I have solved the second problem with:

<p:lineChart id="Chart" value="#{ChartBean.chartData}" var="data" xfield="#{data.index}">
    <p:chartSeries  label="ResponseTime" value="#{data.data}" />
</p:lineChart>
<p:poll interval="5" actionListener="#{ChartBean.refresh}" update="Chart" />

By setting the live property to false and then refreshing the chart with the <poll> tag, it works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜