You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2002/05/28 23:34:09 UTC

DO NOT REPLY [Bug 9471] New: - Upcasting FormBeans fails when finding exiting instance.

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=9471>.
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=9471

Upcasting FormBeans fails when finding exiting instance.

           Summary: Upcasting FormBeans fails when finding exiting instance.
           Product: Struts
           Version: 1.1 Beta 1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Utilities
        AssignedTo: struts-dev@jakarta.apache.org
        ReportedBy: cjohnson@arrayservices.com


I have  a set of FormBeans that extend a FormBean I wrote called ReportForm.
ReportForm extends ActionForm. I want to prepopulate some of the fields (those
that exist in ReportForm) with a dynamically created instance of the ReportForm
object.

// My Dynamic Redirector's Source
        Long rptId = new Long(request.getParameter("reportId"));
        User user = (User)session.getAttrubute("user");
        Category cat = Category.getInstance(this.getClass().getName());

        ReportForm form = new ReportForm();
        Class cls;
        try
        {
            cls = Class.forName(objectName + "Form", true, 
                    this.getClass().getClassLoader());
            form = (ReportForm)
                    cls.getConstructor(null).newInstance(null);
        }
        catch (Exception e)
        {
            cat.error("Cast did not work: " + e.getMessage());
            e.printStackTrace();
        }

        form.setReportId(rptId.toString());
        String temp = ((ReportModel)this.getServletContext().getAttribute(
                "ReportModel")).getReportDescription(rptId.longValue());
        form.setDescription(temp);
        form.setEmail(user.getEMail());
        form.setLoginId(user.getLoginId());
        form.setCoCode(user.getCoCode());
        form.setOutputType("HTML");

        req.getSession().setAttribute("ReportRequest", form);
        this.getServletContext().getRequestDispatcher(
                "/execute/reports/" + objectName).forward(req,resp);

<!-- struts-config.xml -->
<form-bean    name="ReportRequest"
              type="ReportForm"/>

<action     path="/reports/DateRangeOnly"
            name="ReportRequest"
            type="DateRangeOnlyAction"
            input="/jsp/reports/DateRangeOnlyForm.jsp"
            scope="session">
  <forward name="valid" path="/jsp/reports/SubmitReportRequest.jsp"/>
  <forward name="invalid" path="/jsp/reports/DateRangeOnlyForm.jsp"/>
</action>

// DateRangeOnlyForm.jsp
<%@ page import="org.apache.log4j.Category,
                 ReportConstants, DateRangeOnlyForm"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/afweb.tld" prefix="afweb" %>
<jsp:useBean id="ReportRequest" scope="session"
             type="DateRangeOnlyForm"/>

After figuring out where to send the request and populating the object properly,
the jsp can  downcast the ReportRequest object to the appropriate type with the
useBean tag. In RequestUtils, the determination for creating a new bean versus
recycling an existing bean in the request or scope sessions compares strings of
the class names and cannot handle subclasses.

Attached is a patch that should fix this. You might want to check the code for
conformance with the guidlines and maybe change the exception handling. I copied
it from the DynaBean logic below this section.

The problem is that RequestUtils.java finds the

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>