2013-12-22 111 views
2

在我的web應用程序的每一頁上,我都有一個共同的標題。彈簧整合Javascript

的header.jsp:

<link rel="stylesheet" type="text/css" href="stylesheets/320x480/portrait/header.css" /> 
<div data-theme="b" data-role="header"> 
    <div class="ui-grid-b"> 
      <div class="ui-block-a"> 
       <a id="backButton" data-role="button" data-icon="arrow-l" data-ajax="false"> 
        <spring:message code="backButton"/> 
       </a> 
      </div> 
      <div class="ui-block-b"> 
       <h3>GeoAccessibility</h3> 
      </div> 
      <div class="ui-block-c"> 
       <div data-role="navbar"> 
        <ul> 
         <li id="french"> 
          <a id="fr" href="?language=fr" data-role="button" data-transition="fade" class="ui-btn-active">fr</a> 
         </li> 
         <li id="english"> 
          <a id="en" href="?language=en" data-role="button" data-transition="fade">eng</a> 
         </li> 
        </ul> 
       </div> 

      </div> 
    </div> 
</div> 

在address.jsp:

<script> 
    $('#fr').click(function(){ 
     alert("hello"); 
     //treatment to follow 
    }); 

    $(document).ready(function(){ 
     alert("here"); 
     $('#backButton').attr("href","/fdfds"); 
    }); 
</script> 
<body> 
<div data-role="page" data-ajax="false" id="page1"> 
    <jsp:include page="header.jsp"></jsp:include> 
<div data-role="content"> 
    <forms:form method="post" modelAttribute="address" action="/address"> 
     <spring:message code="streetName" var="streetName" /> 
     <forms:input path="streetName" id="streetName" placeholder="${streetName}" /> 

     <spring:message code="streetNumber" var="streetNumber" /> 
     <forms:input path="streetNumber" id="streetNumber" placeholder="${streetNumber}" /> 
     <!-- Rest of the form --> 

     <button id="submitButton" type="submit" data-mini="true" data-inline="true" data-theme="b" data-ajax="false"><spring:message code="adressValidateBtn" /></button> 

    </forms:form> 
    </div> 
</div> 

爲獲得在address.jsp的或郵寄形式地址控制器:

@Controller 
public class AddressController { 

    @RequestMapping(value="/address",method=RequestMethod.GET) 

    public ModelAndView init(
     @RequestParam(value="language",required=false,defaultValue="fr") String language){ 
      Locale locale = new Locale(language); 
      String[] isoCountries = locale.getISOCountries(); 

      Map<String,String> treeMap = new TreeMap<String,String>(); 
      for(String isoCountry : isoCountries){ 
       Locale countryLoc = new Locale(language, isoCountry); 
       String name = countryLoc.getDisplayCountry(locale); 

       if(!"".equals(name)){ 
        treeMap.put(name,name); 
       } 
      } 

      Map<String,String> tree = new TreeMap<String,String>(treeMap); 

      ModelAndView modelAndView = new ModelAndView("address"); 
      modelAndView.addObject("address",new Address()); 
      modelAndView.addObject("countriesList", tree); 
      modelAndView.addObject("previousPage","/index"); 

      return modelAndView; 
     } 

     @RequestMapping(value="/address",method=RequestMethod.POST) 
     public ModelAndView validate(@RequestParam(value="language",required=false,defaultValue="fr") String language,@ModelAttribute("address") Address address, BindingResult result){ 
       boolean ok = true; 

       //check-up data 

       return new ModelAndView("address"); 
     } 

}

As你在'AddressController'類的'init'方法中看到,我已經添加了一個對象'previousPage',它具有上一頁的'url'值。我想在我的address.jsp中檢索'previousPage'屬性來更改我'後退'按鈕(位於header.jsp中)的'href'屬性。怎麼做 ?

謝謝

回答

0

像所有其他屬性:

${previousPage} 

我看不出有任何理由使用JavaScript來初始化鏈接的href。你可以直接使用它初始化它

<a href="${previousPage}" ...>