Oracle神諭

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            284 隨筆 :: 9 文章 :: 106 評(píng)論 :: 0 Trackbacks

          Intro

          I am rendering a chart to the output stream. Instead of streaming it directly to the response.out, I create a ChartResult , and let webwork do the chaining for me.

          I generate the chart in one class, and I render it out in another class, efftectively decoupling the view from the actions. You can easily render it out to file or some view other than a web response.out if you wish.

          Configuration
          xwork.xml -result-types definitions
          <result-types>
          ?? <result-type name="chart" class="myapp.webwork.extensions.chartResult"/>
          </result-types>
          xwork.xml -action definitions
          <action name="viewModerationChart" class="myapp.webwork.actions.ViewModerationChartAction">
          ?? <result name="success" type="chart">
          ????? <param name="width">400</param>
          ????? <param name="height">300</param>
          ?? </result>
          </action>

          Source Codes
          My result class search for a "chart" in the ValueStack and renders it out...

          public class ChartResult implements? Result{
          ?? private int width;
          ?? private int height;
          ?? public void execute(ActionInvocation invocation)throws Exception{
          ?????? JFreeChart chart = (JFreeChart)invocation.getStack().findValue("chart");
          ?????? HttpServeletResponse response = ServeletActionContext.getResponse();
          ?????? OutputStream os = response.getOutputStream();
          ?????? ChartUtilities.writeChartAsPNG(os,chart,width,height);
          ?????? os.flush();
          ?? }
          ?????
          ?? public void setHeight(int height){
          ???? this.height=height;
          ?? }
          ??
          ?? public void setWidth(int width){
          ???? this.width=width;
          ?? }
          }

          public class ViewModerationChartAction extends ActionSupport{
          ?? private JFreeChart chart;
          ??
          ?? public String execute() throws Exception{
          ????? //chart creation logic ...
          ????? XYSeries dataSeries = new XYSeries(new Integer(1));
          ????? for(int i=0;i<=100;i++){
          ???????? dataSeries.add(i,RandomUtils.nextInt());
          ????? }
          ?????
          ????? XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
          ????? ValueAxis xAxis = new NumberAxis("Raw Marks");
          ????? ValueAxis yAxis = new NumberXxis("Moderated Marks");
          ?????
          ????? chart = new JFreeChart(
          ????????????????????? "Moderation Function",
          ????????????????????? JFreeChart.DEFAULT_TITLE_FONT,
          ????????????????????? new XYPlot(
          ??????????????????????????? xyDataset,
          ??????????????????????????? xAxis,
          ??????????????????????????? yXis,
          ??????????????????????????? new
          ?????????? StandardXYItemRenderer(StandardXYItemRender.LINES),
          ??????????????????????????? false????????????????
          ????????????????????? );
          ????????????????????? ...
          ????? )
          ?? }
          ??
          ?? public JFreeChart getChart(){
          ????? return chart;
          ?? }
          }

          posted on 2006-04-11 11:55 java世界暢談 閱讀(320) 評(píng)論(0)  編輯  收藏 所屬分類: WEBWORK

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 北流市| 瓮安县| 洱源县| 平顺县| 嫩江县| 墨竹工卡县| 岳普湖县| 南召县| 花垣县| 乌苏市| 遂川县| 苍梧县| 罗定市| 江陵县| 固镇县| 连云港市| 乐平市| 香河县| 科技| 文山县| 巴中市| 南平市| 司法| 田阳县| 昌图县| 翁牛特旗| 德钦县| 郑州市| 旬阳县| 辉南县| 简阳市| 特克斯县| 长垣县| 石阡县| 盘锦市| 遂川县| 南阳市| 荃湾区| 大名县| 中卫市| 庆元县|