i want to use getter, setter and is for one attribute together in one class just i given below, Is it possible...
public boolean isLength(){ return true; }
public void setLength(String length) { this.m_length = length; }
public String getLength() { return m_length; }
Beacause i got the error like that : "Unable to find setter method for attribute : length
Why that happens.
Regards, Indravadan Patel
abhishek pendkay
Ranch Hand
Joined: Jan 01, 2007
Posts: 184
posted
0
what is the name of your property , is it length or m_length cause you are appearing to set the value of m_length. and secondly why do you need the isLength() method It appeares from your code that the name of our property is m_length and not length youe method reads m_length = length so you are setting the value of m_length
as long as the getter and setter have the same name it doesn't matter that the attribute is called m_length.
I advise against supplying isLength() for something that is not a boolean value. It is misleading and may lead to errors. We often have getValue and isValue when it is a boolean, but otherwise not.
Originally posted by David O'Meara: as long as the getter and setter have the same name it doesn't matter that the attribute is called m_length.
I advise against supplying isLength() for something that is not a boolean value. It is misleading and may lead to errors. We often have getValue and isValue when it is a boolean, but otherwise not.
Hi,
I have use length in JSP as attribute and set, get and is methos in Tag handler classs. i have defined the length attribute in tld file.
Regards and thanks, Indravadan
Indravadan T Patel
Greenhorn
Joined: Sep 09, 2007
Posts: 29
posted
0
Hi All,
i here show you my JSP, TLD and Taghandler class. ---------------------------------- <%@ taglib uri="/WEB-INF/tlds/SimpleTag.tld" prefix="csajsp" %> <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body>
public int doStartTag() { try { JspWriter out = pageContext.getOut(); int len = Integer.parseInt(getLength()); out.println("Multiplication :" +len*len); } catch (Exception ex) {
}
return (SKIP_BODY); }
public boolean isLength(){ return true; }
public void setLength(String length) { this.length = length; }
public String getLength() { return length; }
} --------------------------------- and i got error like that :
org.apache.jasper.JasperException: /index.jsp(11,12) Unable to find setter method for attribute: length org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
The problem here comes from the isLength method. It is causing confusion as it looks like a getter method for the length attribute. You should rename it to something else.
Indravadan T Patel
Greenhorn
Joined: Sep 09, 2007
Posts: 29
posted
0
Originally posted by Christophe Verre: The problem here comes from the isLength method. It is causing confusion as it looks like a getter method for the length attribute. You should rename it to something else.
Hi i know that the problem with isLength but i want to put that one in my code and i want to resolve that problem
Did you want to try removing it to see if the code works, then maybe we can start from a point that works rather than trying to guess what the issue is?
Please?
Indravadan T Patel
Greenhorn
Joined: Sep 09, 2007
Posts: 29
posted
0
Originally posted by David O'Meara: Did you want to try removing it to see if the code works, then maybe we can start from a point that works rather than trying to guess what the issue is?
Please?
Hi,
I have remove that isLength() from code and it was working fine.
Regards, Indravadan patel
Indravadan T Patel
Greenhorn
Joined: Sep 09, 2007
Posts: 29
posted
0
Originally posted by David O'Meara: Did you want to try removing it to see if the code works, then maybe we can start from a point that works rather than trying to guess what the issue is?
Please?
Hi,
I have removed the isLength() method from the code and at that time it is working fine. If i put the setLength(boolean length) with isLength(), at that time the String setLength and getLength methods are not working menas that i can not get error but the result is not as per expectation.
Then you need to call it something else. The server is using reflection to match the values with getters and setters on the object. If you do not set up your object according to the JavaBean specification, then your code is likely to be unpredictable and wrong.