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

JSF Java Discussion :

jsf + javascript


Sujet :

JSF Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mai 2009
    Messages : 6
    Par défaut jsf + javascript
    bonjour tout le monde,
    je travaille actuellement sur une application en jsf, un formulaire contanant plusieurs champs ,je dois avoir en fin de compte la somme de ces champs qui sera affiché dans le output
    Le calcul est fait en javascript
    Il me semble qu'il n'ya aucune erreur, mais le resultat n'est pas là je suis egaré
    voiçi le code :
    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
    <script type="text/JavaScript" language="JavaScript">
     
    function checkop(form)
    {
    	var first = document.getElementById("form:first").value;
    	var second document.getElementById("form:second").value;
    	var third = document.getElementById("form:third").value;
    	var fourth = document.getElementById("form:fourth").value;
    	var fiveth = document.getElementById("form:fiveth").value;
    	var sixth = document.getElementById("form:sixth").value;
    	var operator = "+";
     
    	var operand1 = first;
    	var operand2 = second;
    	var operand3 = third;
    	var operand4 = fourth;
    	var operand5 = fiveth;
    	var operand6 = sixth;
     
    	var res = eval(operand1 + operator + operand2 + operator + operand3 + operator + operand4 + operator + operand5 + operator + operand6);
    	var opres = document.getElementById("form:opres");
    	opres.value = res;
     
    }
    </script>
    Le code jsf :
    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
     
    <h:form  id="op" name="op">
     
                    <a4j:outputPanel id="table0">
                     <table border="1" class="dr-table rich-table" style=" width : 840px;">
     
                     <tbody>
                        <tr>
                           <td> <rich:inputNumberSpinner name="first" id="first" value="0" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                            <td> <rich:inputNumberSpinner value="0" name="second" id="second" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                             <td> <rich:inputNumberSpinner value="0" name="third" id="third"  minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                           <td> <rich:inputNumberSpinner value="0" name="fourth" id="fourth"  minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                            <td> <rich:inputNumberSpinner value="0" name="fiveth" id="fiveth" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                          <td> <rich:inputNumberSpinner value="0" name="sixth" id="sixth" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                            <td colspan="4">  <h:outputText value=" Score "/>
                              </td>
                              <td> <h:outputText id="opres" value="" /> </td>
     
                        </tr>
                         <tr>
     
                              <td> <h:commandButton name="go" value="Calculer" onclick="checkop(op)"/>
                                  </td>
                        </tr>
                </tbody>
            </table>
            </a4j:outputPanel>
               </h:form>

  2. #2
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Par défaut
    as tu essayé de faire des alert pour tester chaque valeur et également de faire un alert de ton calcul

  3. #3
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mai 2009
    Messages : 6
    Par défaut
    tout d'abord, merci pour avoir lu mon pb
    en fait,g pas fait des test sur les valeurs introduites mais...
    au debut j'ai realisé cette application just en HTML et javascript, et ça marché trs bien
    mais quand j'ai tranformé les balises que j'ai en jsf , ça n'a pas marché
    je sais pas trop, est ce qu il y a une incompatibilité entre js et jsf ou quelque chose de ce genre

  4. #4
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mai 2009
    Messages : 6
    Par défaut
    j'ai fait ce que vous m'avez dit,j'ai ajouté
    alert('test');
    dans ma fonction javascript pour tester, mais il ya toujours rien

  5. #5
    Membre confirmé
    Étudiant
    Inscrit en
    Janvier 2007
    Messages
    73
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2007
    Messages : 73
    Par défaut
    Citation Envoyé par lowlyman Voir le message
    bonjour tout le monde,
    je travaille actuellement sur une application en jsf, un formulaire contanant plusieurs champs ,je dois avoir en fin de compte la somme de ces champs qui sera affiché dans le output
    Le calcul est fait en javascript
    Il me semble qu'il n'ya aucune erreur, mais le resultat n'est pas là je suis egaré
    voiçi le code :
    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
    <script type="text/JavaScript" language="JavaScript">
     
    function checkop(form)
    {
    	var first = document.getElementById("form:first").value;
    	var second document.getElementById("form:second").value;
    	var third = document.getElementById("form:third").value;
    	var fourth = document.getElementById("form:fourth").value;
    	var fiveth = document.getElementById("form:fiveth").value;
    	var sixth = document.getElementById("form:sixth").value;
    	var operator = "+";
     
    	var operand1 = first;
    	var operand2 = second;
    	var operand3 = third;
    	var operand4 = fourth;
    	var operand5 = fiveth;
    	var operand6 = sixth;
     
    	var res = eval(operand1 + operator + operand2 + operator + operand3 + operator + operand4 + operator + operand5 + operator + operand6);
    	var opres = document.getElementById("form:opres");
    	opres.value = res;
     
    }
    </script>
    Le code jsf :
    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
     
    <h:form  id="op" name="op">
     
                    <a4j:outputPanel id="table0">
                     <table border="1" class="dr-table rich-table" style=" width : 840px;">
     
                     <tbody>
                        <tr>
                           <td> <rich:inputNumberSpinner name="first" id="first" value="0" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                            <td> <rich:inputNumberSpinner value="0" name="second" id="second" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                             <td> <rich:inputNumberSpinner value="0" name="third" id="third"  minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                           <td> <rich:inputNumberSpinner value="0" name="fourth" id="fourth"  minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                            <td> <rich:inputNumberSpinner value="0" name="fiveth" id="fiveth" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                          <td> <rich:inputNumberSpinner value="0" name="sixth" id="sixth" minValue="0" maxValue="2"/></td>
                        </tr>
                        <tr>
                            <td colspan="4">  <h:outputText value=" Score "/>
                              </td>
                              <td> <h:outputText id="opres" value="" /> </td>
     
                        </tr>
                         <tr>
     
                              <td> <h:commandButton name="go" value="Calculer" onclick="checkop(op)"/>
                                  </td>
                        </tr>
                </tbody>
            </table>
            </a4j:outputPanel>
               </h:form>

    Salut
    essai ce code ..

    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
    <script type="text/JavaScript" language="JavaScript">
     
    function checkop(form)
    {
    	var first = document.getElementById(form+":first").value;
    	var second document.getElementById(form+":second").value;
    	var third = document.getElementById(form+":third").value;
    	var fourth = document.getElementById(form+":fourth").value;
    	var fiveth = document.getElementById(form+":fiveth").value;
    	var sixth = document.getElementById(form+":sixth").value;
    	var operator = "+";
     
    	var operand1 = first;
    	var operand2 = second;
    	var operand3 = third;
    	var operand4 = fourth;
    	var operand5 = fiveth;
    	var operand6 = sixth;
     
    	var res = eval(operand1 + operator + operand2 + operator + operand3 + operator + operand4 + operator + operand5 + operator + operand6);
    	var opres = document.getElementById(form+":opres");
    	opres.value = res;
     
    }
    </script>
    je crois que tu passe form ...comme un string ...donc le op !!est agnoré

  6. #6
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mai 2009
    Messages : 6
    Par défaut
    non malheurseument ça n'a pas marché..
    j'ai lu klkpart qu il y a une incompatibilité entre jsf et javascript, et il faut passer par ajax.. mais le pb je sais pas comment y arriver car je connais rien en ajax

  7. #7
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Par défaut
    essaye peut être d'ajouter ça lors de ton appel à ta fonction js

    onclick="javascript:checkop(this)"

  8. #8
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mai 2009
    Messages : 6
    Par défaut
    merci pour ton aide alexandre, mais j'ai dejà essayé ceci et rien ne marche
    je veux seulement savoir est ce que c'est faisable en ajax, car g lu klkpart qu'il ya un framwork apelé ajax4jsf et vu que ajax c'est du javascript, donc fort probable qu il y aura un moyen de faire connecter ma fonction js avec jsf
    ou je me trompe??

  9. #9
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Par défaut
    tu peux le faire en java et envoyer la requete en ajax..ça doit être beaucoup plus simple..

Discussions similaires

  1. JSF + javascript
    Par amal_noussair dans le forum JSF
    Réponses: 3
    Dernier message: 02/10/2008, 21h18
  2. jsf javascript accent
    Par thetoto52 dans le forum JSF
    Réponses: 2
    Dernier message: 11/04/2008, 11h30
  3. Réponses: 7
    Dernier message: 04/10/2007, 11h31
  4. JSF, javascript et panelGrid
    Par cecile_bzh dans le forum JSF
    Réponses: 2
    Dernier message: 06/09/2007, 15h38
  5. [JSF][Javascript]Contrôle côté client
    Par JohnBlatt dans le forum JSF
    Réponses: 7
    Dernier message: 15/11/2006, 18h21

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