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 2 Java Discussion :

Struts 2 + JSON + JQuery


Sujet :

Struts 2 Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Juin 2009
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 35
    Par défaut Struts 2 + JSON + JQuery
    bonjour tout le monde ,je suis débutant dans l'utilisation de json et ça fait une semaine que je me suis confronté avec le problème de grid . la grid m'affiche rien et dans le console je reçois ces messages
    [WARN,ServletUrlRenderer,http-8080-2] No configuration found for the specified action: 'bonreception2' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
    [WARN,ServletUrlRenderer,http-8080-2] No configuration found for the specified action: 'bonreception2' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
    [WARN,ServletUrlRenderer,http-8080-2] No configuration found for the specified action: 'bonreception3' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
    [WARN,ServletUrlRenderer,http-8080-2] No configuration found for the specified action: 'bonreception3' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
    size de commercants 26
    size de commercants 26
    dans Struts.xml j'ai
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <struts>
     
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
    <constant name="struts.convention.result.path" value="/pages"/>
    <constant name="struts.custom.i18n.resources" value="messages" />
    <package name="voucher" extends="struts-default,json-default" namespace="/">
    <action name="recherche_reception1" class="ma.pcard.voucher.action.RechCmdDistListAction">
    <result name="success">/JSP/menu_order/order_distributeur/recherche/achatfinddetail.jsp</result>
    <result name="input">/error.jsp</result>
    </action>
    </package>
    </struts>


    dans la page jsp
    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
    <%@ taglib uri="/struts-tags" prefix="s" %>
    <%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
    <%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
     
    <html>
    <head>
    <sj:head jqueryui="true" jquerytheme="redmond" />
    </head>
    <body>
    <s:url id="remoteurl" action="recherche_reception1"/>
        <sjg:grid
    dataType="json"
            name="grid"
            caption="amine"
          href="%{remoteurl}"
            height="400"
            width="400"
     
            gridModel="gridModel"
     
     
        >///////////////nomCom est un attribut de l'entité Commercant
            <sjg:gridColumn name="nomCom" index="nomCom" title="nom" />
     
        </sjg:grid>
    </body>
    	</html>

    dans l'action java

    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
    public class RechCmdDistListAction extends ActionSupport implements SessionAware{
    	/**
             * 
             */
    	private Map<String, Object> session;
    	private CommercantManager commercantManager;
    	private List<Commercant>gridModel;
    	private List<Commercant>	commercants;
    public String execute() throws Exception
    	  {
    		 this.session=getSession();
    		 ApplicationContext ctx=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
     
    		 commercantManager=(CommercantManager) ctx.getBean("commercantManager");
     
     
    		 commercants = commercantManager.getAllCommercants();
    		 System.out.println("size de commercants "+commercants.size());
    		 Object list =  session.get("mylist");
     
    		    if (list != null)
    		    {
     
    		      commercants = (List<Commercant>) list;
    		    }
    		    else
    		    {
     
    		      commercants = commercantManager.getAllCommercants();
    		    }
     
    		      setGridModel(commercants);
     
     
     
    	    //Your logic to search and select the required data.
    		 session.put("mylist",commercants);
    	    //calculate the total pages for the query
    		 return SUCCESS;
    			// TODO: handle exception
    		}
     
     
    	  public String getJSON() throws Exception
    	  {
    	    return execute();
    	  }
    	public CommercantManager getCommercantManager() {
    		return commercantManager;
    	}
    	public void setCommercantManager(CommercantManager commercantManager) {
    		this.commercantManager = commercantManager;
    	}
    	public List<Commercant> getGridModel() {
    		return gridModel;
    	}
    	public void setGridModel(List<Commercant> gridModel) {
    		this.gridModel = gridModel;
    	}
     
    	public Map<String, Object> getSession() {
    		return session;
    	}
    	public void setSession(Map<String, Object> session) {
    		this.session = session;
    	}
    	public List<Commercant> getCommercants() {
    		return commercants;
    	}
    	public void setCommercants(List<Commercant> commercants) {
    		this.commercants = commercants;
    	}
     
    }
    lorsque j'ajoute type=json au result success
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    <result name="success" type="json">/JSP/menu_order/order_distributeur/recherche/achatfinddetail.jsp</result>
    je reçois cette erreur
    org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131)
    org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99)
    org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
    org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)
    s'il vous plait aidez-moi?

  2. #2
    Membre très actif
    Inscrit en
    Novembre 2004
    Messages
    234
    Détails du profil
    Informations forums :
    Inscription : Novembre 2004
    Messages : 234
    Par défaut
    telecharge le showcase Struts2Jquery

  3. #3
    Invité de passage
    Homme Profil pro
    Inscrit en
    Novembre 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Novembre 2011
    Messages : 1
    Par défaut
    Je me suis inscrit pour répondre à ce problème avec lequel je me suis arraché les cheveux bien longtemps (l'analyse du showcase ne m'ayant pas aiguillé du tout).

    Ton erreur se trouve dans ton fichier Struts.xml. Il faut que tu modifie l'action comme ceci:

    <action name="recherche_reception1" class="ma.pcard.voucher.action.RechCmdDistListAction" method="getJSON">

    <result name="success" type="json">/JSP/menu_order/order_distributeur/recherche/achatfinddetail.jsp</result>
    <result name="input">/error.jsp</result>

    </action>


    Ceci permet de déclarer tes données comme étant au format JSon.
    En espérant que ça puisse t'être encore utile ou bien que ça serve à quelqu'un.

Discussions similaires

  1. Json jquery et highcharts
    Par L4ur3nt dans le forum jQuery
    Réponses: 8
    Dernier message: 29/12/2013, 15h21
  2. [Action Struts 2 / JSON] Erreur 404
    Par dude_dev dans le forum Struts 2
    Réponses: 1
    Dernier message: 13/12/2012, 15h26
  3. [EJB / REST / JSON / JQuery] Problème pour faire un POST
    Par saveriu dans le forum Services Web
    Réponses: 1
    Dernier message: 19/04/2012, 11h08
  4. Webservices - JSON - JQUERY
    Par aurelien.tournier dans le forum Services Web
    Réponses: 3
    Dernier message: 07/11/2010, 11h32

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