Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

struts and the html:multibox tag

843836May 19 2005 — edited May 19 2005
Hello all and sorry for my english...

I have a little problem...

I have a jsp page with the next code:

...
<html:form action="anadir.do">
...
<logic:iterate name="Lista" id="categs" scope="request" type="com.entity.Categorias">
<html:multibox property="categorias" value="<%= String.valueOf(categs.getId_categoria()).toString() %>"/>
<bean:write name="categs" property="categoria"/>[/br>
</logic:iterate>
...
<html:submit value="Anadir"/>
</html:form>

So, if in the collection named "Lista" there are 2 objets "Categorias" you will see two verification controls. But I want that the 2 verification controls are checked initiality.
In order to do this I codify the next bean for the form:

import org.apache.struts.action.ActionForm;

public class Anadirform extends ActionForm {
private String nombre = "";
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
private String[] categorias = {"1","2"};
public String[] getCategorias() {
return categorias;
}
public void setCategorias(String[] categorias) {
this.categorias = categorias;
}
}

assigng to the "categorias" property the initial values "1" and "2". Then these values are the same that those that you obtain when proccesing <%= String.valueOf(categs.getId_categoria()).toString() %> and the verification control remain initiality check...

But there is a PROBLEM: When I send the form y run the correct action class, if I leave unchecked both verification controls (manuallity), then:

...
Anadirform anadirForm = (Anadirform)form;
...
String[] cat = anadirForm.getCategorias();
...

what I get is a array of strings with 2 elements, when it shouldn't be any element. The problem appears when initializing the "categorias" property in the bean of the form... this is obvious

�solutions?

Thank you all
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2005
Added on May 19 2005
1 comment
260 views