javascript 变量“Spring”在哪里?在 spring webflow 中定义?

发布于 2024-10-19 20:05:29 字数 252 浏览 1 评论 0原文

我正在使用 spring webflow,我的页面出现以下错误:

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

我想知道在 spring 框架中定义的 javascript 变量 Spring 在哪里。我使用的是maven,那么我应该添加什么依赖项呢?

I am using spring webflow, my page got the following error:

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

I am wondering where is javascript variable Spring defined in spring framework. I am using maven, so what dependency should I add in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

第几種人 2024-10-26 20:05:29

基本 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< /code>

如果您按照指定配置 Spring MVC,则可以提供服务 此处

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

请注意完整的资源 URL
取决于您的 DispatcherServlet
已映射。在 mvc-booking 示例中
我们选择将其映射为
默认 servlet 映射 '/':

<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>

这意味着要加载的完整 URL
Spring.js 是
/myapp/resources/spring/Spring.js
。如果
你的 DispatcherServlet
映射到 /main/* 然后是完整的 URL
会是
/myapp/main/resources/spring/Spring.js

Base Maven Dependency:

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

This will include this transitive dependency:

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

Which contains the JavaScript resources:

Resource:

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

Which you can serve if you configure Spring MVC as specified 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.

腹黑女流氓 2024-10-26 20:05:29

我在 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 is undefined”的原因。

在这一点上,我不知道为什么 tagx 对此如此挑剔。

I was having this issue in Spring Roo and it turned out the problem was associated with the references to the dojo and spring scripts in the load-scripts.tagx file. The syntax should be as follows:

  <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>

If you reformat to put the comments above the lines, then the spring.js is never included at runtime and so that's why you see 'Spring.addDecoration is undefined'.

At this point, I'm not sure why the tagx is so picky about this.

吃不饱 2024-10-26 20:05:29

这个问题解决了。首先,必须按照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>

我没有在我的 webflow 中使用tiles,webflow 的示例使用tiles 并导入standard.jsp 中的三个js 文件,这就是为什么我应该在每个jsp 文件中显式导入js 文件。

This issue resolved. First of all, must add configuration as Sean said.Then import the following 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>

I did't use tiles in my webflow, the example of webflow using tiles and import that three js files in standard.jsp, that why I should import js files explicitly in every jsp file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文