File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Setting bean in Simple tag attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Setting bean in Simple tag attribute" Watch "Setting bean in Simple tag attribute" New topic
Author

Setting bean in Simple tag attribute

Harshvardhan gupta
Greenhorn

Joined: Apr 04, 2010
Posts: 8
According to HFSJ i am trying example on page 521.
I tried the following but my jsp shows nothing. it comes out blank.Please help dear intellects


JSP that uses tag :



the tag handler:



the object to be set as attribute:



TLD file for tag :



Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
You are mixing up Scriptlet variables with EL variables.
These things are not the same.

${movieCollection} does not refer to your scriptlet variable movieCollection, but is rather looking for an attribute of that name.
ie the java equivalent of ${movieCollection} would be pageContext.findAttribute("movieCollection");

One solution (for this example page)
add this to the end of your <% scriptlet %> section where you define the list of movies:



This puts the movieCollection variable into the page attribute space where your EL reference can then find it.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Although, using scriptlets at all in your JSP pages is not recommended.

And mixing scriptlets with JSTL and EL is even less recommended,

If you are going to use scriptlets (not recommended) then just use scriptlets. Mixing scriptlets with JSTL/EL is just a big old mess.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harshvardhan gupta
Greenhorn

Joined: Apr 04, 2010
Posts: 8
Do I also need to specify the type for attribute movieList as java.util.List in the TLD file?
Tex Martin
Greenhorn

Joined: Sep 09, 2010
Posts: 7
    
    1

Hi Harshvardhan
I'm on the same page in HFSJ :-)
Apart from what can be learned from the other answers, it caught my eye that your javaBean lacks getter/setter for the name attribute.

I just tried it out on Jetty; it says "The class 'foo.Movie' does not have the property 'name'". I don't know if e.g. TomCat are more lenient.

Cheers and good luck

Tex Martin


SCJP, SCWCD
Harshvardhan gupta
Greenhorn

Joined: Apr 04, 2010
Posts: 8
you are absolutely correct my friend . Actually initially when i started trying it my intentions were to make it a bean . But i just ended up with trying a normal object which could be set in tag attribute . so it cant be called a bean without getter and setter but atleast i needed to check whether any random object can be set in attribute value . thanks and regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting bean in Simple tag attribute