The way lazy DynaBeans work is that when a  property's indexed/mapped getter
or setter is called it automatically instantiates the indexed/mapped
property - i.e.. for indexed properties thats the i.e. get(name, index) or
set(name, index, value) methods and for mapped properties thats the
get(name, key) or set(name, key, value) methods.

The IterateTag isn't using the indexed methods - its just doing a get(name)
to retrieve the whole array/list and since the property isn't defined to the
lazy bean it can't know whether its an indexed property or not - hence your
getting a null returned.

In the case of your mapped properties - those tags (e.g. <html:text>) are
calling the mapped getters to retrieve the property value and thats why they
are working.

In the scenario where you haven't prepared the form in an Action first
(setting up the indexed property - empty if required) then you need to
define that property in the struts-config.xml, so that the lazy form knows
its an indexed property and instantiates it appropriately. Something like...

  <form-bean name="lazyForm"
          type="org.apache.struts.validator.LazyValidatorForm">
     <form-property name="products" type="java.util.ArrayList" />
  </form-bean>

That will avoid the problem you're having.

Even if you populate an empty indexed property before there is still an
issue when using validator - it can't cope with null indexed properties and
so with 'request' scope forms in that scenario you would also have to do the
above.

http://struts.apache.org/api/org/apache/struts/validator/LazyValidatorForm.html

Niall

----- Original Message ----- 
From: "Jörg Herbst" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 09, 2004 9:01 PM
Subject: Problems with LazyValidatorForm


> Hi,
>
> I've got a Problem using the LazyValidatorForm while using indexed
properties.
>
> I tried to use the examples found at
http://www.niallp.pwp.blueyonder.co.uk/ using
> the following code:
>   <html:form action="/myActionPath" >
>     <html:text name="lazyForm"  property="labelValue" />
>     <html:text name="lazyForm"  property="map(foo)" />
>     <html:text name="lazyForm"  property="map(fool)" />
>     <logic:iterate name="lazyForm"  id="products" property="products">
>         Product Code:        <html:text name="products" property="code"
indexed="true"/>
>         Product Description: <html:text name="products"
property="description" indexed="true"/>
>         Product Price:       <html:text name="products" property="price"
indexed="true"/>
>     </logic:iterate>
>     </html:form>
>
> There are no properties  configured at the struts-config.xml. The simple
properties
> works well and also the maped properties work fine. But I get some
headache with the
> indexed properties. Running the shown code I'll get a JSP Exception with
"No collection found".
> This is correct, cause the first there is no property product in bean
lazyForm. Why do I get
> such an exception using indexed properties and no exception using maped
properties?
>
> I'm looking for a simple solution where I can provide a fixed number of
indexed properties
> for a web based input form. I'm thinking of some code like the following:
> <c:forEach begin="0" end="2" var="i">
>     Enter your <c:out value="${i}"> property:
>     <html:text name="lazyFormat" property="myProperty" indexed="true"/>
> </c:forEach>
>
> where I can access the properties in the action class with:
> List myProperites = (List) (((DynaBean)form).get("myProperty"));
>
> Is there a way to realize such behavoir with the LazyForm? Or is there
maybe some other solution,
> using a DynaBean?
>
> Thanks
> Joerg
>
> ________________________________________________________________
> Verschicken Sie romantische, coole und witzige Bilder per SMS!
> Jetzt neu bei WEB.DE FreeMail: http://freemail.web.de/?mc=021193
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to