MaitrePo | Bonjour,
J'ai donc une appli Struts avec un formulaire mais il semble qu'il ne soit pas peuplé lorsque je clique sur le bouton submit... d'ailleurs, d'après les traces, les setters ne sont pas appelés ! Je commence à désespérer, peut-être que vous verrez une énormité qui m'est passée sous le nez..
La jsp :
Code :
- <html:form action="/private/alerts/manage">
- <logic:present name="contactDisplay">
- <br/><c:out value='${isContactSubscriber}'/>
- <div align="center">
- <html:select property="contact">
- <html:option value="oui">oui</html:option>
- <html:option value="non">non</html:option>
- </html:select>
- </div>
- </logic:present>
- <br/>
- <logic:present name="advertisingDisplay">
- <br/><c:out value='${isAdvertisingSubscriber}'/>
- <div align="center">
- <html:select property="advertising">
- <html:option value="oui">oui</html:option>
- <html:option value="non">non</html:option>
- </html:select>
- </div>
- </logic:present>
- <br/>
- <br/>
- <div align="center">
- <html:select property="startHour" size="1" multiple="false">
- <html:option value="0">00</html:option>
- <html:option value="23">23</html:option>
- </html:select>
- heure et
- <html:select property="stopHour" size="1" multiple="false">
- <html:option value="0">00</html:option>
- <html:option value="23">23</html:option>
- </html:select>
- heure
- </div>
- <br/>
- <html:select property="frequency" size="1" multiple="false">
- <html:option value="DAILY">7j/7</html:option>
- <html:option value="WEEK">du Lun au Ven</html:option>
- <html:option value="WEEKEND">le weekend</html:option>
- </html:select>
- <br/>
- <html:submit>Valider</html:submit>
- </html:form>
|
Dans le struts config j'ai
Code :
- <form-bean name="alertingForm" type="com.mm123.tchatche.mobile.web.struts.alerting.AlertingForm"/>
|
et
Code :
- <action path="/private/alerts/manage" type="com.mm123.tchatche.mobile.web.struts.alerting.AlertingAction"
- name="alertingForm"
- validate="true"
- input="/do/public/alerts/manage">
- [forwards...]
- </action>
|
Mon formulaire :
Code :
- public class AlertingForm extends ActionForm implements Serializable {
- private static final long serialVersionUID = 1L;
- private static Log log = LogFactory.getLog(AlertingForm.class);
- private boolean contactToValidate = false; //vrai si contact est à valider
- private String contact="";
- private boolean advertisingToValidate = false;
- private String advertising="";
- private boolean startHourToValidate = false;
- private String startHour="";
- private boolean stopHourToValidate = false;
- private String stopHour="";
- private boolean momentInDayToValidate = false;
- private String momentInDay="";
-
- private boolean frequencyToValidate = false;
- private String frequency="";
- private boolean phoneNumberToValidate = false;
- private String phoneNumber="";
- /**
- * init du formulaire
- */
- public void reset(ActionMapping mapping, HttpServletRequest request) {
- /* Retrieve from session or from server the last user's preferences */
- UserServicePreferences pref = null;
-
- if (request.getAttribute("contact" ) != null) {
- this.contact = "true";
- log.debug("The contact field is activated." );
- }
-
- if (request.getAttribute("advertising" ) != null) {
- this.advertising = "true";
- log.debug("The advertising field is activated." );
- }
-
- try {
- if(Boolean.parseBoolean(this.contact)) {
- pref = AlertingUserInfoRetriever.getUsersPreferencesByService(request,
- AlertingServiceType.CONTACT_ALERTING);
- //Verification des anciennes preferences avec les nouvelles
- } else if (Boolean.parseBoolean(this.advertising)) {
- pref = AlertingUserInfoRetriever.getUsersPreferencesByService(request,
- AlertingServiceType.ADVERTISING_ALERTING);
- }
-
- } catch (AlertingException e) {
- // Nothing to do, the user's preferences wont be initialized.
- log.error("Unable to initialize form " + e, e);
- }
-
- /**
- * if pref == null maybe is because the user is not subscribed yet.
- */
- if (pref != null) {
- this.startHour = pref.getStartHour();
- this.stopHour = pref.getStopHour();
- this.momentInDay = pref.getMomentInDay();
- this.frequency = pref.getFrequency();
- }
-
- if (request.getAttribute("phoneNumber" ) != null) {
- this.phoneNumber = Boolean.toString((Boolean)request.getAttribute("phoneNumber" ));
- }
- log.debug("reset : contact="+this.contact+" advertising="+this.advertising+" startHour="+this.startHour+ " stopHour="+this.stopHour+" frequency="+this.frequency);
- }
- public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
- log.debug("validate : " +
- "contact="+this.contact+
- "advertising="+this.advertising+
- " startHour="+this.startHour+
- " stopHour="+this.stopHour+
- " frequency="+this.frequency);
- ActionErrors errors=new ActionErrors();
- //si les champs contact et advertising sont présent : un des 2 doit etre choisi
- if(contactToValidate && advertisingToValidate){
- //erreur si les deux sont à non
- if(!Boolean.parseBoolean(contact) && !Boolean.parseBoolean(advertising)){
- ActionMessage newError = new ActionMessage("error.alerts.contactAdvertising.allfalse" );
- errors.add(ActionMessages.GLOBAL_MESSAGE, newError);
- errors=new ActionErrors();
- return errors;
- }
- }
- //si les champs startHour et stopHour sont à valider
- if(startHourToValidate && stopHourToValidate){
- if(startHour.equals("" ) || stopHour.equals("" )){
- ActionMessage newError =
- new ActionMessage("error.alerts.periodicity.badValue" );
- errors.add(ActionMessages.GLOBAL_MESSAGE, newError);
- return errors;
- }
- }
- //si le champs momentInDay est à valider
- if(momentInDayToValidate){
- if(momentInDay==null || momentInDay.equals("" )){
- ActionMessage newError = new ActionMessage("error.alert.form.momentInDay.required" );
- errors.add("global", newError);
- errors=new ActionErrors();
- return errors;
- }
- }
- //si le champs fréquence est à valider
- if(frequencyToValidate){
- if(frequency==null || frequency.equals("" )){
- ActionMessage newError = new ActionMessage("error.alert.form.frequency.required" );
- errors.add("global", newError);
- return errors;
- }
- }
- //si le numéro de téléphone est a valider
- if(phoneNumberToValidate){
- //phone Number
- if(phoneNumber==null || phoneNumber.equals("" )){
- ActionMessage newError = new ActionMessage("error.alert.form.phoneNumber.required" );
- errors.add("global", newError);
- return errors;
- }else if(!phoneNumberGoodFormat(phoneNumber)){
- ActionMessage newError = new ActionMessage("error.alert.form.phoneNumber.notValid" );
- errors.add("global", newError);
- }
- }
- log.debug("contactToValidate : "+contactToValidate+" contact : "+contact+" advertisingToValidate : "+advertisingToValidate+" advertising : "+advertising);
- return null;
- }
- /**
- * vrrai si num de tel valide
- * @param phoneNumber
- * @return
- */
- public boolean phoneNumberGoodFormat(String phoneNumber){
- Pattern pattern = Pattern.compile("^06\\d{8}$" );
- Matcher matcher = pattern.matcher(phoneNumber);
- return matcher.find();
- }
- public boolean isContact() {
- return Boolean.getBoolean(contact);
- }
- public String getContact(){
- return contact;
- }
- public void setContact(String contact) {
- log.error("setContact="+contact);
- if(contact.equalsIgnoreCase("oui" )){
- this.contact="true";
- }else{
- this.contact="false";
- }
- //this.contact = contact;
- }
- public boolean isAdvertising() {
- return Boolean.getBoolean(advertising);
- }
- public String getAdvertising() {
- return advertising;
- }
- public void setAdvertising(String advertising) {
- log.error("setAdvertising="+advertising);
- if(advertising.equalsIgnoreCase("oui" )){
- this.advertising="true";
- }else{
- this.advertising="false";
- }
- this.advertising = advertising;
- }
- public String getFrequency() {
- return frequency;
- }
- public void setFrequency(String freq) {
- this.frequency = freq;
- }
- public String getStartHour() {
- return startHour;
- }
- public void setStartHour(String start) {
- this.startHour = start;
- }
- public String getStopHour() {
- return stopHour;
- }
- public void setStopHour(String stop) {
- this.stopHour = stop;
- }
- public String getPhoneNumber() {
- return phoneNumber;
- }
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
- public String getMomentInDay() {
- return momentInDay;
- }
- public void setMomentInDay(String momentInDay) {
- this.momentInDay = momentInDay;
- }
|
Donc setContact/setAdvertising ne sont pas appelées, les attributs sont vides aussi à l'appel de la méthode validate.
Qu'est ce que se passe-til donc ?! |