You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paride Perazzolo <tr...@despammed.com> on 2004/07/05 16:06:55 UTC

Using struts-nested tags

Hi folks,
I'm new to the list, so forgive me if I'm not respecting Netiquette or
asking off-topics.

I'm trying to render pieces of html using the following syntax:

from struts-config.xml the definition of the form follows:


<form-bean name="canalizzazioneCLDForm"
type="org.apache.struts.validator.DynaValidatorActionForm">   <form-property name="listaDanneggiati" type="java.util.ArrayList"/>
</form-bean>


into the jsp I wrote (MyBeanContainer has the method getListaDanneggiati()
which returns a ArrayList of beans):

<jsp:useBean id="beanContainer" class="com.mycompany.MyBeanContainer"
scope="session"></jsp:useBean>  ............  <html:form method="post"
action="/canalizzazione_cld.do">   <nested:root name="beanContainer">
      <nested:iterate  property="listaDanneggiati" >
          <nested:text styleClass="inputText" property="cognome"/><br/>
          <nested:text styleClass="inputText" property="nome"/><br/>
          <nested:iterate property="oggColpiti">             &nbsp;&nbsp;&nbsp;<nested:text styleClass="inputText"
             property="descrizioneGenerica"/><br/>
             &nbsp;&nbsp;&nbsp;<nested:text styleClass="inputText"
             property="tipoGenerico"/><br/>          </nested:iterate>
       </nested:iterate>
   </nested:root>
</html:form>



The html I actually get is:


...............
<input type="text" name="listaDanneggiati[0].cognome" value="SDFSDFDS"
class="inputText"><br/> <input type="text" name="listaDanneggiati[0].nome"
value="SDFSDF" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
type="text" name="listaDanneggiati[0].oggColpiti[0].descrizioneGenerica"
value="Trasportato" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
type="text" name="listaDanneggiati[0].oggColpiti[0].tipoGenerico"
value="Persona" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
type="text" name="listaDanneggiati[0].oggColpiti[1].descrizioneGenerica"
value="COSE" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input type="text"
name="listaDanneggiati[0].oggColpiti[1].tipoGenerico" value="Cosa/Animale"
class="inputText"><br/> <input type="text"
name="listaDanneggiati[1].cognome" value="SDFSDF" class="inputText"><br/>
<input type="text" name="listaDanneggiati[1].nome" value="SDFSDF"
class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input type="text"
name="listaDanneggiati[1].oggColpiti[0].descrizioneGenerica"
value="Trasportato" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
type="text" name="listaDanneggiati[1].oggColpiti[0].tipoGenerico"
value="Persona" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
type="text" name="listaDanneggiati[1].oggColpiti[1].descrizioneGenerica"
value="SDFSFSDF" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
type="text" name="listaDanneggiati[1].oggColpiti[1].tipoGenerico"
value="Cosa/Animale" class="inputText"><br/>  ...............

which is nice but not satisfying. I'd like to get something like:


<input type="text" name="beanContainer.listaDanneggiati[0].nome"
value="SDFSDF" class="inputText"><br/>

where the name property of the input text includes the root name, ie
"beanContainer".

I need this to manage the interactivity correctly. Infact what I actually
get when I submit the form is the following:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.RangeCheck(Unknown Source)
	at java.util.ArrayList.get(Unknown Source)
	at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:298)
	at
	org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:474)
	at
	org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
	at........



Thank you in advance...



-- 
Paride Perazzolo
tremalnaik@despammed.com




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


Re: Using struts-nested tags

Posted by Paride Perazzolo <tr...@despammed.com>.
>> <jsp:useBean id="beanContainer" class="com.mycompany.MyBeanContainer"
>> scope="session"></jsp:useBean>
>
> You shouldn't need the above on the page. You should set
> MyBeanContainer  with the id "beanContainer" into session or request
> scope in the Action  you are in "BEFORE" you get to this JSP page. The
> page will have it. No  need to use the useBean stuff.
>


ok, now I understand what you mean. I should never access session beans in
my jsp, but being aware of the 1-1 relationship between the page form and
the one which I defined in the struts-config.xml
So I'm going to update the form beans (using objects like containers and
navigators in session) in the related actions before passing control to
JSPs and/or after submitting the form.
I think this is the correct procedure to use.

thanks for your help

-- 
Paride Perazzolo
tremalnaik@despammed.com



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


Re: Using struts-nested tags

Posted by Rick Reumann <st...@reumann.net>.
Paride Perazzolo wrote:

> Hi folks,
> I'm new to the list, so forgive me if I'm not respecting Netiquette or
> asking off-topics.

