struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <shirishchandra.sakh...@ubs.com>
Subject RE: problem with indexed properties
Date Fri, 13 Feb 2004 15:18:14 GMT
can you get the html code generated by your jsp?(using view source on that perticular page).The
parameter name generated may be of help...

But i can immediately see one problem.
The example you are refering to contains List Of beans...So when a parameter reference like
emp[i].name is created , it will be resolved as getEmp(i).getName();
But in your case, getCandlist(index) wil return a string itself.So on string how will you
cal setter.It is not a bean with a setter method.

I have not used indexed tags.But have a look at the parameter reference created in HTML.It
will help you to understand whats goign on...

HTH.
regards,
Shirish

-----Original Message-----
From: Shyam A [mailto:struts_newbie@yahoo.com]
Sent: Friday, February 13, 2004 4:04 PM
To: Struts Users Mailing List
Subject: problem with indexed properties


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


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