How to generate dynemic GET/SET Method in Struts.....
hi,
experts,
i m doing struts application and i get struct at generatting GET/SET properties for my Dynemic html form in that form i fetch control name and related properties from database and i want to access this properties in action with the help of form which generates dynemic GET/SET properties depends on form controls
how would i do please give some hints...
example:
my html form:
<html:text name="bpmAttrForm" property="attrName"></html:text>
.
.
. dynemic controls( i don't no how many )
my form in struts
public void getX()
{
}
public void setX()
{
}
.... dynemic GET/SET Properties ( i don't no how many )
like this....
thnks.....
Hi ,
You would have to create a Dynamic form class extending DynaActionForm and ovrride get and set method. In the implementation you access the dyanValues HashMap of DyanActionForm to set and get values from it.
package yourpackage;
import org.apache.struts.action.DynaActionForm;
public class DynaForm extends DynaActionForm
{
public Object get(String name)
{
Object value = dynaValues.get(name);
return (value);
}
public void set(String name, Object value)
{
dynaValues.put(name, value);
}
}
now in your struts configuration would be
<form-bean name="myDynaForm" type="yourpackage.DynaForm" />
if your action class execute method you would have to add and retrive your form properties through the map.
DynaActionForm myDynaForm = (DynaActionForm) form;
String prop1 = (String)myDyanaForm .get(propertyName);
in your jsp you can access properties using expression library
${myDynaForm.map.propertyName}
Cheers
Masood
hi,can u tell me what should i write in my jsp page ,form , actioni have to create dynaAction (which is default from struts) or my ownand how to access those methods which is declared in formthanks..