• Post Reply Bookmark Topic Watch Topic
  • New Topic

passing custom objects for Tag

 
Tapio Niemela
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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..
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that an instance of MyOwnJavaObject is established as a scoped variable named whatever:

 
Tapio Niemela
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 77
  • Mark post as helpful
  • send pies
  • 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..
 
Vijitha Kumara
Bartender
Posts: 3952
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!