Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lazy action form problem

 
BC claudio
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how come it always ends up with an exception?

javax.servlet.ServletException: Exception creating bean of class org.apache.struts.validator.LazyValidatorForm: {1}

http://www.niallp.pwp.blueyonder.co.uk/lazyactionform.html


Define the form in the struts-config.xml:

<struts-config>

<form-beans>
<form-bean name="lazyForm" type="org.apache.struts.validator.LazyValidatorForm"/>
</form-beans>

<action-mappings>
<action path="/myActionPath" type="myPackage.MyAction" name="lazyForm" validate="true"/>
</action-mappings>

</struts-config>

Set up the jsp in the usual way.

<html:form action="/myActionPath">

<h2>Simple Property Example</h2>

Customer Number: <html:text property="custNo"/>
Customer Name: <html:text property="custName"/>

<h2>Mapped Property Example</h2>

Street: <html:text property="address(street)"/>
Town: <html:text property="address(town)"/>
State: <html:text property="address(state)"/>
Country: <html:text property="address(country)"/>

<h2>Indexed Property Example</h2>

<logic:iterate id="products" property="products">
Product Code: <html:text name="products" property="code" indexed="true"/>
Product Description: <html:text name="products" property="description" indexed="true"/>
Product Price: <html:text name="products" property="price" indexed="true"/>
</logic:iterate>

</html:form>

Use in the Action by casting the ActionForm to a DynaBean.

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServeletRequest request,
HttpServletResponse response) throws Exception {

// Cast form to DynaBean
DynaBean dynaForm = (DynaBean)form;

// Use the DynaBean
String custNo = (String)dynaForm.get("custNo"); // simple
Map address = (Map)dynaForm.get("address"); // mapped
List products = (List)dynaForm.get("products"); // indexed

... etc etc

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic