struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shyam A <struts_new...@yahoo.com>
Subject problem with indexed properties
Date Fri, 13 Feb 2004 15:03:55 GMT
Hello,

I'm trying to use indexed propeties in my form bean
(ActionForm) to handle an array of text fields
generated dynamically. Initially, I used a String[] to
hold the text field values, and had a problem when
validation errors occured in my validate() method,
i.e, the values of the text fields were not retained.

To work around that, I'm trying indexed properties,
but it has not helped my cause, only added to my
woes:(

With indexed properties, I don't seem to get the
values of the textfields in the form bean(I get a
NullPointerException on form submission). Also, the
values in the textfields are not retained on
validation errors.
When my JSP is displayed initially, I seem to get some
null/junk entries in the text fields.

I used the sample code from
http://marc.theaimsgroup.com/?l=struts-user&m=104815589928698&w=2
for my form bean.

So, in my ActionForm, I have

#########################################
private List candList = new ArrayList(); //previoulsy
was String[]

public List getCandList() 
   {
      return candList;
   }
		
public void setCandList(List aCandList) 
   {
      candList = aCandList;
   }


public String getCandList(int index) 
   {
	  while(index >= candList.size()){

		candList.add(new String(""));

		}	
      return (String) candList.get(index);
   }


 public void setCandList(int index,String aCand) 
   {
      candList.set(index,aCand);
   }

-----------------------------------------------------

I do not set candList=null in the reset() method.

In my Action class (DispatchAction), I have two
methods - get() and submit() corresponding to "get"
and "submit" requests on my JSP. In the get() method,
I tried populating the candList in my form bean with
dummy values, corresponding to the number of text
fields(obtained from database).

In my JSP, I use

<html:text property="candList" size="25"
maxlength="25" indexed="true"/>

within a <logic:iterate> tag for a collection (of
business entities).


---------------------------------------------
I guess there may be something wrong with the
getters/setters in my ActionForm, as my form bean
doesn't seem to get the user entered values in the
text fields.
Am I missing something in the reset() method?

Could somebody tell me what I'm doing wrong.

I'm not sure if the candList in my form bean should be
populated with dummy values in the get() method of my
Action class.

I tried in vain to find some good examples of form
beans with indexed properties..most of the examples
are for DynaActionForm, and I'm really strutting in
the dark:(

Any help/pointers will be greatly appreciated.


Thanks,
Shyam



__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message