2013-04-04 41 views
1

我試圖在某些JavaScript中訪問Spring Source Security用戶變量$ {username},並且它不斷返回爲空字符串。在上一頁中,我只顯示$ {username}的用戶名。從我可以告訴,我需要做的JavaScript得到這個是:如何在Javascript中使用Spring Security用戶名

<c:out value="${username}"/> 

但在下面的代碼,生成的HTML總是有一個空字符串。我錯過了什麼?

<%@ page session="false"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>The Admin Page</title> 
<style type="text/css"> 

    .wideCols .field-radio { width: 5%; } 
    .wideCols .field-username { width: 15%; } 
    .wideCols .field-firstName { width: 15%; } 
    .wideCols .field-lastName { width: 20%; } 
    .wideCols .field-email { width: 40%; } 
    .wideCols .field-enabled { width: 5%; } 
</style> 
</head> 
<body> 
    <h1>Users</h1> 
    <spring:url value="/admin/addUser" var="accountUrl" /> 

    <a href="${accountUrl}">Add User</a> 
    <div id="result1"></div> 

    <div id="grid" class="wideCols"></div> 
    <!-- <button type="button" id="saveNode"></button> --> 


    <script type="text/javascript"> 
     require([ "dojo/store/JsonRest", 
        "dojo/_base/declare", 
        "dgrid/OnDemandGrid", 
        "dgrid/Selection", 
        "dgrid/editor", 
        "dgrid/selector", 
        "dojo/domReady!" 
       ], function(JsonRest, declare, OnDemandGrid, Selection, editor, selector) { 

      var userAccountStore = new JsonRest({ 
       idProperty : "userAccountId", 
       target : "<c:url value="/userMgr/" />" 
      }); 

      window.grid = new (declare([OnDemandGrid, Selection]))({     
       store : userAccountStore,   
       columns: [ selector({ label: 'radio'}, "radio"), 
          { label: "Username", field: "username"}, 
          { label: "First Name", field: "firstName"}, 
          { label: "Last Name", field: "lastName"}, 
          { label: "Email", field: "email"}, 
          editor({ label: "Enabled", field: "enabled", autoSave: "true", canEdit: function(object){ 
           return object.username != "<c:out value="${username}"/>"; 
          }, }, "checkbox")], 
      }, "grid"); 

     }); 

    </script> 
</body> 
</html> 

回答