Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Recover ArrayForm in Action

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i have searched this question in Search utility but i didn�t found the solution. In a jsp page, i have a variable form. Sorry for my english. Part of code is:

----Action that recover information for modify in a jsp page----

session.setAttribute("listaejercicios",listacontrol);




----Jsp Page----

<html:form action="altacontrolSubmit.do?method=AltaControlEjerciciosAction">

<logic:iterate id="datos" name="listaejercicios">
<html:text name="datos" property="tiempoteorico" indexed="true"/>
....


The jsp page work fine and each property shows it value. One example is two exercises like:

<input type="text" name="datos[0].tiempoteorico" value="25">
<input type="text" name="datos[1].tiempoteorico" value="30">


I don�t know how many exercises there is so my form is:

---MyForm---

public class ListaControlForm extends ValidatorForm{

private ControlForm[] listacontrol;

public ListaControlForm(){
listacontrol = new ControlForm[0];
}

public void setListacontrol(ControlForm[] listacontrol){
this.listacontrol = listacontrol;
}

public void setListacontrol(int index,ControlForm listacontrol){
this.listacontrol[index] = listacontrol;
}

public ControlForm[] getListacontrol(){
return listacontrol;
}

public ControlForm getListacontrol(int index){
return listacontrol[index];
}

public void reset(ActionMapping mapping, HttpServletRequest request){
this.listacontrol = new ControlForm[0];
}



public class ControlForm{

private String tiempoteorico;

public ControlForm(){
tiempoteorico = null;
}

public void setTiempoteorico(String tiempoteorico){
this.tiempoteorico = tiempoteorico;
}

public String getTiempoteorico(){
return tiempoteorico;
}
}
}




I�d like in Action recover all values for storing in DB but i don�t know this issue.

---My Action---

ListaControlForm listacontrol = (ListaControlForm) form;

for (int i=0; i<listacontrol.length(); i++){
//shows an error :length cannot be resolved or is not a field
}


I think this error is due to i have to create one method in ListaControlForm like as:

public int Longitudlistacontrol(){
return listacontrol.length;
}

but if i put in Action:
ListaControlForm listacontrol = (ListaControlForm) form;
int tamano = listacontrol.getLongitudlistacontrol();

shows an error again.

Anyone can help me? or any idea?
 
Manuel Sanchez Iba�ez
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I continue with my problem. I have readed about DynaActionForm and DynaValidatorForm. I think my problem will be resolved with this option but my tests don�t work.

I hope explain clearly (my english is bad). I want show in a jsp form a unknown numbers of Objects:

Pre-Action:


In a Jsp page:



My jsp page shows a good information:
<input type="text" name="controles[0].tiempoteorico" value="25">
<input type="text" name="controles[1].tiempoteorico" value="30">
....

According to information, i declare this in struts-config.xml:





So, the user can update/modify that values and when it submitted the form, i want recover all values.


My Action:


This Action cause an error:
excepci�n
javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:497)
....

causa ra�z
java.lang.ArrayIndexOutOfBoundsException
java.lang.reflect.Array.get(Native Method)
org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:252)
org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:386)
....


Any idea will be grateful.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic