Greetings. 
 
I am trying to use DynaActionForm with standard java bean and getting
error while submitting the request. The error is 
    javax.servlet.ServletException: BeanUtils.populate() 
    ....
    root cause 
    java.lang.IllegalArgumentException: No bean specified
    ...
 
The details are.
 
struts-config.xml
...
<form-beans>
        <form-bean 
             name="Sample3Form" 
            dynamic="true"
type="org.apache.struts.action.DynaActionForm">
             <form-property  name="ContactDTO"
type="com.JFSample.model.vo.Sample3"/>
        </form-bean>
    </form-beans>
...
<form-beans>
 
<action-mappings>
     <action path="/editSample3"
                type="com.JFSample.struts.Sample3Action"
                name="Sample3Form"
                scope="request">
            <forward name="success" path="/Sample3Detail.jsp" />
            <forward name="failure" path="/Sample3Detail.jsp" />
        </action>
 <action-mappings>
 
The standard java bean class (ValueObject/DTO)
 
package com.JFSample.model.vo;
public class Sample3
{
    public Sample3 ()    {    }
    public Integer getContactID() { return contactID;    }
    public void setContactID ( Integer _value) {        contactID =
_value;    }
    public String getFirstName() { return firstName;    }
    public void setFirstName ( String _value) { firstName = _value;    }
    public String getLastName() { return lastName;    }
    public void setLastName ( String _value) { lastName = _value;    }
    public String getEmailAddress() { return emailAddress;    }
    public void setEmailAddress ( String _value) { emailAddress =
_value;    }
 
    private Integer contactID = 0;
    private String firstName = " ";
    private String lastName = " ";
    private String emailAddress = " ";
}    
 
Action form (Sample3Action)
 
package com.JFSample.struts;
 
import java.io.IOException;
import java.util.Hashtable;
import java.util.Locale;
import java.sql.Timestamp;
import java.util.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import org.apache.commons.beanutils.*;
import org.apache.struts.util.MessageResources;
import com.JFSample.model.vo.Sample3;
 
public final class Sample3Action extends Action {
    static final String SUCCESS_MAPPING = "success";
    static final String FAILURE_MAPPING = "failure";
 
    public Sample3Action() { super();    }
 
    protected ActionForward newSample3(HttpServletRequest request,
                                                ActionMapping mapping,
                                                ActionErrors errors,
                                                ActionForm form,
                                                HttpSession session) {
        System.out.println("Reached newSample3");
        DynaActionForm formData = (DynaActionForm) form;

        Sample3 valueObj = new Sample3();
        valueObj.setContactID(new Integer(1));
        valueObj.setFirstName("MyFirstName");
        valueObj.setLastName("MyLastName");
        valueObj.setEmailAddress("MyEmailAddress");
 
      try {
         PropertyUtils.setNestedProperty(formData, "ContactDTO",
valueObj);
       } catch (Exception e) {.... }
        return (mapping.findForward(SUCCESS_MAPPING));
 }
 
    public ActionForward execute(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
                                throws IOException, ServletException {
 
        HttpSession session     = request.getSession();
        ActionErrors     errors      = new ActionErrors();
        Locale           locale      = (Locale)
session.getAttribute(Action.LOCALE_KEY);
        MessageResources messages    = getResources();
        String action = request.getParameter("action");
        if (action == null )
            action = "new";
        if (action.equals("new")) {
            return newSample3( request, mapping, errors, form, session);
}
        if (action.equals("update")) { return updateSample3( request,
mapping, errors, form, session); }
        return (mapping.findForward(FAILURE_MAPPING));
    }
 
    protected ActionForward updateSample3(HttpServletRequest request,
                                                ActionMapping mapping,
                                                ActionErrors errors,
                                                ActionForm form,
                                                HttpSession session) {

        DynaActionForm formData = (DynaActionForm) form;
        Sample3 valueObj = null;
          try {
         valueObj = (Sample3) 
          PropertyUtils.getNestedProperty(formData, "ContactDTO");
        } catch (Exception e) {System.out.println(e.getMessage());  }
 
        Integer contactID = new Integer(0); 
        String firstName = ""; 
        String lastName = ""; 
        String emailAddress = ""; 
 
        contactID = valueObj.getContactID();
        firstName = valueObj.getFirstName();
        lastName = valueObj.getLastName();
        emailAddress = valueObj.getEmailAddress();
 
        System.out.println("ContactID = " + contactID.toString());
        System.out.println("FirstName = " + firstName);
        System.out.println("LastName  = " + lastName);
        System.out.println("Email     = " + emailAddress);
        return (mapping.findForward(SUCCESS_MAPPING));
    }
}
 
The JSP part (Sample3Detail.jsp)
 
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<link rel="StyleSheet" href="css/style.css" type="text/css">
<head><title>Edit Sample3</title><script language=Javascript
src="js/validations.js"></script>
<script language=Javascript>
    function validate( vForm) {
        vForm.submit();
    }
</script>
 
</head><body class=bodyStyle>
<span class=errorMessageStyle>
<html:errors/></span>
<html:form action="/editSample3.do?action=update">
<TABLE cellpadding=0 cellspacing=0 class=tableBorderStyle>
    <tr>        <td class=formTitleStyle>Edit Sample1</td>    </tr>
    <tr><td>    <TABLE class=tableStyle>    <TR>
        <td class=formLabelStyle>ContactID</td>
        <td class=formInputStyle><html:text  
         styleClass="formInputStyle" 
         property="ContactDTO.contactID" size="30"/></td>
    </tr>
    <TR> <td class=formLabelStyle>FirstName</td>
    <td class=formInputStyle><html:text 
         styleClass="formInputStyle" 
         property="ContactDTO.firstName" size="30"/></td>
    </tr>
    <TR>
        <td class=formLabelStyle>LastName</td>
        <td class=formInputStyle><html:text
         styleClass="formInputStyle" 
         property="ContactDTO.lastName" size="30"/></td>
    </tr>
    <TR> <td class=formLabelStyle>EmailAddress</td>
        <td class=formInputStyle><html:text  styleClass="formInputStyle"

         property="ContactDTO.emailAddress" size="30"/></td>
    </tr>
    <tr>  <td colspan=2>
            <html:button styleClass="formButtonStyle" property="ok"
onclick="validate(this.form)" value="Submit"/>
            <html:reset styleClass="formButtonStyle"/>
        </td>
    </tr>    </TABLE>    </td></tr></TABLE></html:form></body></html>

Test sceneario...
 
from browser if we do
http://localhost:8080/.../editSample3.do?action=new it works 
while submitting the request (
http://localhost:8080/.../editSample3.do?action=update ) we get the
above error.
 
The above error we get before even reaching the action class execute
method.
We did refer to the document from
http://www.apache.org/~jvanzyl/jakarta-commons/beanutils/apidocs/org/apa
che/commons/beanutils/package-summary.html#dynamic

 Our understand is the existing javabean(DTO/ValueObjects) can be used
with DynaActionForm and we need not create DynaBean. 

Could some one guide us please. 

Thanks for your cooperation and help.

-guna

 

Reply via email to