0

该图表显示得非常好,但日志一点也不好看。

我找不到异常的原因。任何建议表示赞赏!我相信在两种情况下,没有实例,因为它没有被调用,或者我的 bean 中有一个空指针。但是我已经在 bean 中完成了错误处理,所以我相信可能还有其他原因?

错误 1

    SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path     [/test threw exception [/home/barChart.xhtml @14,67 listener="#{chartBean}": Identity 'chartBean' does not reference a MethodExpression instance, returned type: ChartBean] with root cause
    javax.el.ELException: /home/barChart.xhtml @14,67 listener="#{chartBean}": Identity 'chartBean' does not reference a MethodExpression instance, returned type: ChartBean
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)

错误 2

    SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/test] threw exception [null] with root cause
    java.lang.NullPointerException
        at org.primefaces.component.chart.bar.BarChartRenderer.encodeOptions(BarChartRenderer.java:64)

错误 3

    SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
    java.lang.RuntimeException: java.lang.OutOfMemoryError: PermGen space
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292......

然后错误加起来

代码:barChart.xhtml

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
    </h:head>
    <h:body>


            <h1 class="title ui-widget-header ui-corner-all">Login - Statistics</h1>
            <div class="entry">

                <p:barChart id="horizontal" value="#{chartBean.categoryModel}" legendPosition="ne"  breakOnNull="false" barMargin="3" barPadding="3"
                            title="Horizontal Bar Chart"  orientation="horizontal" min="0" max="#{chartBean.count}" style="height:#{chartBean.ssize}" />


            </div>
    </h:body>
    </html>

