• 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 ArrayList to JSP custom Tag?

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
i have to pass ArrayList to JSP custom tag in attribute.
How can i do it?
Could please any body help me?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What part are you stuck on?
Passing Java objects as attributes is a common thing to want to do and is covered in any tutorial or book that teaches how to make custom tags.
 
Mallik Avula
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,
i hope we can pass Strings as arguments for attributes.
But While passing ArrayList or any collection, How to say this is ArrayList to the attribute.
This is may code:
--------- jsp----------
<%@ taglib prefix="question" uri="/questionTag" %>
<%
ArrayList ll = new ArrayList();
ll.add("jj");
ll.add("kk");
request.setAttribute("ll",ll);
%>
<question:hihi collection="${ll}"/>

this is my tld
-----------------------------
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>Question Tag</shortname>
<info>Question Tag library</info>
<tag>
<name>hihi</name>
<tagclass>QuestionsTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>collection</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
-------------- this is my setter method in handler class

public void setCollection(ArrayList list)
{
this.list = list;
}
but it is throwing exception
Could you help in this, please?
 
Sheriff
Posts: 67746
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

Originally posted by Mallik Avula:
But While passing ArrayList or any collection, How to say this is ArrayList to the attribute.


You don't have to "say" anything. Any object can be passed as a scoped variable (attribute).

The setter for the custom tag needs to be set up to accept the correct class.

but it is throwing exception

Do you not feel that it would be useful to show us the exception?
[ May 27, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67746
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
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i also have the same kind of issue, i not sure can we send objects to custom tags. i want to send date as a argument to custom tag....

any help will be appreciated. thank you
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohammed Yousuff wrote:i also have the same kind of issue, i not sure can we send objects to custom tags. i want to send date as a argument to custom tag....

any help will be appreciated. thank you



Yes, yes, of course you can send objects to custom tags, you can do things like this without problem:



where myObject can be a ArrayList, an Object, a pageContext or a Dog.

What is exactly your problem? Mallik said he gets an exception, let's see the stacktrace before saying nothing (and then regretting of having said a stupid thing )
 
Bear Bibeault
Sheriff
Posts: 67746
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
Mohammed Yousuff, in the future it'd be best to open a new topic with your own question rather than tacking it onto an old, dead topic.
 
reply
    Bookmark Topic Watch Topic
  • New Topic