Welcome to the list. Not off topic. Comments inline.

> I'm trying to render pieces of html using the following syntax:
> 
> from struts-config.xml the definition of the form follows:
> 
> 
> <form-bean name="canalizzazioneCLDForm"
> type="org.apache.struts.validator.DynaValidatorActionForm">   <form-property name="listaDanneggiati" type="java.util.ArrayList"/>
> </form-bean>
> 
> 
> into the jsp I wrote (MyBeanContainer has the method getListaDanneggiati()
> which returns a ArrayList of beans):
> 
> <jsp:useBean id="beanContainer" class="com.mycompany.MyBeanContainer"
> scope="session"></jsp:useBean>  

You shouldn't need the above on the page. You should set MyBeanContainer 
with the id "beanContainer" into session or request scope in the Action 
you are in "BEFORE" you get to this JSP page. The page will have it. No 
need to use the useBean stuff.


............  <html:form method="post"
> action="/canalizzazione_cld.do">   <nested:root name="beanContainer">
>       <nested:iterate  property="listaDanneggiati" >
>           <nested:text styleClass="inputText" property="cognome"/><br/>
>           <nested:text styleClass="inputText" property="nome"/><br/>
>           <nested:iterate property="oggColpiti">             &nbsp;&nbsp;&nbsp;<nested:text styleClass="inputText"
>              property="descrizioneGenerica"/><br/>
>              &nbsp;&nbsp;&nbsp;<nested:text styleClass="inputText"
>              property="tipoGenerico"/><br/>          </nested:iterate>
>        </nested:iterate>
>    </nested:root>
> </html:form>
> 
> 
> 
> The html I actually get is:
> 
> 
> ...............
> <input type="text" name="listaDanneggiati[0].cognome" value="SDFSDFDS"
> class="inputText"><br/> <input type="text" name="listaDanneggiati[0].nome"
> value="SDFSDF" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
> type="text" name="listaDanneggiati[0].oggColpiti[0].descrizioneGenerica"
> value="Trasportato" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
> type="text" name="listaDanneggiati[0].oggColpiti[0].tipoGenerico"
> value="Persona" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
> type="text" name="listaDanneggiati[0].oggColpiti[1].descrizioneGenerica"
> value="COSE" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input type="text"
> name="listaDanneggiati[0].oggColpiti[1].tipoGenerico" value="Cosa/Animale"
> class="inputText"><br/> <input type="text"
> name="listaDanneggiati[1].cognome" value="SDFSDF" class="inputText"><br/>
> <input type="text" name="listaDanneggiati[1].nome" value="SDFSDF"
> class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input type="text"
> name="listaDanneggiati[1].oggColpiti[0].descrizioneGenerica"
> value="Trasportato" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
> type="text" name="listaDanneggiati[1].oggColpiti[0].tipoGenerico"
> value="Persona" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
> type="text" name="listaDanneggiati[1].oggColpiti[1].descrizioneGenerica"
> value="SDFSFSDF" class="inputText"><br/> &nbsp;&nbsp;&nbsp;<input
> type="text" name="listaDanneggiati[1].oggColpiti[1].tipoGenerico"
> value="Cosa/Animale" class="inputText"><br/>  ...............
> 
> which is nice but not satisfying. I'd like to get something like:
> 
> 
> <input type="text" name="beanContainer.listaDanneggiati[0].nome"
> value="SDFSDF" class="inputText"><br/>

I don't sew why you would want this? The form bean property is the 
ArrayList listaDanneggiati so that's what will get set when you submit 
the form. Your form bean doesn't have a bean property "beanContainer" so 
you wouldn't even want that trying to be added.. you'd get a "no 
property 'beanContainer" found in form.." error.

> 
> where the name property of the input text includes the root name, ie
> "beanContainer".
> 
> I need this to manage the interactivity correctly. Infact what I actually
> get when I submit the form is the following:
> 
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> 	at java.util.ArrayList.RangeCheck(Unknown Source)
> 	at java.util.ArrayList.get(Unknown Source)
> 	at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:298)
> 	at
> 	org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:474)
> 	at
> 	org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
> 	at........

What scope is your canalizzazioneCLDForm given in the ActionMapping. The 
  quick way to avoid this problem is to make sure it has Session scope. 
If you don't give it session scope you'll have to do some other things 
to make sure their are the proper number of fields available to set in 
your nested arrays (annoying I know, but this comes up a lot on the list 
so search the archives some or in the mean time just use Session scope 
for your form to get it working).

-- 
Rick

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