views:

151

answers:

2

hi all

i have two problems with primefaces 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 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'.

and

  1. getChartData() method only called seven times!!!!
A: 

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");
Odelya
A: 

thanks for reply

but i think this problems is primafaces bug!

the problem one can be solved by using tag

i have solved problem 2 by doing so:

<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 set live propety to false and then refreshing chart by tag

it works fine

arash
You can open an issue here:http://code.google.com/p/primefaces/issues/list
Odelya
i don't want to help google code because it banned my country for political issues!
arash