Bonjour à tous
j'ai des petits soucis avec les checkbox et malgrés tous ce que j'ai trouvé dessu je ne suis pas arrivé à solutionner mon problème.
je m'explique :
J'ai fais une IHM de saisie qui propose deux mode de recherche, pour selectionner un mode de recherche, il faut checker une checkbox, lorsqu'on clic dessu, la page se recharge et afficher la liste qui correspond au mode de recherche, mon soucis est que qd la page se réaffiche je n'arrive pas à conserver la case cocher, elle réapparait en décocher...
je voudrais qu'elle reste cochée...
Deplus je voudrais aussi pouvoir l'initialiser.
Question : est ce que le fait que j'utilise la même proprièté pour les deux checkbox pose un souci, chaque box renvoie une valeur différente...
voilà mon code :
JSP
Form :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 <layout:checkbox styleClass="champs" property="checkbox" value="cashier" key="label.variationsCriteria.per.cashier" onclick="rechargePage()"/> <layout:checkbox styleClass="champs" property="checkbox" value="rubric" key="label.variationsCriteria.per.rubric" onclick="rechargePage()"/>
action :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 public class VariationsCriteriaForm extends AbstractForm { /** shop id */ private Integer _shopId; /** threshold1 */ private Integer _threshold1; /** threshold2 */ private Integer _threshold2; /** cashier */ private String _cashierNo; /** */ private String[] checkbox; static int i = 0; /** cashier */ private String _codeRubric; /** date 1 */ private String _date1; /** date 2 */ private String _date2; /** * Constructor */ public VariationsCriteriaForm() { super(); } /** * set the property value * * @param string new value */ public void setCashierNo(String string) { _cashierNo = string; } /** * return the property value * * @return value */ public String getCashierNo() { return _cashierNo; } /** * return the property value * * @return value */ public String getCodeRubric() { return _codeRubric; } /** * set the property value * * @param string new value */ public void setCodeRubric(String rubric) { this._codeRubric = rubric; } /** * set the property value * * @param string new value */ public void setDate1(String string) { _date1 = string; } /** * return the property value * * @return value */ public String getDate1() { return _date1; } /** * set the property value * * @param string new value */ public void setDate2(String string) { _date2 = string; } /** * return the property value * * @return value */ public String getDate2() { return _date2; } /** * set the property value * * @param val new value */ public void setShopId(Integer val) { _shopId = val; } /** * return the property value * * @return value */ public Integer getShopId() { return _shopId; } /** * set the property value * * @param integer new value */ public void setThreshold1(Integer integer) { _threshold1 = integer; } /** * return the property value * * @return value */ public Integer getThreshold1() { return _threshold1; } /** * set the property value * * @param integer new value */ public void setThreshold2(Integer integer) { _threshold2 = integer; } /** * return the property value * * @return value */ public Integer getThreshold2() { return _threshold2; } /** * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, * javax.servlet.http.HttpServletRequest) */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = super.validate(mapping, request); if (errors.isEmpty()) { TreasuryValidator.validatePeriod(getDate1(), getDate2(), errors, GeneralConstants.GLOBAL_ERROR_KEY); } return errors; } /** * @return the checkboxCashier */ public String[] getCheckbox() { return checkbox; } /** * @param checkboxCashier the checkboxCashier to set */ public void setCheckbox(String[] checkbox) { this.checkbox = checkbox; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // check user permissions String userRight = checkPermission(CASHIER_VARIATIONS_RESOURCE, request); if (userRight.equals(NO_RIGHT)) { return mapping.findForward(ACCESS_DENIED_FWD); } VariationsCriteriaForm criteriaForm = (VariationsCriteriaForm) form; // load available shops request.setAttribute(SHOPS_ATTR, getShopsList(request, new Boolean(true))); // load cashiers ShopService service = (ShopService) getBusinessDelegate(ShopService.class); Shop shop = getCurrentShop(request); List cashiers = service.getCashiersForShop(shop.getShopId().intValue()); List rubrics = service.getRubricsForShop(shop.getShopId().intValue()); request.setAttribute(RUBRICS_ATTR, rubrics); request.setAttribute(CASHIER_LIST_ATTR, cashiers); String checkbox = null; String[] tab = criteriaForm.getCheckbox(); if(criteriaForm.getCheckbox() != null){ checkbox = tab[0]; //gestion de l'affichage des listes criteriaForm.setCodeRubric(ALL_LABEL); criteriaForm.setCashierNo(ALL_LABEL); request.setAttribute("box", checkbox);//gestion de l'affichage des listes } // prepare form with initial values if (criteriaForm.getCashierNo() == null) { SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Calendar cal = Calendar.getInstance(); criteriaForm.setDate2(format.format(cal.getTime())); cal.add(Calendar.DAY_OF_YEAR, -30); criteriaForm.setDate1(format.format(cal.getTime())); Integer thresold = new Integer(30); criteriaForm.setThreshold1(thresold); criteriaForm.setThreshold2(thresold); criteriaForm.setCheckbox(new String[]{"cashier"});//initialiser la box? checkbox = "cashier"; // select default value "tous" criteriaForm.setCashierNo(ALL_LABEL); criteriaForm.setCodeRubric(ALL_LABEL); request.setAttribute("box", checkbox); } criteriaForm.setShopId(shop.getShopId()); return mapping.findForward(SUCCESS_FWD); }
Partager