DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13597>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13597

ClassCastException in <jsp:setProperty if editor class set in BeanInfo

           Summary: ClassCastException in <jsp:setProperty if editor class
                    set in BeanInfo
           Product: Tomcat 4
           Version: 4.0.1 Final
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: Jasper
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


description : FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

Java 2 Enterprise Edition version 1.3.1, build 1.3.1-b17

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Apache Tomcat/4.0.1
Sun ONE Studio 4.0 update 1

A DESCRIPTION OF THE PROBLEM :

When an editor class is set to the property in the
BeanInfo, the jsp tag setProperty throw a
ClassCastException.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. execute the given web application
2. Go to URL http://localhost:8081/webapp/login.jsp
3. type the username toto
4. type enter.
5. you should see the exception

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected result:

Welcome toto

Actual Result:

ClassCastException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
root cause

org.apache.jasper.JasperException: Unable to convert string 'toto' to 
class
java.lang.String for attribute username: java.lang.ClassCastException
        at org.apache.jasper.runtime.JspRuntimeLibrary.convert
(JspRuntimeLibrary.java:184)
        at 
org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper
(JspRuntimeLibrary.java:267)
        at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper
(JspRuntimeLibrary.java:219)
        at org.apache.jsp.welcome$jsp._jspService(welcome$jsp.java:105)



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
File LoginBean.java
===================
public class LoginBean {
  private String username = "";
  public void setUsername(String username) {this.username = username;}
  public String getUsername() {return username;}
}
File LoginBeanBeanInfo.java
===================
import java.beans.*;
import java.io.*;

public class LoginBeanBeanInfo extends SimpleBeanInfo {
  private Class beanClass = LoginBean.class;

  public LoginBeanBeanInfo() {
  }

  public PropertyDescriptor[] getPropertyDescriptors() {
    try {
      PropertyDescriptor _username = new PropertyDescriptor("username",
beanClass, "getUsername", "setUsername");
      _username.setDisplayName("username");
      _username.setShortDescription("username");
      _username.setPropertyEditorClass(javax.swing.JTextField.class);
      PropertyDescriptor[] pds = new PropertyDescriptor[] {_username};
      return pds;
    }
    catch(IntrospectionException ex) {
      ex.printStackTrace();
      return null;
    }
  }
}
File login.jsp
===================
<html>
<head>
<title>login</title>
</head>
<jsp:useBean id="loginBeanId" scope="session" class="LoginBean" />
<body>
<h1>Login Page</h1>
<form method="post" action=<%= 
request.getContextPath()+"/welcome.jsp"%>
    <br>Username   :  <input name="username"><br>
    <input type="submit" name="Submit" value="OK">
    <input type="reset" value="Reset">
</form>
</body>
</html>

File welcome.jsp
===================
<%@page import="LoginBean"%>
<html>
<head><title>Welcome Page</title></head>
<body>

<jsp:useBean id="loginBeanId" scope="session" class="LoginBean" />
<jsp:setProperty name="loginBeanId" property="username" />
Welcome <jsp:getProperty name="loginBeanId"  property="username" />

</body>
</html>

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
replace the line
<jsp:setProperty name="loginBeanId" property="username" />
by
<%
    String s = request.getParameter("username");
    loginBeanId.setUsername(s);
%>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to