aspose file tools*
The moose likes JSP and the fly likes Passing a Scriptlet Object to a Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing a Scriptlet Object to a Bean" Watch "Passing a Scriptlet Object to a Bean" New topic
Author

Passing a Scriptlet Object to a Bean

Cory Hartford
Ranch Hand

Joined: May 16, 2011
Posts: 82

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


‎"The greatest of all weaknesses is the fear of appearing weak." - JB Bossuet
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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?


~ Mansukh
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

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

Joined: Jul 27, 2010
Posts: 1157

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

Joined: May 16, 2011
Posts: 82

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

Joined: Jul 06, 2005
Posts: 1018
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
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

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

Joined: May 16, 2011
Posts: 82

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
 
subject: Passing a Scriptlet Object to a Bean