Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom JSTL Tag (extending BodyTagSupport) to generate javascript array when pass a java list

 
Micale Raj
Ranch Hand
Posts: 30
Hibernate IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,

I want to create a custom JSTL tag ( extending BodyTagSupport ) to generate javascript array when pass a java list. I'm new to JSTL and don't know how to start this. I want this new javascript variable to accessed by java script functions.
I think this is possible. How to do this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Micale Raj wrote:I want to create a custom JSTL tag


There's no such thing as a "custom JSTL tag". The JSTL is a predefined tag library. I assume you mean a "custom tag"?

extending BodyTagSupport


You don't want to use BodyTagSupport -- that's JSP 1. You want to use JSP 2's SimpleTagSupport.

I'm new to JSTL and don't know how to start this.


That doesn't matter because this has nothing to do with the JSTL.

I want this new javascript variable to accessed by java script functions. I think this is possible. How to do this ?


You can emit any output you want, including JavaScript markup.
 
Micale Raj
Ranch Hand
Posts: 30
Hibernate IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. It should be custom tag. I can't use SimpleTagSupport since my project using JSP 1 . I'm trying to do this as following. But I'm getting error : No property editor found for the bean "java.util.List"



The taglib.tld


in Jsp Page,



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP 1? That's over 10 years old. There is no excuse for using something so old. What is the reason for this?
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extend your tld file to define the attribute of type list
That should look something like:



Looking at your usage in the JSP page. How do you expect "a,b,c" to become a List?
That looks like a comma separated string to me...
# <custom:listToJavaScriptArray list="a,b,c"/>
 
Micale Raj
Ranch Hand
Posts: 30
Hibernate IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:Extend your tld file to define the attribute of type list
That should look something like:



Looking at your usage in the JSP page. How do you expect "a,b,c" to become a List?
That looks like a comma separated string to me...
# <custom:listToJavaScriptArray list="a,b,c"/>


Thanks for the help.
I tried it and it worked. :)
You are right about jsp part. It's a comma separated string. I used a java.util.List from request build the array. Now it's working. Thank you very much ! :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic