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

[794 byte] By [Java_Jaguara] at [2007-10-2 18:22:19]
# 1

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

masoodmjana at 2007-7-13 19:42:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
hi,thanks.....i get the hints from your code....but what should i write in my jsp struts html control..thnx...
Java_Jaguara at 2007-7-13 19:42:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Is it necessary to use struts html control?
masoodmjana at 2007-7-13 19:42:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
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..
Java_Jaguara at 2007-7-13 19:42:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...