aspose file tools*
The moose likes JSP and the fly likes Passing ArrayList to JSP custom Tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing ArrayList to JSP custom Tag?" Watch "Passing ArrayList to JSP custom Tag?" New topic
Author

Passing ArrayList to JSP custom Tag?

Mallik Avula
Ranch Hand

Joined: Nov 30, 2006
Posts: 86
Hi All,
i have to pass ArrayList to JSP custom tag in attribute.
How can i do it?
Could please any body help me?


Thanks & Regards<br />Mallik Avula<br />SCJP1.4
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mallik Avula
Ranch Hand

Joined: Nov 30, 2006
Posts: 86
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

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

Joined: Oct 17, 2007
Posts: 198
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


My Thoughts : http://passion4java.blogspot.com
Try not to become a man of success but rather to become a man of value.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing ArrayList to JSP custom Tag?