Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Cewolf ChartPostProcessor with dynamic variable

 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am setting a cewolf's chart maxX value as follows



The problem I am having, is that the 'value' needs to change in relation to a session variable. I obviously cant do

(Integer)session.getAttribute("maxXValue")

because of the local variable "session" being accessed from within a inner class. How would I go about injecting a variable into this chart processor?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the JSP EL to pass the value to the postprocessor:

<cewolf:param name="maxXValue" value="${maxXValue}"/>

Assuming that there are no other attributes with that name in the page or request scope, it will get it from the session. Or you can use "${sessionScope.maxXValue}".
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:You can use the JSP EL to pass the value to the postprocessor:

<cewolf:param name="maxXValue" value="${maxXValue}"/>

Assuming that there are no other attributes with that name in the page or request scope, it will get it from the session. Or you can use "${sessionScope.maxXValue}".


I dont need to get a value to my JSP page though. I need to set the max X value within the ChartPostProcessor i have below

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "get a value to my JSP page" - JSP has access to the user's session, so it can retrieve the value.

The "params" Map in the processChart method contains all values that are passed in via cewolf:param tags, so I think adding that single line of JSP code is all it takes to implement this (plus the Java code that retrieves the element from the Map and uses it).
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I'm not sure what you mean by "get a value to my JSP page" - JSP has access to the user's session, so it can retrieve the value.

The "params" Map in the processChart method contains all values that are passed in via cewolf:param tags, so I think adding that single line of JSP code is all it takes to implement this (plus the Java code that retrieves the element from the Map and uses it).


Ah ok, I understand. But I am getting "cannot find symbol - maxXValue" when trying to compile.

I am using this in my processChart method



and this in my jsp page cewolf chart

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String maxX = (String) params.get(String.valueOf(maxXValue));

That should read

String maxX = (String) params.get("maxXValue");
 
MichaelJ McCabe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, again, for all your help. I now have it working.

Both ${maxXValue} and ${sessionScope.maxXValue} didnt work so I ended up doing

<% int maxXValue = (Integer)session.getAttribute("maxXValue"); %>

then using

value="<%=maxXValue %>"

looking great
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to hear that you got it working. It sounds as if your web app may not be set up correctly for EL; http://faq.javaranch.com/java/ElOrJstlNotWorkingAsExpected may help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic