<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
3)
Biz eylemlerle kullanmak için özel bir sonuç türünü tanımlamak gerekir özel bir sonuç türü oluşturun:
package com.quaternion.result;
import com.opensymphony.xwork2.ActionInvocation;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.access.TilesAccess;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.servlet.ServletRequest;
import org.apache.tiles.request.servlet.ServletUtil;
public class TilesResult extends ServletDispatcherResult {
public TilesResult() {
super();
}
public TilesResult(String location) {
super(location);
}
@Override
public void doExecute(String location, ActionInvocation invocation) throws Exception {
//location = "test.definition"; //for test
setLocation(location);
ServletContext context = ServletActionContext.getServletContext();
ApplicationContext applicationContext = ServletUtil.getApplicationContext(context);
TilesContainer container = TilesAccess.getContainer(applicationContext);
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ServletRequest servletRequest = new ServletRequest(applicationContext, request, response);
container.render(location, servletRequest);
}
}
4) Biz de yaklaşık Struts2 anlatmak gerekir Sonuç türümüz:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<package name="tiles-package" namespace="" extends="struts-default">
<result-types>
<result-type default="true" name="tiles-result" class="com.quaternion.result.TilesResult"/>
</result-types>
</package>
</struts>
Bunun dışında Artık projelerimizde karoları kullanabiliriz, "test" denilen bir kiremit tanımını yarattığımızı varsayalım.
package com.quaternion.demo.action.test;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
@ParentPackage("tiles-package")
@Result(type="tiles-result", location="test.definition")
public class QuaternionResultTest extends ActionSupport{}
bu kadar
, bu daha da yapılandırma detayları için http://tiles.apache.org/framework/index.html bakınız, sen 3+ çinileri ile Struts2 herhangi bir sürümünü yapılandırmak sağlayacak: tanımı" biz aşağıdakileri yaparak bu tanımı kullanmak bizim eylem söyleyebilir . yeni bir eklenti Struts 2 eklendi Ken
Kiremitleri 2-konvansiyonlara bağlayarak etrafta dolaşıyorum, Çalışıyor, ama güzel değil ... belki de ben de gönderebilirim? – Quaternion
Lütfen, bu Tiles 3'ü desteklemenin ilk denemesidir, bu yüzden bir sonraki sürümle birlikte genişletebiliriz –
Taşınmış kabul edilmiş cevap burada ... çünkü bu eklenti yukarıda çok daha az iş yapıyor. – Quaternion