Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

Can Tag Handler class have complicated data type ?

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems the default attribute type for Tag Handler class is always "String". What if I need to pass a user-defined data type or just an arraylist ? For example, I want to do ---

In .jsp:

*********************************
<jsp:useBean id="My_Object" class="mypackage.data.MyObject" scope="request" />

<% Arryalist arraylist_1 = new ArrayList(); ...... %> //create an arraylist_1

<myprefix:mytag name="john" param1="arraylist_1" param2="My_Object" />
**********************************

In MyTag.java:

*****************
private String name;
private Arraylist param1;
private MyObject param2;

************
In other words, "param1" and "param2" are not String type. Is that OK ? From what I have tested it doesn't work at all. It seems it requires the type to be "String". That's not good. We often need to pass complicated things to a JSP. If a Tag Handler class only accepts String, can can I handle the situation that I need Arraylist or other user-defined data structure ?

Any thought ?
 
Sheriff
Posts: 67745
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

Any thought ?



Yes. Take a look at what you wrote:



What is the value of param1? The string arraylist_1.

But that's not waht you want. You want the value of the scripting variable arraylist_1 to be passed.

So how would you differentiate the two?

Hint:

Let's say that you wanted to emit the value of arraylist_1 in a paragraph. Would you write is as:



?

No. How would you write it?
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


What is the value of param1? The string arraylist_1.

But that's not waht you want. You want the value of the scripting variable arraylist_1 to be passed.

So how would you differentiate the two?

Hint:

Let's say that you wanted to emit the value of arraylist_1 in a paragraph. Would you write is as:



?

No. How would you write it?



If I am not mistakening you want Frank to "loop" through the ArrayList to retrieve the String values (correct me if I get you wrong). It sounds like it works, but I don't think it is a general way to do what he wants. What if the data type he wants to pass is more complex than an Array that you can loop through ?

I think the "general" way is to let the action class use "request.setAttribute" to pass that specific data type instance. And in the Tag Handler class it can use .getRequest to retrieve that instance.
 
Bear Bibeault
Sheriff
Posts: 67745
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

(correct me if I get you wrong).



You get me wrong.

He has a simple syntax error and I am trying to get him to see it.

I don't think it is a general way to do what he wants.



Yes, he can do exactly what he wants. He just needs to get the syntax right.
[ April 10, 2005: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use this:

<myprefix:mytag name="john" param1="<%=arraylist_1%>"

and describe a setter in your tag so:

public void setParam1(Object o)
{
...
}

it works
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic