Créer un Select à partir d'une Map
Bonjour,
Ca peut sembler bête comme demande mais impossible de mettre la main sur la démarche précise à suivre pour faire fonctionner la balise <s:select>. En réunissant plusieurs sources j'arrive à un code qui me semble pas trop mal mais toujours la même erreur.
Code:
tag 'select', field 'list', name 'plop': The requested list key 'myMapA' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
Struts.xml
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
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.custom.i18n.resources" value="package"/>
<package name="default" extends="struts-default">
<!--<default-action-ref name="index"/>-->
<!-- Navigation rules -->
<action name="gotoPage2" class="com.bea.provisioning.test.TestStruts" method="getString">
<result name="success" type="redirect">page2.jsp</result>
<result name="error"></result>
</action>
<!--<action name="creerPorteur" class="com.bea.provisioning.action.ActionPorteur" method="createPorteur">
<result name="success" type="redirect">page2.jsp</result>
</action>-->
<action name="essai" class="com.bea.provisioning.action.ActionPorteur">
<result>AttributionBeaPorteur.jsp</result>
</action>
<action name="essaiSuite" class="com.bea.provisioning.action.ActionAttribution">
<result>page2.jsp</result>
</action>
</package>
</struts> |
ActionPorteur.java
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
| package com.bea.provisioning.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.bea.provisioning.entites.Porteur;
import com.bea.provisioning.service.ServicePorteur;
import com.opensymphony.xwork2.ActionSupport;
public class ActionPorteur extends ActionSupport{
private Porteur porteur;
private Map<Integer, String> myMapA;
private List<String> list = new ArrayList<String>();
/**
*
*/
private static final long serialVersionUID = 1L;
public ActionPorteur(){
list.add("Plop");
}
public Porteur getPorteur() {
return porteur;
}
public void setPorteur(Porteur porteur) {
this.porteur = porteur;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public Map<Integer, String> getMyMapA() {
return myMapA;
}
public void setMyMapA(Map<Integer, String> myMapA) {
this.myMapA = myMapA;
}
/* (non-Javadoc)
* @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
*/
public void setServletRequest(HttpServletRequest arg0) {
// TODO Auto-generated method stub
}
public String createPorteur(){
new ServicePorteur().createPorteur(porteur);
return SUCCESS;
}
public String getFreePorteurs(){
myMapA = new ServicePorteur().getFreePorteurs();
return SUCCESS;
}
public String getFreePorteursList(){
list = new ServicePorteur().getFreePorteursList();
return SUCCESS;
}
@Override
public String execute() throws Exception {
myMapA = new HashMap<Integer, String>();
myMapA.put(0,"plop");
myMapA.put(1, "plop2");
return super.execute();
}
} |
AttributionBeaPorteur.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <%@taglib uri="/struts-tags" prefix="s"%><%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:form action="essaiSuite" method="post" theme="simple">
<p>
<s:textfield name="porteur.nom" value="nom" size="20"/>
<s:textfield name="porteur.prenom" value="prenom" size="20"/>
<%--<s:select name="mapId" list="map" listKey="id" listValue="name"/>--%>
<s:select name="plop" list="myMapA"/>
<s:submit value="Créer" align="center"/>
</p>
</s:form>
</body>
</html> |
J'aimerai juste récupérer une Map sur ActionPorteur et en faire un <s:select>.
Je vous remercie de votre aide parce que ça fait bien trois jours que je me bats avec le même message d'erreur ^^.
5 pièce(s) jointe(s)
tag 'checkboxlist', field 'list', name 'mode': The requested list key 'listMode' could not be resolved as a co
Bonjour tt le monde J ai essayé d afficher la page Demander.jsp mais il m affiche tjs ce probleme
Ci joint Ma classe d 'action ,struts.xml.la Page JSP
j ai besoin de votre aide Mercii C urgent car je passe un stage