之外的所有東西我的Spring4 Thymeleaf2瓷磚和Ajax配置工作除了最後一步之外。我的html頁面不刷新。我知道該方法被調用,結果從我的服務方法返回。我認爲我的錯誤是我對待helloworld拼貼中的「id」的方式。Spring4 Webflow Thymeleaf2瓷磚Ajax:除
我將顯示我的整個配置,因爲在Web上有幾個xml配置示例,並且one of them是錯誤的。
最後一步的幫助將深表謝意。配置的
關鍵部分:
Webflow的配置
<!-- Webflow Config-->
<webflow:flow-registry id="flowRegistry"
\t \t base-path="/WEB-INF/flows/admin" flow-builder-services="flowBuilderServices">
\t \t <webflow:flow-location id="testflow" path="testflow.xml" />
\t \t <webflow:flow-location id="xzcreatetesttype" path="xzcreatetesttype.xml" />
\t </webflow:flow-registry>
\t <webflow:flow-executor id="flowExecutor"
\t \t flow-registry="flowRegistry" />
\t <webflow:flow-builder-services id="flowBuilderServices"
\t \t view-factory-creator="mvcViewFactoryCreator" validator="validator" development="true" />
\t
\t <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
\t \t <property name="flowExecutor" ref="flowExecutor" />
\t \t <property name="saveOutputToFlashScopeOnRedirect" value="true" />
\t </bean>
\t \t
\t <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
\t \t <property name="flowRegistry" ref="flowRegistry" />
\t \t <property name="order" value="-1" />
\t </bean>
查看配置
<!-- views config-->
\t <bean id="templateResolver"
\t \t class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
\t \t <property name="prefix" value="/WEB-INF/html/" />
\t \t <property name="suffix" value=".html" />
\t \t <property name="templateMode" value="HTML5" />
\t \t <property name="cacheable" value="false" />
\t \t <property name="order" value="0"></property>
\t </bean>
\t <!-- Thymeleaf Template Engine -->
\t <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
\t \t <property name="templateResolver" ref="templateResolver" />
\t \t <property name="additionalDialects">
\t \t \t <set>
\t \t \t \t <bean class="org.thymeleaf.extras.tiles2.dialect.TilesDialect" />
\t \t \t </set>
\t \t </property>
\t </bean>
\t <!-- Resolves logical view names returned by Controllers to Tiles; a view
\t \t name to resolve is treated as the name of a tiles definition -->
\t <bean id="tilesViewResolver" class="org.thymeleaf.spring4.view.AjaxThymeleafViewResolver">
\t \t <property name="viewClass"
\t \t \t value="org.thymeleaf.extras.tiles2.spring4.web.view.FlowAjaxThymeleafTilesView" />
\t \t <property name="templateEngine" ref="templateEngine" />
\t \t <property name="order" value="1" />
\t \t <property name="characterEncoding" value="UTF-8" />
\t </bean>
\t
\t <bean id="tilesConfigurer"
\t \t class="org.thymeleaf.extras.tiles2.spring4.web.configurer.ThymeleafTilesConfigurer">
\t \t <property name="definitions">
\t \t \t <list>
\t \t \t \t <value>/WEB-INF/**/views.xml</value>
\t \t \t </list>
\t \t </property>
\t </bean>
服務配置
<!--the businesservice and auservice are not relevant to the current problem. Not used-->
<bean id="adminUserViewService" class="jake.prototype2.service.user.AdminUserViewServiceImpl">
\t \t <property name="businessService" ref="businessService" />
\t \t <property name="auService" ref="auService" />
\t </bean>
的Javascript配置
<!--general config-->
<!-- The following is required to access the javascript libraries required for ajax calls-->
\t <mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />
\t <mvc:annotation-driven />
\t <mvc:default-servlet-handler />
<!---WebFlow Flow config-->
<flow xmlns="http://www.springframework.org/schema/webflow"
\t xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
\t xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.4.xsd">
<!-- Here I instantiate a bean that just has get and set date methods and a java.util.date field-->
<var name="mydate"
\t \t class="jake.prototype2.controller.viewwrapper.ViewWrapperHelloWorld" />
\t <!-- called the first view through a controller but I could set up in xml config -->
\t <view-state id="hellotlv1">
\t \t
\t \t <transition on="next" to="standard" />
\t </view-state>
<!-- This confirms that tiles are working. Two tiles are integrated onto a template -->
\t <view-state id="standard"> \t
\t \t <transition on="next" to="standardext" />
\t </view-state>
\t
\t <!-- This is where we call an ajax method. First we update the mydate bean, then we render as an ajax fragment -->
\t <view-state id="standardext">
\t \t
\t \t <transition on="next" to="xzlogin" />
\t \t <transition on="doHelloWorld">
\t \t <!-- I update the date. I have used this design before and it works, i.e., passing variable in as an argument,
\t \t updating value and returning to view via webflow -->
\t \t <evaluate expression="adminUserViewService.doHelloWorld(mydate,flowRequestContext)"
\t \t \t \t result="mydate" />
\t \t \t <render fragments="helloworld" />
\t \t </transition>
\t </view-state>
..........
<!--Tiles Config-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
\t "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
\t "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
\t
<tiles-definitions>
\t
\t
\t \t <!-- If just using tiles view resolver all pages must be defined in view regardless of whether or not they use tiles
\t \t The path to the tiles is the path over and ablve the path specified in templateResolver configuration. Hence since template configuration
\t \t specifies WEB-INF/html and since there is a single view.xml and all html files (templates and fragments) in the html folder, no further
\t \t path specification is required in this case. Webflow will be looking for the definition name as the "to" value of a transition -->
\t \t <definition name="hellotl" template="hellotl" templateType="thymeleaf"/>
\t \t <definition name="hellotlv1" template="hellotlv1" templateType="thymeleaf"/>
\t \t
\t \t
\t <!-- standard.html is a template. hw and hw2 are tiles inserted into the template. Note there is no need to specify a suffix .html here -->
\t \t <definition name="standard" template="standard" templateType="thymeleaf">
\t \t <put-attribute name="testa" value="hw :: content" type="thymeleaf"/> \t
\t \t <put-attribute name="testb" value="hw2 :: test" type="thymeleaf"/>
\t \t <put-attribute name="helloworld" value="hw :: helloworld" type="thymeleaf"/>
\t \t </definition>
\t
\t <!-- standardext is where we attempt an ajax call. -->
\t <definition name="standardext" extends="standard" templateType="thymeleaf">
\t \t <put-attribute name="testa" value="hw3 :: content" type="thymeleaf"/> \t \t
\t \t <put-attribute name="testb" value="hw2 :: blank"/> \t
\t \t <put-attribute name="helloworld" value="hw3 :: helloworld"/> \t \t
\t </definition>
\t
</tiles-definitions>
** HTML模板**
<!--this is the template for tiles-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:tiles="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org"
lang="en">
<head>
<title>test layout</title>
</head>
<body >
<div tiles:include="testa">dodododo</div>
\t \t This text appears everywhere
<div tiles:include="testb">kkkkkkk</div>
<div tiles:include="helloworld">hello world</div>
</body>
</html>
** HTML瓷磚阿賈克斯**
<!-these are the two tiles used for the Ajax call>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
\t xmlns:th="http://www.thymeleaf.org"
\t xmlns:tiles="http://www.thymeleaf.org"
\t xmlns:sec="http://www.thymeleaf.org" lang="en">
<head>
</head>
<body>
\t <div tiles:fragment="content">
\t \t <script type="text/javascript" th:src="@{/resources/dojo/dojo.js}"></script>
\t \t <script type="text/javascript" th:src="@{/resources/spring/Spring.js}"></script>
\t \t <script type="text/javascript"
\t \t \t th:src="@{/resources/spring/Spring-Dojo.js}"></script>
\t \t <form id="triggerform" method="post" action="">
\t \t \t <input type="submit" id="helloWorld" name="_eventId_doHelloWorld"
\t \t \t \t value="Update now!" />
\t \t </form>
\t \t <script type="text/javascript">
\t \t \t Spring.addDecoration(new Spring.AjaxEventDecoration({
\t \t \t \t formId : 'triggerform',
\t \t \t \t elementId : 'helloWorld',
\t \t \t \t event : 'onclick'
\t \t \t }));
\t \t </script>
\t </div>
\t
\t
\t <!--If I do not include a tiles:fragment, I get an excetion from apache tiles-->
\t <div id="data" tiles:fragment="helloworld"> <span th:text="${mydate}? ${mydate.date}">
\t <!--because the date is initialized with the bean, I always see the date here, but it does not update-->
\t \t the date goes here</span></div>
</body>
</html>
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.webflow.execution.RequestContext;
import jake.prototype2.controller.utilities.SessionAndRequestParameters;
import jake.prototype2.controller.viewwrapper.ViewWrapperHelloWorld;
import jake.prototype2.controller.viewwrapper.ViewWrapperUserAdminLogin;
import jake.prototype2.controller.welcome.*;
import jake.prototype2.model.business.Business;
import jake.prototype2.model.user.UserAdmin;
import jake.prototype2.model.user.UserStructureException;
public class AdminUserViewServiceImpl implements AdminUserViewService
{
/**The autowired beans are not required for the hello wrld function**/
@Autowired
private BusinessService businessService;
@Autowired
private AdminUserService auService;
/*******service methods************/
/**The method takes a bean declared in test flow as an argument and returns it as the return object.
* I cannot guarantee this is the best design as I don't know how webflow deals with objects.
* (In theory, it should be returning the same reference)
* RequestContext is not needed in this example, but it is a helpful tool in many methods if you need access to
* webflow or servlet environment objects. Note, this is webflows, request context
* org.springframework.webflow.execution.RequestContext**/
public ViewWrapperHelloWorld doHelloWorld(ViewWrapperHelloWorld mydate, RequestContext ctx)
{
SS.getLogger().debug("\n\n\nReturning with new date");
mydate.setDate(new Date(System.currentTimeMillis()));
return mydate;
}