IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

Problème de Checkbox


Sujet :

Struts 1 Java

  1. #1
    F2S
    F2S est déconnecté
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Points : 97
    Points
    97
    Par défaut Problème de Checkbox
    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

    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()"/>
    Form :

    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;
    	}
    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
        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);
        }

  2. #2
    Membre actif Avatar de Sebou77
    Inscrit en
    Mars 2006
    Messages
    212
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations forums :
    Inscription : Mars 2006
    Messages : 212
    Points : 223
    Points
    223
    Par défaut
    Utilises les balises CODE, c'est super pour lire là

  3. #3
    F2S
    F2S est déconnecté
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Points : 97
    Points
    97
    Par défaut Répondre à la discussion
    balises CODE ????

    peux tu m'expliquer ? je ne vois pas

  4. #4
    Membre régulier
    Inscrit en
    Août 2004
    Messages
    171
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 171
    Points : 97
    Points
    97
    Par défaut
    Tout d'abors, effectivement la balise code c'est chouette.

    Les balises, c'est lorsque tu tape ton message les petit icones au dessus de la zone de texte. Y en a une pour mettre en gras, souligé, etc. Et une pour
    mettre un forme une zone de code.

    Pour ton probleme, il faut savoir que struts (cela vien du html je crois) gère de facon spéciale les checkbox, pour info reporte toi à la faq: http://java.developpez.com/faq/strut...ox#simplecheck

    Mais tout simplement, quel est la porté (le scope) de ton formulaire struts ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <action path="/test/test" 
    parameter="method" 
    type="test.struts.TestEditAction" 
    name="testForm" 
    validate="false" 
    scope="session"
    />
    Car si elle n'est pas session, c'est normal que tes checkbox ne restent pas cochés

  5. #5
    F2S
    F2S est déconnecté
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Points : 97
    Points
    97
    Par défaut
    je n'ai pas précisé de scope, mais si tu m'en parle c que je dois certainement le faire...

  6. #6
    F2S
    F2S est déconnecté
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Points : 97
    Points
    97
    Par défaut
    le scope est bien égale à session, mais ça ne fonctionne toujours pas...

    la case ne reste pas coché

Discussions similaires

  1. [SQL] Problème résultat checkbox dans requête SQL
    Par Skeud007 dans le forum PHP & Base de données
    Réponses: 20
    Dernier message: 02/07/2006, 15h02
  2. problème contrôle checkbox cliqué ou non
    Par mussara dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 03/04/2006, 16h16
  3. [ASP3] Problème de checkbox
    Par beegees dans le forum ASP
    Réponses: 2
    Dernier message: 23/03/2006, 16h42
  4. [xsl] Probléme De checkbox
    Par dimkha dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 27/01/2006, 12h09
  5. Problème sur CHECKBOX
    Par dede92 dans le forum Windows
    Réponses: 6
    Dernier message: 22/02/2005, 10h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo