Tuesday, 15 February 2011

struts2 - Unable to implement ModelDriven or ServletRequestAware in Struts 2 Action Class using JFree -



struts2 - Unable to implement ModelDriven or ServletRequestAware in Struts 2 Action Class using JFree -

i trying generate chart based on user input. using jfree charts in struts 2 framework. in chart-generation action class, unable implement modeldriven concept; unable retrieve parameter values httpservletrequest object. .

if phone call chart-generation action class implementing modeldriven or servletrequestaware, works fine but, displays chart on next page. need generate chart based on user input.

i unsuccessful searching info on jfree struts 2; useful tutorial links appreciated.

this struts.xml

class="lang-xml prettyprint-override"><?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd "> <struts> <package name="jfree" extends="jfreechart-default"> <action name="chartaction" class="com.kogent.action.chartaction"> <result name="success" type="chart"> <param name="width">500</param> <param name="height">300</param> </result> </action> </package> </struts>

and action class

class="lang-java prettyprint-override">package com.kogent.action; import java.util.random; import org.jfree.chart.jfreechart; import org.jfree.chart.axis.numberaxis; import org.jfree.chart.axis.valueaxis; import org.jfree.chart.plot.xyplot; import org.jfree.chart.renderer.xy.standardxyitemrenderer; import org.jfree.data.xy.xyseries; import org.jfree.data.xy.xyseriescollection; import com.opensymphony.xwork2.actionsupport; import com.opensymphony.xwork2.modeldriven; import com.opensymphony.xwork2.preparable; public class chartaction extends actionsupport implements modeldriven<formbean>,preparable{ private jfreechart chart; private formbean bean; @override public formbean getmodel() { // todo auto-generated method stub homecoming bean; } @override public void prepare() throws exception { // todo auto-generated method stub bean=new formbean(); } public string execute() throws exception { // chart creation logic... system.out.print(bean.getcategory()+" "+bean.getcharttype()); //if remove above line action runs fine require vales user xyseries dataseries = new xyseries(new integer(1)); (int = 0; <= 100; i++) { dataseries.add(i, new random().nextint(50)); } xyseriescollection xydataset = new xyseriescollection(dataseries); valueaxis xaxis = new numberaxis("marks"); valueaxis yaxis = new numberaxis("age"); chart = new jfreechart("chart title", jfreechart.default_title_font, new xyplot(xydataset,xaxis, yaxis, new standardxyitemrenderer(standardxyitemrenderer.lines)), false); chart.setbackgroundpaint(java.awt.color.white); homecoming super.success; } public jfreechart getchart() { homecoming chart; } }

based on jfree chart many examples there, giving links check out.

first:implementing jfree chart there nil required other servlet request aware , servlet response aware, request taking request user , response giving output user that's it. it's wish utilize 'modeldriven' interface ( gains ability transfer form info object automatically).

just utilize links.

create chart , display them dynamically in jsp.

create area chart in jsp page using jfreechart.

creating pie charts jfreechart

already give-and-take there in stack overflow only

this official site help total you

struts2 jfreechart

No comments:

Post a Comment