和 Bean ChartBean.java

    @ManagedBean(name="chartBean")
    @RequestScoped
    public class ChartBean implements Serializable {

        CDBPool cdb;
        ResultSet res = null;
        private int method = 0;
        private int  months = 12;
        private String  country = null;
        private int bitval = 1;
        private int type = 0;
        private CartesianChartModel categoryModel;

        private int size = 1;
        private String sSize = "10";           //Width of chart
        private String maxCount="100";          //size of x-axis 
        private int count = 0;
        private HttpServletRequest request;
        private HttpServletResponse response;

        public ChartBean()   {
        request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
            createCategoryModel();
        }


    /**
    * To set the max of x-axis as integer
    * @return 
    */
        public int getCount() {
            return count;
        }


    /**
    * To set the max of x-axis
    * @return 
    */
        public String getMaxCount() {
            return maxCount;
        }

        public int getSize() {
            return size;
        }
    /**
    * To set the width of chart
    * @return 
    */
        public String getSsize() {
            return sSize;
        }

        public void itemSelect(ItemSelectEvent event) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item selected",
                    "Item Index: " + event.getItemIndex() + ", Series Index:" + event.getSeriesIndex());

            FacesContext.getCurrentInstance().addMessage(null, msg);
        }

        public CartesianChartModel getCategoryModel() {
            return categoryModel;
        }

        public final void setChartProp(int method, int  months, String country, int  bitval, int  type){
            //TODO Replace thees values with request get...
            this.method = method;
            this.months = months;
            this.country = country;
            this.bitval = bitval;
            this.type = type;
            if (method == 0) {
                method = 0;
            }
            if (months == 12) {
                months = 12;
            }
            if (country == null) {
                country = "%";
            }
            if (bitval == 1) {
                bitval = 1;
            }
            if (type == 0) {
                type = 0;
            }
            //CALL "cdbdba"."CDBStatLoginDay"("@SUMMETHOD" = 0,"@MONTHSBACK" = 12,"@COUNTRY" = '%',"@BITVAL" = '1',"@TYPE" = 0)
    /*
            mint,diff,dh,sum
            20110616,366,0,84
            20110616,366,1,52
            20110616,366,2,6
            20110616,366,3,17
    */      

            String sqlString = "Exec CDBStatLoginDay " + method + "," + months + ",'" + country + "'," + bitval + "," + type;
            res = cdb.dbQuery(sqlString);
        }

        private void createCategoryModel()  {
            try {
                cdb = JSPCodeFunctions.getDBPool(request, response);
            } catch (Exception ex) {
                Logger.getLogger(ChartBean.class.getName().concat(" when calling JSPCodeFunctions ")).log(Level.SEVERE, null, ex);
            }
                setChartProp(method,  months,  country,  bitval,  type);    
            categoryModel = new CartesianChartModel();
            ChartSeries hits = new ChartSeries();

            if (res != null) {

                Date incrementDate = null;
                DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
                int days = 0;
                String day;
                String month;
                String year; 
                String serieDate = null;
                String startDate = null;

                count = 100;
                try {
                    while (res.next()) {
                        size = res.getInt(2);
                        try {
                            incrementDate = ChartDate.addDays((Date)formatter.parse( res.getString(1)), res.getInt(3));
                        } catch (ParseException ex) {
                            Logger.getLogger(ChartBean.class.getName().concat(" When retriving rows from res ")).log(Level.SEVERE, null, ex);
                        }
                        day = incrementDate.toString().split(" ")[2];
                        month = incrementDate.toString().split(" ")[1];
                        year = incrementDate.toString().split(" ")[5];
                        serieDate = day+""+month+""+year;
                        count = (res.getInt(4)>count)? res.getInt(4):count;
                        hits.set(serieDate, res.getInt(4));  //Sets date and count
                        days++;
                        try {
                            startDate = ChartDate.addDays((Date)formatter.parse( res.getString(1)), 0).toString().split(" ")[2]+"-"+ChartDate.addDays((Date)formatter.parse( res.getString(1)), 0).toString().split(" ")[1]+"-"+ChartDate.addDays((Date)formatter.parse( res.getString(1)), 0).toString().split(" ")[5];
                        } catch (ParseException ex) {
                            Logger.getLogger(ChartBean.class.getName().concat(" When retriving rows from res")).log(Level.SEVERE, null, ex);
                        }

                    }
                    maxCount = String.valueOf(count);
                    sSize= String.valueOf(size*15)+"px";                
                    hits.setLabel("Numer of login from: "+startDate+" to "+serieDate.toString());
                } catch (SQLException ex) {
                    Logger.getLogger(ChartBean.class.getName()).log(Level.SEVERE, null, ex);
                }

                try {
                    if (res!=null)res.close();res = null;
                } catch (SQLException ex) {
                    Logger.getLogger(ChartBean.class.getName()).log(Level.SEVERE, null, ex);
                }
                categoryModel.addSeries(hits);


            }else{
                //Lets add some default test data
                ChartSeries boys = new ChartSeries();
                boys.setLabel("Boys");
                boys.set("2004", 120);
                boys.set("2005", 100);
                ChartSeries girls = new ChartSeries();
                girls.setLabel("Girls");
                girls.set("2004", 52);
                girls.set("2005", 60);
                categoryModel.addSeries(boys);
                categoryModel.addSeries(girls);
                }
        }

    }
4

2 回答 2

1

您发布的代码似乎不完整。该错误清楚地说明了问题:

/home/barChart.xhtml @14,67 listener="#{chartBean}":标识'chartBean'没有引用MethodExpression实例,返回类型:ChartBean

您发布的代码中的第 14 行是空的,所以请检查您的真实代码

监听器必须引用一个方法,所以listener="#{chartBean}"你应该使用 sth而不是listener="#{chartBean.doStuff}"

于 2012-06-21T08:29:59.157 回答
0

我的解决方案:我进行了一般清理,替换了不推荐使用的标记库并删除了 truts xml 文件,并在类路径上添加了 struts jar。我相信我有一个冲突 betsen struts server face 和 jsf。是什么导致了缓存,我不知道,在我清理后它现在消失了。

于 2012-06-29T12:47:59.400 回答