tags:

views:

896

answers:

2

I m passing multiple attributes in my custom tag like

&lt mytag Firstname="Thadeus" Lastname="Jones" &gt

Then how would I access the individual attributes in the TagHandler class..

Kindly specify any suggestions..

Regards, Vinayak

A: 

Hi,

Not really the answer to what you asked, but I hate (ie have never written) TagHandler's but I love tag files. Lets you write custom tags using jsp files. You probably know about them and are not available/applicable - but thought I'd mention them just in case.

Chris Kimpton
+2  A: 

In order to access the parameters your TagHandler class should define the private members and provide accessor methods.

public class TagHandler extends TagSupport {
    private String firstName;
    private String lastName;

    public void setFirstName(String firstname) { firstName = firstname; }
    public void setLastName(String lastname) { lastName = lastname;}
}

you can then access the parameters through the TagHandler variables.

public int doStartTag() throws JspException {
    pageContext.getOut().print(lastName + ", " + firstName);
}

If you still have problems double check your naming conventions, the Java interpeter is trying to guess what the setter method is. So if your parameter is "FirstName" than the set method must be "setFirstName" if the parameter is "lastname" the set parameter must be "setlastname". I perfer to follow the former, since it is the standard Java naming convention.

ShaneB
Yea.. while I m just doing this stuff, I m getting the errorUnable to find the setter method for the attribute: firstnameI have specified the attribute name in the tld file..what might b the problem..
Vinayak.B