Changeset 396 for tapas/web


Ignore:
Timestamp:
03/05/12 16:23:47 (12 years ago)
Author:
vmipsl
Message:

serialization javascript --> toJson
récupération json en objet java dans le controller

Location:
tapas/web
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • tapas/web/init.jsp

    r389 r396  
    66<tiles:insert page="/resources/templates/templateEther.jsp" flush="true"> 
    77 
    8     <tiles:put name="insertCss" type="string"></tiles:put> 
     8    <tiles:put name="insertCss" type="string"/> 
    99    <tiles:put name="insertJsOrJsp" type="string"> 
    10         <ether:htmlJsp jspFile="init_script"></ether:htmlJsp> 
     10        <ether:htmlJs jsFile="library/jquery.json-2.3"/> 
     11        <ether:htmlJsp jspFile="init_script"/> 
    1112    </tiles:put> 
    1213 
  • tapas/web/init_script.jsp

    r389 r396  
    2828        }, 
    2929 
    30  
    3130        // REQUESTS ******************************************************** 
    3231        requestCreateXML: function() 
    3332        { 
    34 //            alert(this.input1.val()+' - '+$("#2").val()); 
    35             $.ajax( { 
    36                 url: "project?methodName=createUserRequest&input1="+this.input1.val()+"&input2="+$("#2").val(), 
    37                 success:jQuery.proxy( this.handleCreateXML, this ) 
    38             } ); 
     33            var jsonFormXml = this.serializeFormXMLToJson(); 
     34            if( jsonFormXml ) 
     35                $.ajax( { 
     36                    url: "project?methodName=createUserRequest&jsonFormXML=" + jsonFormXml, 
     37                    success:jQuery.proxy( this.handleCreateXML, this ) 
     38                } ); 
    3939        }, 
    4040 
     
    4242        handleCreateXML: function( result ) 
    4343        { 
    44 //            alert("XML créé"); 
    4544            var bob = jQuery.parseJSON( result ).result; 
    46             alert(bob); 
    47  
     45            alert( bob ); 
    4846        }, 
    4947 
    5048 
    5149        // EVENTS ******************************************************** 
    52  
    5350        onClickSubmit: function() 
    5451        { 
    5552            this.requestCreateXML(); 
     53        }, 
     54 
     55        // OTHERS ******************************************************** 
     56        serializeFormXMLToJson: function() 
     57        { 
     58            var formXML = new Object(); 
     59            formXML.input1 = $( "#1" ).val(); 
     60            formXML.input2 = $( "#2" ).val(); 
     61            return $.toJSON( formXML ); 
    5662        } 
    57  
    5863 
    5964    } ); 
  • tapas/web/resources/templates/templateEther.jsp

    r388 r396  
     1<%@ page import="com.ether.Context" %> 
    12<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
    23<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
     
    115116    <div id="containerCenter" class="containerTapas containerCenter"> 
    116117        <tiles:insert attribute="body"/> 
     118 
     119        <BR/> 
     120        <%=Context.getPageURI( request )%><BR/> 
     121        <%=Context.getRelativePageURI( request )%><BR/> 
     122        <%=Context.getRelativePath( request )%><BR/> 
     123        <%=Context.getWebroot( request )%><BR/> 
     124        <%=request.getQueryString()%><BR/> 
     125        <%=request.getContextPath()%><BR/> 
     126        <%=request.getPathInfo()%><BR/> 
     127        <%=request.getServletPath()%><BR/> 
     128        <%=request.getRequestURL()%><BR/> 
    117129    </div> 
    118130 
     
    129141    var templateTexts = $A( "" ); 
    130142    templateTexts["label.home"] = '<spring:message code="label.home"/>'; 
    131     templateTexts["label.language.fr"] = '<spring:message code="label.language.fr"/>'; 
    132     templateTexts["label.language.en"] = '<spring:message code="label.language.en"/>'; 
     143    templateTexts["label.language.to.fr"] = '<spring:message code="label.language.to.fr"/>'; 
     144    templateTexts["label.language.to.en"] = '<spring:message code="label.language.to.en"/>'; 
    133145    templateTexts["label.mail"] = '<spring:message code="label.mail"/>'; 
    134146    templateTexts["label.map"] = '<spring:message code="label.map"/>'; 
  • tapas/web/resources/templates/templateEther_script.jsp

    r388 r396  
    22 
    33<script type="text/javascript"> 
    4 var InterfaceTemplate = Class.create( { 
     4    var InterfaceTemplate = Class.create( { 
    55 
    6     initialize: function() 
     6        initialize: function() 
     7        { 
     8            /** *********** CONTAINERS *********** **/ 
     9            this.containerTools = $( "#tools" ); 
     10            this.containerLogin = $( "#loginModule" ); 
     11            this.containerMenuData = $( "#menuData" ); 
     12 
     13            /** *********** VARIABLES *********** **/ 
     14            this.isLanguageFr = <%=Context.getLangue(request).equals( "fr" )%>; 
     15            this.webmaster = "<%=Context.getWebmaster(request)%>"; 
     16            <%--this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false;--%> 
     17 
     18            /** ************ CREATE ************ **/ 
     19//        this.createLogin(); 
     20            this.createTools(); 
     21            this.updateLoginOrLogout(); 
     22        }, 
     23 
     24        // CREATES ******************************************************** 
     25        createTools: function() 
     26        { 
     27            var mailButton = new Button( {value:templateTexts["label.mail"], parent:this.containerTools, id:"button_mail", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickMail, this )} ); 
     28 
     29//        var valueLanguage = templateTexts["label.language.fr"]; 
     30//        if( this.isLanguageFr ) 
     31//            valueLanguage = templateTexts["label.language.en"]; 
     32 
     33            <%--var languageButton = new Button( {value: templateTexts["label.language.<%=Context.getLocale( request )%>"], parent:this.containerTools, id:"button_language", className: "red_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} );--%> 
     34            var languageButton = new Button( {value:templateTexts["label.language.to.<%=Context.getLocale( request )%>"], parent:this.containerTools, id:"button_language", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} ); 
     35            var homeButton = new Button( {value:templateTexts["label.home"], parent:this.containerTools, id:"button_home", className: "red_button", classNameText:"red_button_text", onClick:this.onClickHome} ); 
     36        }, 
     37 
     38        createLogin: function() 
     39        { 
     40            this.loginModule = new LoginButton( {parent:this.containerLogin, urlLogin:"project?methodName=login", urlLogout:"project?methodName=logout", isNeededInscription:true, callbackInscription:jQuery.proxy( this.onClickInscription, this ), anotherOnClickLogin:this.updateLoginOrLogout, anotherOnClickLogout:this.updateLoginOrLogout } ); 
     41            this.loginModule.setJSONUser( this.jSONUser ); 
     42            this.loginModule.display(); 
     43            setLoginModule( this.loginModule ); 
     44        }, 
     45 
     46        // REQUESTS ******************************************************** 
     47 
     48        // EVENTS ******************************************************** 
     49        onClickHome: function() 
     50        { 
     51            document.location.href = "index.jsp"; 
     52        }, 
     53 
     54        onClickLanguage: function() 
     55        { 
     56            this.path = "<%=request.getContextPath()%>"; 
     57            this.webmaster = "<%=Context.getWebmaster(request)%>"; 
     58 
     59            alert("<%=request.getQueryString()%>||<%=Context.getRelativePath( request )%>||<%=Context.getRelativePageURI(request)%>"); 
     60 
     61            this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>"; 
     62 
     63            alert( this.relativePageUri + " " +<%=Context.isFrench(request)%> ); 
     64            if( <%=Context.isFrench(request)%> ) 
     65                document.location.href = this.path + this.relativePageUri + "&language=en"; 
     66            else 
     67                document.location.href = this.path + this.relativePageUri + "&language=fr"; 
     68        }, 
     69 
     70        onClickMail: function() 
     71        { 
     72            document.location.href = "mailto:" + this.webmaster + "?subject=[TAPAS]"; 
     73        }, 
     74 
     75        onClickInscription: function() 
     76        { 
     77            var dataProtocol = "resources/jsp/dataProtocol_fr.jsp"; 
     78            if( !this.isLanguageFr ) 
     79                dataProtocol = "resources/jsp/dataProtocol_en.jsp"; 
     80 
     81            var $dialog = $( '<div></div>' ) 
     82                    .load( dataProtocol ) 
     83                    .dialog( { 
     84                                 autoOpen: false, 
     85                                 title: loginTexts["login.inscription"], 
     86                                 height: 800, 
     87                                 width: 750 
     88                             } ); 
     89            $dialog.dialog( 'open' ); 
     90 
     91            // TODO : see with $dialog.ready() to manage buttons 
     92        }, 
     93 
     94        updateLoginOrLogout: function() 
     95        { 
     96            <%--if( "<%=UserRole.ADMINISTRATOR%>" == getJSONUserRole() )--%> 
     97            <%--$( "#button_bo" ).show();--%> 
     98            <%--else--%> 
     99            <%--$( "#button_bo" ).hide();--%> 
     100        } 
     101 
     102    } ); 
     103 
     104    /** ******************************* **/ 
     105    /** *********** ACCOUNT *********** **/ 
     106    /** ******************************* **/ 
     107    function onClickAcceptDataProtocol() 
    7108    { 
    8         /** *********** CONTAINERS *********** **/ 
    9         this.containerTools = $( "#tools" ); 
    10         this.containerLogin = $( "#loginModule" ); 
    11         this.containerMenuData = $( "#menuData" ); 
     109        if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() || '' == $( "#password" ).val() ) 
     110        { 
     111            showErrorAccount( null, templateTexts["login.dataProtocolFields"] ); 
     112            return; 
     113        } 
    12114 
    13         /** *********** VARIABLES *********** **/ 
    14         this.isLanguageFr = <%=Context.getLangue(request).equals( "fr" )%>; 
    15         this.path = "<%=request.getContextPath()%>"; 
    16         setPath( this.path ); 
    17         this.webmaster = "<%=Context.getWebmaster(request)%>"; 
    18         this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>"; 
    19         <%--this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false;--%> 
    20  
    21         /** ************ CREATE ************ **/ 
    22 //        this.createLogin(); 
    23         this.createTools(); 
    24         this.createMenuData(); 
    25         this.updateLoginOrLogout(); 
    26     }, 
    27  
    28     // CREATES ******************************************************** 
    29     createTools: function() 
    30     { 
    31         var mailButton = new Button( {value:templateTexts["label.mail"], parent:this.containerTools, id:"button_mail", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickMail, this )} ); 
    32  
    33         var valueLanguage = templateTexts["label.language.fr"]; 
    34         if( this.isLanguageFr ) 
    35             valueLanguage = templateTexts["label.language.en"]; 
    36  
    37         var languageButton = new Button( {value:valueLanguage, parent:this.containerTools, id:"button_language", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} ); 
    38         var homeButton = new Button( {value:templateTexts["label.home"], parent:this.containerTools, id:"button_home", className: "red_button", classNameText:"red_button_text", onClick:this.onClickHome} ); 
    39     }, 
    40  
    41     createLogin: function() 
    42     { 
    43         this.loginModule = new LoginButton( {parent:this.containerLogin, urlLogin:"project?methodName=login", urlLogout:"project?methodName=logout", isNeededInscription:true, callbackInscription:jQuery.proxy( this.onClickInscription, this ), anotherOnClickLogin:this.updateLoginOrLogout, anotherOnClickLogout:this.updateLoginOrLogout } ); 
    44         this.loginModule.setJSONUser( this.jSONUser ); 
    45         this.loginModule.display(); 
    46         setLoginModule( this.loginModule ); 
    47     }, 
    48  
    49     createMenuData: function() 
    50     { 
    51         this.containerMenuData.empty(); 
    52  
    53         var ulData = $( document.createElement( "ul" ) ); 
    54         this.containerMenuData.append( ulData ); 
    55  
    56         var liExtract = $( document.createElement( "li" ) ); 
    57         liExtract.append( '<a onclick=\'javascript:neededLogin("/DataAccess.do")\'><span>' + templateTexts["data.access.extract.short"] + '</span></a>' ); 
    58         ulData.append( liExtract ); 
    59  
    60         var liDownload = $( document.createElement( "li" ) ); 
    61         liDownload.append( '<a onclick=\'javascript:neededLogin("/PrepareTree.do")\'><span>' + templateTexts["data.upload.short"] + '</span></a>' ); 
    62         ulData.append( liDownload ); 
    63     }, 
    64  
    65     // REQUESTS ******************************************************** 
    66  
    67     // EVENTS ******************************************************** 
    68     onClickHome: function() 
    69     { 
    70         document.location.href = "index.jsp"; 
    71     }, 
    72  
    73     onClickLanguage: function() 
    74     { 
    75         if( this.isLanguageFr ) 
    76             document.location.href = this.path + "/English.do?requestUri=" + this.relativePageUri; 
     115        if( $( "#checkboxUser" ).attr( 'checked' ) ) 
     116            createAccount(); 
    77117        else 
    78             document.location.href = this.path + "/French.do?requestUri=" + this.relativePageUri; 
    79     }, 
    80  
    81     onClickMail: function() 
    82     { 
    83         document.location.href = "mailto:" + this.webmaster + "?subject=[TAPAS]"; 
    84     }, 
    85  
    86     onClickInscription: function() 
    87     { 
    88         var dataProtocol = "resources/jsp/dataProtocol_fr.jsp"; 
    89         if( !this.isLanguageFr ) 
    90             dataProtocol = "resources/jsp/dataProtocol_en.jsp"; 
    91  
    92         var $dialog = $( '<div></div>' ) 
    93                 .load( dataProtocol ) 
    94                 .dialog( { 
    95                              autoOpen: false, 
    96                              title: loginTexts["login.inscription"], 
    97                              height: 800, 
    98                              width: 750 
    99                          } ); 
    100         $dialog.dialog( 'open' ); 
    101  
    102         // TODO : see with $dialog.ready() to manage buttons 
    103     }, 
    104  
    105     updateLoginOrLogout: function() 
    106     { 
    107         <%--if( "<%=UserRole.ADMINISTRATOR%>" == getJSONUserRole() )--%> 
    108             <%--$( "#button_bo" ).show();--%> 
    109         <%--else--%> 
    110             <%--$( "#button_bo" ).hide();--%> 
     118            showErrorAccount( null, templateTexts["login.dataProtocolAccept"] ); 
    111119    } 
    112120 
    113 } ); 
    114  
    115 /** ******************************* **/ 
    116 /** *********** ACCOUNT *********** **/ 
    117 /** ******************************* **/ 
    118 function onClickAcceptDataProtocol() 
    119 { 
    120     if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() || '' == $( "#password" ).val() ) 
     121    function createAccount() 
    121122    { 
    122         showErrorAccount( null, templateTexts["login.dataProtocolFields"] ); 
    123         return; 
     123        var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() + "&pwd=" + $( "#password" ).val(); 
     124        var request = $.ajax( { 
     125            url: "project?methodName=createAccount&" + parametersUrl, 
     126            success:handleCreateAccount, 
     127            error: showErrorAccount 
     128        } ); 
    124129    } 
    125130 
    126     if( $( "#checkboxUser" ).attr( 'checked' ) ) 
    127         createAccount(); 
    128     else 
    129         showErrorAccount( null, templateTexts["login.dataProtocolAccept"] ); 
    130 } 
     131    function handleCreateAccount() 
     132    { 
     133        $( "#infosAccount" ).hide(); 
     134        $( "#infosAccount" ).removeClass( "containerErrors" ); 
     135        $( "#infosAccount" ).addClass( "containerInfos" ); 
     136        $( "#infosAccount" ).html( templateTexts["login.dataProtocol.account"] ); 
     137        $( "#infosAccount" ).show(); 
     138    } 
    131139 
    132 function createAccount() 
    133 { 
    134     var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() + "&pwd=" + $( "#password" ).val(); 
    135     var request = $.ajax( { 
    136         url: "project?methodName=createAccount&" + parametersUrl, 
    137         success:handleCreateAccount, 
    138         error: showErrorAccount 
    139     } ); 
    140 } 
     140    function showErrorAccount( result, text ) 
     141    { 
     142        $( "#infosAccount" ).hide(); 
     143        $( "#infosAccount" ).removeClass( "containerInfos" ); 
     144        $( "#infosAccount" ).addClass( "containerErrors" ); 
     145        if( null != result ) 
     146            $( "#infosAccount" ).html( templateTexts[result.responseText] ); 
     147        else 
     148            $( "#infosAccount" ).html( text ); 
    141149 
    142 function handleCreateAccount() 
    143 { 
    144     $( "#infosAccount" ).hide(); 
    145     $( "#infosAccount" ).removeClass( "containerErrors" ); 
    146     $( "#infosAccount" ).addClass( "containerInfos" ); 
    147     $( "#infosAccount" ).html( templateTexts["login.dataProtocol.account"] ); 
    148     $( "#infosAccount" ).show(); 
    149 } 
    150  
    151 function showErrorAccount( result, text ) 
    152 { 
    153     $( "#infosAccount" ).hide(); 
    154     $( "#infosAccount" ).removeClass( "containerInfos" ); 
    155     $( "#infosAccount" ).addClass( "containerErrors" ); 
    156     if( null != result ) 
    157         $( "#infosAccount" ).html( templateTexts[result.responseText] ); 
    158     else 
    159         $( "#infosAccount" ).html( text ); 
    160  
    161     $( "#infosAccount" ).show(); 
    162 } 
     150        $( "#infosAccount" ).show(); 
     151    } 
    163152</script> 
  • tapas/web/src/com/ether/Controller.java

    r389 r396  
    44import com.ether.annotation.Mandatory; 
    55import com.ether.annotation.ParamName; 
     6import com.ether.annotation.UseJSON; 
    67import net.sf.json.JSONObject; 
    78import org.apache.commons.logging.Log; 
     
    1112 
    1213import java.util.HashMap; 
    13 import java.util.List; 
    1414import java.util.Map; 
    1515 
    1616/** 
    1717 * @author vmipsl 
    18  * @date 17 feb 2011 
     18 * @date 05 march 2012 
    1919 */ 
    2020public class Controller 
     
    2424    /** *********************************************************** **/ 
    2525    /** *********************** VIEWS ***************************** **/ 
    26     /** 
    27      * ********************************************************** * 
    28      */ 
     26    /** *********************************************************** **/ 
    2927    @ControllerMethod(view = VIEW_INIT) 
    3028    public Map<String, Object> home() 
     
    3735    /** *********************************************************** **/ 
    3836    /** *********************** CALLS ***************************** **/ 
    39     /** 
    40      * ********************************************************** * 
    41      */ 
    42  
     37    /** *********************************************************** **/ 
    4338    @ControllerMethod(jsonResult = true) 
    44     public JSONObject createUserRequest( @ParamName("input1") final String input1, @ParamName("input2") final String input2 ) 
     39    public JSONObject createUserRequest( @ParamName("jsonFormXML") @Mandatory @UseJSON final FormXML jsonFormXML ) 
    4540            throws ServiceException 
    4641    { 
    47  
    4842        //appel a createxml 
    4943        _tapasService.createXMLRequest(); 
    5044 
    51  
    5245        final JSONObject result = new JSONObject(); 
    53         result.put( "result","SUCCESS" ); 
     46        result.put( "result", "SUCCESS" ); 
    5447        return result; 
    5548    } 
  • tapas/web/src/messages_en.properties

    r389 r396  
    11inWork=Work in progress.. 
    22language=English 
    3 label.language.fr=French 
    4 label.language.en=English 
     3label.language.to.en=French 
     4label.language.to.fr=English 
    55label.language=Language 
    66 
  • tapas/web/src/messages_fr.properties

    r389 r396  
    11inWork=Page en cours de construction.. 
    22language=Français 
    3 label.language.fr=Français 
    4 label.language.en=Anglais 
     3label.language.to.en=Français 
     4label.language.to.fr=Anglais 
    55label.language=Langue 
    66 
Note: See TracChangeset for help on using the changeset viewer.