Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Declarations and Scriplets  RSS feed

 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a function declared at the top of my JSP called createChart. This function uses JFreeChart's create line chart method from the ChartFactory class. It works fine right now. Here's the thing though. Now I want to create Bar charts in the same function. I pass in a string from my scriptlet into the function (i.e. called graphType). In the function I want to do the following check. If graphT equals LINE then call createLineChart else createBarChart. First I had the if and the declared the chart object inside the if while returning the chart object back outside the if (thought it had to do with it being local inside the if block). I then added JFreeChart chart; outside the if and called the createLineChart the same way as before but still no go. Any suggestions to why this isn't working? Also a brief personal explanation of the diff between declaration and scriplet would be helpful (especially when it comes to variable handling and declaration). Thanks.

Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this stage, you shouldn't be using scriptlets ro scriplet declarations in your page at all. This is the the type of processing that should be factored out into Java classes.

That said, a declaration is placed at the class level in the servlet that is created on behalf of the JSP. Scriplets are placed in the body of the service method.
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,
Just trying to understand why the if isn't working. Since the value is accessible shouldn't the if work? The reason why this isn't a class yet is I'm new to Java programming (rather haven't done too much with it) to create and importing the class but also this code is based off instructions from someone whose familar with the type of app I'm doing (so I went with the flow). For now, what can I do in the JSP to get the variable to check out? Thanks.

Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We'll need to see some code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!