|
Hi Niall, Thanks for your inputs. I followed your methodology with slight changes. I have a class MCDynaClass which equals your LazyDynaClass. Instead of having a separate bean as LazyDynaBean, i extended the DynaActionForm as MCDynaActionForm and overridden the set methods as per my requirement. The entry in the struts-config.xml will be like <form-beans> <form-bean name = "severityForm" type = "com.adventnet.client.struts.action.MCDynaActionForm"/> </form-beans> <action path = "/severityDetails" type = "com.adventnet.client.struts.action.SeverityDetailsAction" name = "severityForm" > <forward name = "details" path = "/jsp/detailsPage.jsp"/> </action> <action path = "/updateSeverity" type = "com.adventnet.client.struts.action.UpdateSeverityDetailsAction" name = "severityForm" input = "/severityDetails.do" scope = "session"> <forward name = "success" path = "/jsp/results.jsp"/> </action> In the ActionClass i will get the DataObject(my own object) and set it to the form through the setDataObject method. MCDynaActionForm userForm = (MCDynaActionForm) form; userForm.setDataObject(newDO); By this way i am able to populate the values dynamically. The problems comes when i am submitting the form. When the form is submitted, the instance of the form that i am getting in the action class is different. As a result, I cannot update the dataObject as it is null. I could not figure out where i have gone wrong. I have attached my source. Kindly help me. Thanks Shanmugam PL Niall Pemberton wrote: Yup, thats it - plus dynamic="true" <form-bean name="fooForm1" type="lib.framework.struts.LazyValidatorActionForm" dynamic="true" /> <form-bean name="fooForm2" type="lib.framework.struts.LazyValidatorActionForm" dynamic="true" /> <form-bean name="fooForm3" type="lib.framework.struts.LazyValidatorActionForm" dynamic="true" /> <form-bean name="fooForm4" type="lib.framework.struts.LazyValidatorActionForm" dynamic="true" />Oh, I noticed an error in LazyValidatorForm, its declared as "abstract" - which it shouldn't be - I don't use it directly, I use LazyValidatorActionForm which extends it. Niall ----- Original Message ----- From: "Mark Lowe" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Tuesday, March 09, 2004 8:53 AM Subject: Re: Populating form Elements from another object. |
package com.adventnet.client.struts.action;
import org.apache.struts.action.DynaActionForm;
import java.lang.reflect.Array;
import java.util.*;
import com.adventnet.persistence.ejb.*;
import com.adventnet.persistence.*;
import com.adventnet.nms.ms.config.client.ConfigurationCache;
import org.apache.commons.beanutils.*;
public class MCDynaActionForm extends DynaActionForm {
protected MCDynaClass wccDynaClass = null;
public MCDynaActionForm(){
wccDynaClass = new MCDynaClass();
}
public DynaClass getDynaClass() {
return (this.wccDynaClass);
}
public void set(String name, Object value) {
System.out.println("*********** SHAN : Set method
called. Updation takes place in data object also ********** " + dataObject);
System.out.println("*********** SHAN : HashValue is
********** " + hashCode());
((MCDynaClass)getDynaClass()).add(name,
value.getClass());
dynaValues.put(name, value);
if(dataObject != null){
String[] values = name.split(":");
String tableName = values[0];
String columnName = values[1];
try{
// This will update in
all the rows that are present with this value.
dataObject.set(tableName, columnName, value);
}
catch(Exception e){
e.printStackTrace();
}
}
}
public void set(String name, int index, Object value) {
((MCDynaClass)getDynaClass()).add(name,
value.getClass());
dynaValues.put(name, value);
}
public void set(String name, String key, Object value) {
((MCDynaClass)getDynaClass()).add(name,
value.getClass());
dynaValues.put(name, value);
}
public DataObject dataObject = null;
public void setDataObject(Object dataObject){
this.dataObject = (DataObject) dataObject;
setFormValues();
}
public Object getDataObject(){
return dataObject;
}
public void setFormValues(){
try{
List tableList =
dataObject.getTableNames();
if(tableList != null &&
tableList.size() > 0){
int size =
tableList.size();
for(int i = 0; i <
size; i++){
String
tableName = (String) tableList.get(i);
Row
row = dataObject.getFirstRow(tableName);
List
columnNames = row.getColumns();
List
columnTypes = row.getColumnTypes();
if(columnNames != null && columnNames.size() > 0){
int count = columnNames.size();
for(int j = 0; j < count; j++){
String columnName = (String) columnNames.get(j);
Object value = row.get(columnName);
set(tableName + ":" + columnName, value);
}
}
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
public DataObject createDataObject() throws DataAccessException{
try{
DataObject createdDO = null;
PersistenceRemote persistenceAPI =
ConfigurationCache.getPersistenceAPI();
createdDO =
persistenceAPI.constructDataObject();
Iterator set =
dynaValues.keySet().iterator();
Properties rows = new Properties();
Row row = null;
while(set.hasNext()){
String name = (String)
set.next();
Object value =
dynaValues.get(name);
String[] values =
name.split(":");
String tableName =
values[0];
String columnName =
values[1];
row = (Row)
rows.get(tableName);
if(row == null){
row =
new Row(tableName);
rows.put(tableName, row);
}
row.set(columnName,
value);
}
Enumeration enum =
rows.propertyNames();
while(enum.hasMoreElements()){
String
currentTableName = (String) enum.nextElement();
Row currentRow = (Row)
rows.get(currentTableName);
createdDO.addRow(currentRow);
}
return createdDO;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

