Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing ArrayList to JSP custom Tag?

 
Mallik Avula
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • 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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 .
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • 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
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic