• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing custom objects for Tag

 
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey, I was wondering about passing custom java Objects (not String or primitive-wrappers) for Tag class in jsp. With strings its easy, I just pass it like <myLib:myTag myAttribute="stringvalue"/>, but how do I do it with MyOwnJavaObject? There's existing setters and getters for the custom java Object already in place..
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that an instance of MyOwnJavaObject is established as a scoped variable named whatever:

 
Tapio Niemela
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Assuming that an instance of MyOwnJavaObject is established as a scoped variable named whatever:



hi and thanks for your answer, but could you still please clarify "scoped variable"?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, where would the object exist? If not in one of the scopes, where would it be?

You're not still using scriptlets in your JSP, are you?
 
Tapio Niemela
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Well, where would the object exist? If not in one of the scopes, where would it be?

You're not still using scriptlets in your JSP, are you?



I finally was successfull with this one, I just put MyOwnJavaObject into request scope with key "whatever".

and yes, I "have to" solve this one using scriptlets. And yes I know I shouldn't use them, although the reason isn't quite clear. I know that they make code more ugly (which in my opinion EL does also, or loops and if-clauses using JSTL) and they don't allow reuse. But let's face it, how many components can one really reuse? And if the goal is reusable components (which it should be) that can be arranged using something else, like servlets, xml, POJO etc..
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tapio Niemela wrote:And yes I know I shouldn't use them, although the reason isn't quite clear. I know that they make code more ugly (which in my opinion EL does also, or loops and if-clauses using JSTL)


That may depends on how you define "ugly", but there are many reasons to avoid scriptlets in JSP. Those are introduced mainly for page authors (who are not familiar with Java). And custom tags allows creating reusable tags in many common cases other than what JSTL provides.

And if the goal is reusable components (which it should be) that can be arranged using something else, like servlets, xml, POJO etc..


Here the reusable means in the "view", so if we use servlets for that we are writing HTML inside the servlets which is really a bad idea.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic