2011-03-01 78 views
0

我使用的Webflow春天,我的網頁得到了以下錯誤:在spring webflow中定義的javascript變量'Spring'在哪裏?

Spring is not defined 
Spring.addDecoration(new Spring....entId:'proceed', event:'onclick'})); 

我想知道哪裏是在Spring框架中定義JavaScript變量Spring。我正在使用maven,那麼我應該添加哪些依賴項?

回答

1

基地Maven的相關性:

<dependency> 
    <groupId>org.springframework.webflow</groupId> 
    <artifactId>spring-webflow</artifactId> 
    <version>2.2.1.RELEASE</version> 
</dependency> 

這將包括此傳遞依賴:

<dependency> 
    <groupId>org.springframework.webflow</groupId> 
    <artifactId>spring-js</artifactId> 
    <version>2.2.1.RELEASE</version> 
</dependency> 

其中包含的JavaScript資源:

資源:

META-INF/web-resources/spring/Spring.js

,如果你配置Spring MVC作爲指定here,你可以成爲:

<mvc:annotation-driven/> 
<mvc:resources mapping = "/resources/**" 
       location = "/, classpath:/META-INF/web-resources/" /> 

Note that the full resource URL depends on how your DispatcherServlet is mapped. In the mvc-booking sample we've chosen to map it with the default servlet mapping '/':

<servlet> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

That means the full URL to load Spring.js is /myapp/resources/spring/Spring.js. If your DispatcherServlet was instead mapped to /main/* then the full URL would be /myapp/main/resources/spring/Spring.js .

+0

謝謝您的回覆,但如何導入該js文件?我記得我之前沒有明確地導入它。我沒有錯誤。但我改變了一些,然後它不起作用。 – Tom 2011-03-02 02:43:50

+0

@tom看到這部分的參考:http://static.springsource.org/spring-webflow/docs/2.3.x/reference/html/ch12s02.html – 2011-03-02 07:45:01

+0

我使用的是spring3.0.4,我添加了以下兩個行: \t ,但不工作。 – Tom 2011-03-02 09:32:42

0

這個問題解決了。首先,必須像Sean說的那樣添加配置。然後導入以下js。

<script type="text/javascript" src="<c:url value="/resources/dojo/dojo.js" />"></script> 
<script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"></script> 
<script type="text/javascript" src="<c:url value="/resources/spring/Spring-Dojo.js" />"></script> 

餘did't用磚在我的Webflow,Webflow的使用瓷磚的例子並導入三個js文件中standard.jsp,那我爲什麼要導入的JS在每個JSP文件中明確的文件。

1

我在Spring Roo中遇到了這個問題,結果發現問題與load-scripts.tagx文件中對dojo和spring腳本的引用有關。語法應該如下:

<script src="${dojo_url}" type="text/javascript"><!-- required for FF3 and Opera --></script> 
    <script src="${spring_url}" type="text/javascript"><!-- /required for FF3 and Opera --></script> 
    <script src="${spring_dojo_url}" type="text/javascript"><!-- required for FF3 and Opera --></script> 

如果重新格式化把線上方的意見,那麼spring.js永遠不會包含在運行時,因此這就是爲什麼你看到「Spring.addDecoration未定義」。

在這一點上,我不知道爲什麼這個標籤太挑剔。