How pass dynamic information- please help

Help
guester
2005-05-03
2013-01-13
  • guester
    guester
    2005-05-03

    I m trying create some pie charts which I m able to do.

    How do I pass dynamic information to productdataSet()?

    here's my method: See where the date that are hardcoded in the select query I want them to dynamically passed. Any idea how I do that?

    public Object produceDataset(Map params) throws DatasetProduceException {
            log.debug("producing data.");
            DefaultPieDataset  dataset = new DefaultPieDataset (){
                /**
                 * @see java.lang.Object#finalize()
                 */
                protected void finalize() throws Throwable {
                    super.finalize();
                    log.debug(this +" finalized.");
                }
            };

            Connection con = getDBConnection(); //Gets database connection.
            java.sql.PreparedStatement pstmt = null; //Create an instance of PreparedStatement.
            
            try{

                String query = "SELECT distinct COUNT(*), SITE FROM FAULTS.FAULTS where booked_date>= to_date('01/02/2005','dd/MM/yyyy') " +
                               "and booked_date<= to_date('28/02/2005','dd/MM/yyyy') and site is not null GROUP BY SITE";
                pstmt = con.prepareStatement(query);
                ResultSet rs = pstmt.executeQuery();

                while(rs.next()) {
                     dataset.setValue(rs.getString(2),new Integer(rs.getInt(1)));
                }

                rs.close();
                pstmt.close();

            }catch (Exception ex) {
                    //throw new RuntimeException(se);
                    ex.printStackTrace();
            }finally {
                try{
                    con.close();
                } catch (Exception ex) {
                }
            }
             
            return dataset;
        }

     
    • guester
      guester
      2005-06-10

      I m trying create some pie charts which I m able to do.

      How do I pass dynamic information to productdataSet()?

      here's my method: See where the date that are hardcoded in the select query I want them to dynamically passed. Any idea how I do that?

      public Object produceDataset(Map params) throws DatasetProduceException {
      log.debug("producing data.");
      DefaultPieDataset dataset = new DefaultPieDataset (){
      /**
      * @see java.lang.Object#finalize()
      */
      protected void finalize() throws Throwable {
      super.finalize();
      log.debug(this +" finalized.");
      }
      };

      Connection con = getDBConnection(); //Gets database connection.
      java.sql.PreparedStatement pstmt = null; //Create an instance of PreparedStatement.

      try{

      String query = "SELECT distinct COUNT(*), SITE FROM FAULTS.FAULTS where booked_date>= to_date('01/02/2005','dd/MM/yyyy') " +
      "and booked_date<= to_date('28/02/2005','dd/MM/yyyy') and site is not null GROUP BY SITE";
      pstmt = con.prepareStatement(query);
      ResultSet rs = pstmt.executeQuery();

      while(rs.next()) {
      dataset.setValue(rs.getString(2),new Integer(rs.getInt(1)));
      }

      rs.close();
      pstmt.close(); 

      }catch (Exception ex) {
      //throw new RuntimeException(se);
      ex.printStackTrace();
      }finally {
      try{
      con.close();
      } catch (Exception ex) {
      }
      }

      return dataset;
      }

       
    • bertsylv
      bertsylv
      2005-06-13

      add a param tag in your producer's body.
      <cewolf:producer id="producer">
                  <cewolf:param name="paramName" value="01/02/2005" />
      </cewolf:producer>

      and you can get the value in your DatasetProducer like this:
      String str = (String) params.get("paramValue")

       
    • bertsylv
      bertsylv
      2005-06-14

      correction. I just remark that the value attribute of the param tag accept only runtime expression value. (with tomcat 5.5.9)
      also this is correct:
      <cewolf:param name="paramName" value='<%="01/02/2005"%>' />
      or
      <cewolf:param name="paramName" value="${yourVariable}" />

       
    • guester
      guester
      2005-06-21

      bertsylv, Many thanks for your response. I have another problem. this is what I have in my jsp page.

      These are date variables passed from other page.

      String date1 = request.getParameter("dc1");
      System.out.println(date1);
      String date2 = request.getParameter("dc2");
      System.out.println(date2);

      Chart tags:

      <cewolf:producer id="producer">
          <cewolf:param name="date1" value="${date1}"/>
          <cewolf:param name="date2" value="${date2}"/>
          </cewolf:producer>
          <cewolf:chart id="pieExample3D" type="pie3D" title="Faults By Campus" showlegend="flase">
             <cewolf:data>
                   <cewolf:producer id="pieChartView" />
             </cewolf:data>
          <cewolf:colorpaint color="#EEEEEF"/>
          </cewolf:chart>
          <cewolf:img chartid="pieExample3D" renderer="/cewolf" border="0" width="700" height="400">
                   <cewolf:map tooltipgeneratorid="pieChartViewToolTips"/>
          </cewolf:img>

      in my java class I have :

      String date1 = (String) params.get("date1");

      When I run I  an exception.

      Unable to convert string '${date1}' to class java.io.Serializable for attribute value: java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager

      Any idea why I m getting that, what am I doing wrong?

      please help me if you can.

       
    • guester
      guester
      2005-06-21

      I even tried this, but I m still getting the same error:

      <cewolf:chart id="pieExample3D" type="pie3D" title="Faults By Campus" showlegend="flase">
             <cewolf:data>
                   <cewolf:producer id="pieChartView" />
                   <cewolf:param name="value1" value="${date1}"/>
                   <cewolf:param name="value2" value="${date2}"/>
                   </cewolf:producer>
             </cewolf:data>
          <cewolf:colorpaint color="#EEEEEF"/>
          </cewolf:chart>
          <cewolf:img chartid="pieExample3D" renderer="/cewolf" border="0" width="700" height="400">
                   <cewolf:map tooltipgeneratorid="pieChartViewToolTips"/>
          </cewolf:img>

       
    • guester
      guester
      2005-06-21

      haviing looked at other threads.

      I did this:

      <cewolf:chart id="pieExample3D" type="pie3D" title="Faults By Campus" showlegend="flase">
             <cewolf:data>
                   <cewolf:producer id="pieChartView" />
                   <cewolf:param name="value1" value="<%=(String)request.getParameter("dc1")%>"/>
                   <cewolf:param name="value2" value="<%=(String)request.getParameter("dc2")%>"/>
                   </cewolf:producer>
             </cewolf:data>
          <cewolf:colorpaint color="#EEEEEF"/>
          </cewolf:chart>
          <cewolf:img chartid="pieExample3D" renderer="/cewolf" border="0" width="700" height="400">
                   <cewolf:map tooltipgeneratorid="pieChartViewToolTips"/>
          </cewolf:img>

      I now get  another exception:

      java.lang.ClassCastException: de.laures.cewolf.taglib.tags.DataTag

       
    • KaiG
      KaiG
      2005-06-24

      try it like this:

      <cewolf:param name="value1" value="<%=(java.io.Serializable) request.getParameter("dc1")%>"/>

      that should work - if not just post again

      cheers Kai

       
    • guester
      guester
      2005-07-01

      Sorry I m still getting the same error, any suggestions?

       
    • KaiG
      KaiG
      2005-07-04

      hm sorry, i don't have any. <cewolf:param name="value1" value="<%=(java.io.Serializable) request.getParameter("dc1")%>"/>   works for me and i'm able to access the given parameter via the params HashMap in my Dataset Producer

       
    • guester
      guester
      2005-07-05

      which version of cewolf are you using?

       
    • KaiG
      KaiG
      2005-07-05

      i'm using 0.10.3

       
    • severine
      severine
      2005-07-05

      Hi!

      Try this code:

      <jsp:useBean id="graphic" class="MyDataSet"/>

      and then:

      graphic.setParam(param);

      it works for me.

       
    • C_J
      C_J
      2007-08-29

      Why dont you use get and setter methods to set properties in the dataset producing class and then use the producedataset() method to access the database and return the data set. That is what I did ..