Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing a Scriptlet Object to a Bean

 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't want to resurrect a dead thread, but I haven't found a better answer to this than Ranch Post

I'm trying to get out of writing more scriptlets and using beans instead, but I can't seem to find a way to pass a scriptlet created object to a bean. I was beginning to think you just couldn't do it, but I found the post above, although I am not entirely clear on what "pass the list as parameter of the method of a class". This is what I have tried:




db is a user made POJO, nothing special. I haven't tried implicitly casting db and am going to try that next, but I wanted to post; I think its something simple Im missing.

Thanks
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show me your full JSP and the bean class code and point out exactly what is it that you are having a problem with?
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using beans in a JSP like that is a pretty antiquated way of doing things, but as I understand it the value of the scriptlet <%db%> will be treated as a String and then coerced to whatever type the setPostingSelection method accepts. That has to be either String or a primitive type, or one of the primitive wrapper types. So the question is, what is the type of the parameter of the setPostingSelection method?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Using beans in a JSP like that is a pretty antiquated way of doing things, but as I understand it the value of the scriptlet <%db%> will be treated as a String and then coerced to whatever type the setPostingSelection method accepts. That has to be either String or a primitive type, or one of the primitive wrapper types. So the question is, what is the type of the parameter of the setPostingSelection method?


Shouldn't it be setDisbursement() Paul? postingSelection appears to be the bean id for the class DisbursementPostingSelection. The property = "disbursement" maps on to the setter method if I am not mistaken here.
 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That answers my question Paul. The type isn't a primitive, String, or wrapper, so this isn't going to work. It's an object. I'll have to write my logic inside of a scriplet I guess. Thanks for everyone's input.
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try the JSTL <c:set> tag.


It may be better to construct the object and then store it into context:
ie finish your scriptlet code with
request.setAttribute("db", db);

The next step would be to refactor that code out of the JSP and into a servlet :-)

 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Shouldn't it be setDisbursement() Paul? postingSelection appears to be the bean id for the class DisbursementPostingSelection. The property = "disbursement" maps on to the setter method if I am not mistaken here.


Yes, it should. I haven't used JSP beans for years, I only use JSTL now. That's my excuse for getting it wrong anyway. But as you can see from what Stefan Evans posted, JSTL has the advantage of handling objects properly. As well as not being obsolete.
 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:You could try the JSTL <c:set> tag.


It may be better to construct the object and then store it into context:
ie finish your scriptlet code with
request.setAttribute("db", db);

The next step would be to refactor that code out of the JSP and into a servlet :-)



Thanks Stefan. This seems like the correct path; well, the correct path is refactoring into a servlet like you said, but I don't have the time in the schedule to refactor all of it. This seems like a good way to try an implement current technology with the legacy stuff.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic