struts2.1.2 版本 ajaxtags及其他插件的更改(二)

14 篇文章 1 订阅
5 篇文章 1 订阅

Migrate plugin configuration

Tiles 2

If you use the Tiles 2 plugin, check your tiles.xml file(s) to ensure they contain a DOCTYPE.

<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"  "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"> <tiles-definitions> ...
A missing DOCTYPE in your Tiles configuration will prevent your WebApp from starting. The following is a typical stacktrace for a missing Tiles DOCTYPE.
INFO: Initializing Tiles2 container. . . Nov 22, 2007 11:38:11 AM org.apache.commons.digester.Digester error SEVERE: Parse Error at line 2 column 19: Document is invalid: no grammar found. org.xml.sax.SAXParseException: Document is invalid: no grammar found.

Ajax Theme / Dojo

If your WebApp uses the ajax theme bundled with Struts 2.0 (ajax tags), you need to update every pageas the Dojo support has been moved into a separate plugin and tag library.

1. Add the Dojo plugin as a new dependency for your project

<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-dojo-plugin</artifactId> <version>2.1.1</version> </dependency>

2. Modify ALL pages that use the ajax theme to use the Dojo tag library.

For each page there are three tasks to complete:

  1. reference the new Dojo tag library
  2. update the head tag
  3. update all ajax themed tags
  4. check inline scripts
  5. check inline widgets
    If this is a major undertaking for your application, it's recommended to modify, test and validate each page one at a time.
Reference the new Dojo Tag Library

Reference the new taglib in your JSP or FTL pages.
Before

<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags"%> 

After

<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
Many pages will require both the core and dojo tags. The sx: prefix is preferred for the Dojo tags.
Update the head tag

Review the new attributes of the new head tag. You need to decide which values for the cache, compressed, parseContent and extraLocales attributes are appropriate for your application. These settings have major performance implications.

Before:

<s:head theme="ajax"/> 

After:

<sx:head parseContent="true"/> 
Update all ajax themed tags

Some tags are available only in the Dojo plugin taglib. It will be immediately obvious from your IDE that these tags need to change to the sx: prefix.
Some tags are available in both the core and Dojo plugin taglibs. Any tag that uses the ajax theme needs to be changed to the sx: prefix.

Before:

<s:url id="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /> <s:div id="jobStatus" theme="ajax" href="%{jobStatus}" updateFreq="5000" indicator="indicator"> </s:div> <img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/> 

After:

<s:url var="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /> <sx:div id="jobStatus" href="%{#jobStatus}" updateFreq="5000" autoStart="true" indicator="indicator"> </sx:div> <img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/> 

If you forget to migrate a tag reference from the core to the dojo plugin you will receive an exception similar to the one below:

2008-04-19 14:32:30,475 ERROR [http-8443-Processor23] [[jsp]] Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: No tag "datetimepicker" defined in tag library imported with prefix "s"
Check inline javascript

If your ajax html results contain inline javascript that needs to be executed after updating the DOM, ensure your ajax tags set executeScripts="true" and separateScripts="true". These attributes instruct the widget to search for javascript in the result,
extract it, update the DOM with the result and then execute the javascript.

eg. The following bind will execute scripts within the result when the Submit button is pressed

<s:submit value="Submit" id="submit3" /> <sx:bind targets="div1" highlightColor="#ffffcc" highlightDuration="500" sources="submit3" events="onclick" href="%{#fragment3Url}" errorNotifyTopics="/error" executeScripts="true" separateScripts="true"/>
Check inline widgets

If your ajax html results include dojo widgets, ensure the head tag's parseContent attribute is true. This instructs dojo to parse the ajax responses for widgets. Note that Struts2.0 always enabled this feature and it could not be turned off. Struts2.1 disables this feature and allows it to be turned on as there is a significant performance impact.

Convert EL expression_rs to OGNL

Struts2.1 tags do not allow evaluation of JSP EL within their attributes. Instead, Struts2 tags evaluate attribute values as OGNL. Allowing both expression_r languages within the same attribute opens major security vulnerabilities.

todo: how to convert

Forgetting to convert attributes to OGNL expression_rs will produce exceptions similar to the one below:

org.apache.jasper.JasperException: /example.jsp(8,6) According to TLD or attribute directive in tag file, attribute value does not accept any expression_r

Reduce verbose logging

Struts 2.1 introduces more verbose logging than Struts 2.0. While extremely valuable, some users may find these annoying.

Missing Properties

This message states that the framework searched for a property in the value stack and failed to find it.

2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir] 2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir] 2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir] 2008-04-19 14:21:08,178 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [org.apache.catalina.jsp_file]

To hide these messages, turn off the WARN level logging for OgnlValueStack.

eg. Include a new limit category in your log4j.xml file (only log errors or worse):

<category name="com.opensymphony.xwork2.ognl.OgnlValueStack"> <priority value="error"/> </category> 

TextProvider missing keys

These messages state that the framework searched for text in a resource bundle and failed to find it.

2008-04-19 14:32:30,106 WARN [http-8443-Processor23] [TextProviderHelper] The first TextProvider in the ValueStack (package.Action) could not locate the message resource with key 'companyDetails.addressId' 2008-04-19 14:32:30,107 WARN [http-8443-Processor23] [TextProviderHelper] The default value expression_r 'companyDetails.addressId' evaluated to '10'

To hide those messages, turn off the WARN level logging for TextProviderHelper.

eg. Include a new limit category in your log4j.xml file (only log errors or worse):

<category name="org.apache.struts2.util.TextProviderHelper"> <priority value="error"/> </category>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值