probleme affichage vector
Bonjour a tous
je dois utiliser les struts pour un projet. Pour l'instant tout ce qui est validation de formulaire ca marche tres bien (exemple validation d'un compte client)
Par contre des lors que je dois afficher par exemple une collection d'objet en l'occurence des pizzas. je n'y arrive pas:
ce ke j'obtiens 16 17 com.eppizza.struts.source.Pizza@10ff62a
c'estr a dire l'adresse memoire.
mon code est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| //struts-config.xml
<form-bean name="collectionForm" type="com.epizza.struts.form.CollectionForm" />
<form-bean name="Pizza" type="com.epizza.struts.source.Pizza">
<form-property name="nom" type="java.lang.String" />
<form-property name="prix" type="java.lang.String" />
</form-bean>
<action
attribute="collectionForm"
input="/form/collection.jsp"
name="collectionForm"
path="/collection"
type="com.epizza.struts.action.CollectionAction" />
<action path="/collection2" type="com.epizza.struts.action.Collection2Action" />
//form
Vector v = new Vector();
Vector v2 = new Vector();
Vector v3 = new Vector();
int i = 0;
public CollectionForm() {
v.add("16");
v.add("17");
Pizza mapizza = new Pizza("calzone", "3");
v.add(mapizza);
}
public Vector getV() {
if (i == 0)
v2.add("19");
else
v2.add("21");
i++;
return v;
}
public Vector getV2() {
return v2;
}
public Vector getV3() {
return v3;
}
public void setV(Vector v) {
//this.v = v;
}
//action
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
CollectionForm collectionForm = (CollectionForm) form;
ActionForward resultat = (mapping.findForward("succes"));
return resultat;
}
//pizza
/*
* Created on 19 nov. 2006
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.epizza.struts.source;
/**
* @author Administrateur
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Pizza {
String nom;
String prix;
/**
*
*/
public Pizza(String nom,String prix) {
this.nom = nom;
this.prix = prix;
}
/**
* @return
*/
public String getNom() {
return nom;
}
/**
* @return
*/
public String getPrix() {
return prix;
}
/**
* @param string
*/
public void setNom(String string) {
nom = string;
}
/**
* @param string
*/
public void setPrix(String string) {
prix = string;
}
}
//jsp
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<html>
<head>
<meta name = "Generator" content = "Easy Struts Xslt generator for Eclipse (http://easystruts.sf.net).">
<title>Struts Form for collectionForm</title>
</head>
<body>
<html:form action="/collection.do">
<logic:iterate id="toto" name="collectionForm" property="v">
<bean:write name="toto"/>
<logic:iterate id="pizza" name="collectionForm" property="v3">
<bean:write name="pizza" property="nom"/>
</logic:iterate>
</logic:iterate>
</html:form>
<body>
</html> |
G recuperer un exemple similaire sur internet ke g modifier.
Ce ke j'obtient c'est l'adresse memoire pour <bean:write name="pizza" property="nom"/>.
De plus j'avais quelques questions:
dans ma page jsp je suis obliger de mettre <html:form action="/collection.do"> autrement mon bean n'est pas reconnue alors que je ne veut pas faire de formulaire.Comment faut t'il faire
de plus j'ai vu sur le forum que beaucoup de personne enregistraient des vectors en session mais je me demandais si dans la page jsp il y avait une methode pour instancier un bean.
J'espere ke j'ai été a peu pres clair dans mes questions
Merci pour votre aide