I want to accomplish dynamic property defs by specifying properties in a DynaActionForm from a database value. Not only define values for the attributes but also define the attributes themselves. Is this possible?
I define a property in EditProductsAction by using DynaActionForm dynaFrom = new DynaActionForm(); dynaFrom.set(propertyNameFromDB, new Integer(55)); and in the JSP i try to refer to this as: <html:text property="<%= propertyNameFromDB>" /> I get the NullPointerException whose stack trace is given below. It is occuring inside DynaActionForm.java on the call to getDynaClass() protected DynaProperty getDynaProperty(String name) { DynaProperty descriptor = getDynaClass().getDynaProperty(name); /* Here */ ............ } Can anyone help me on what I am doing wrong? Also what is the difference in the "key" and "name" of the form property? Which method should I use in this case? Thanks a lot. Exception Stack Trace: ----- Root Cause ----- java.lang.NullPointerException at org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java: 551) at org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:365) at com.etilize.cms.web.actions.EditProductSpecsAction.execute(Unknown Source) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces sor.java:446) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510) > You can auto-initialize primitives (and things like that) by using the > "initial" attribute on the <form-property> element. But initializing a > property that is an object requires an *instance* of that object to be > available. It's not appropriate for a general purpose framework to just > go and try to create such things, and hope that it's OK. > > A couple of strategies to consider: > > * Create the form bean in a separate Action that can pre-initialize > all of the necessary properties for you. This will often be the > best course of action when you are creating edit forms for modifying > existing database data. > > * Create a custom subclass of DynaActionForm with a reset() method > that, among other things, instantiates your credit card object > and stores it: > > put("creditCard", new my.package.CreditCard()"); > > Struts calls the reset() method for you when *it* creates the form > bean instance. If you create one yourself, you'll need to remember > to call this method. > > > Craig -- To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>