Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting bean in Simple tag attribute

 
Harshvardhan gupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1691
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Harshvardhan gupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I also need to specify the type for attribute movieList as java.util.List in the TLD file?
 
Tex Martin
Greenhorn
Posts: 10
1
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Harshvardhan gupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic