Bonjour à la communauté !
Je rame un peu.
Je voudrais que dans ma liste déroulante "clientDropdown" l'option correspondant à la valeur id contenu dans mon bean ClientForm et correspondant à la dernière saisie soit marqué "selected".
Ma JSP :
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
| <!-- Liste des clients -->
<html:form styleId="filtreClient" onsubmit="return envoyerListePr()" action="/listeClient?method=creer">
<div class="contenu col2">
<div class="col last" style="width: 40%">
<div class="ligne" style="margin-bottom: 10px;"><label
for="client">Client </label>
<html:select styleId="clientDropdown" styleClass="listeDeroulante" name="ClientForm" property="id" >
<html:option key="dropdownclientDefault" value=""></html:option>
<html:optionsCollection property="listeClient" value="id" label="label" />
</html:select>
</div>
</div>
<div class="col last" style="width: 50%">
<div class="ligne">
<table id=listePrAajouter cellspacing="0" cellpadding="0"
style="text-align :center">
</table>
</div>
<html:hidden styleId="listeCi" name="ClientForm" property="listeCi"></html:hidden>
<html:hidden styleId="listeCh" name="ClientForm" property="listeCh"></html:hidden>
</div>
</html:form> |
Ma liste de choix est contenue dans listeClient qui contient les proprietés id et label
Mon bean :
1 2 3 4 5 6 7 8 9 10
| <!-- Page Client -->
<form-bean name="ClientForm" type="com.form.ClientDynaForm">
<form-property name="listeClient" type="java.util.ArrayList" />
<form-property name="id" type="java.lang.Integer" />
<form-property name="label" type="java.lang.String" />
<form-property name="listeCi" type="java.lang.String" />
<form-property name="listeCh" type="java.lang.String" />
</form-bean> |
L'action correspondante :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<!-- Creation et suppression pr pour un client modification en cours -->
<action path="/listeClient"
type="com.action.ClientFormAction"
name="ClientForm"
scope="session"
validate="false"
parameter="method" >
<forward name="success"
path="createModifyListeClientJSP" redirect="true" />
<forward name="error"
path="createModifyListeClientJSP" redirect="true" />
</action> |
Ma liste de clients est crée dans l'action précédent l'affichage :
1 2 3 4 5 6
| private void alimentationDropDownListeClient(DynaActionForm userform) {
List<clientDTO> liste = new ArrayList<clientDTO>(referentiel
.getClients().values());
userform.set("listeClient", liste);
} |
Et enfin :
ClientDTO :
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
| public class clientDTO implements Serializable, java.lang.Comparable {
private static final long serialVersionUID = 1L;
/**
* br_client_id
*/
private int id = 0;
/**
* br_client_label
*/
private String label="";
/**
* cod_ci et cod_ch
*/
private PRDTO pr;
public clientDTO() {
// TODO Auto-generated constructor stub
} |
Si je recupère cette valeur par :
'<bean:write name="ClientForm" property="id" />'
Cela fonctionne très bien.
Mais si je tente de l'affecter à l'attribut value du select cela ne fonctionne plus. Ce qui semble normal aux dires des forums consultés : on ne peut pas mettre un <bean:write> dans un <html:select>
<html:select styleId="clientDropdown" styleClass="listeDeroulante" name="ClientForm" property="id" value='<bean:write name="ClientForm" property="id" />' >
J'ai lu la FAQ mais ne suis pas sur d'avoir compris ce qui se réfère à la "préselection" d'un élément de ma liste. Bref comment puis-je faire !
Merci par avance de vos réponses.
Partager