- 浏览: 114968 次
- 性别:
- 来自: 哈尔滨
最新评论
-
1054442516:
大哥,小弟刚入门一个月。请tapestry如何集成Mybati ...
(C4)Tapestry IoC:Tapestry IoC Decorators -
walkerstar:
我都是这样做的 public void contribute ...
(2)Tapestry5学习小结:中文验证问题 -
hongyuzhe:
我是真的,那么的那么的希望能多贴出一些,代码说出来。既然能翻译 ...
(A18)Tapestry Core :Configuring Tapestry -
changshuangyi:
问个问题呀,我写的时候为什么private UserAuthe ...
(A6)Tapestry Core:Form Input and Validation -
zhenjw:
怪不得我想看5.0的源代码看不了,原来是没有真正的开放出来呢。 ...
(3)Tapestry5学习小结:显示问题
(1) Tapestry中文问题
在目前的Tapestry5.0.5-SNAPSHOT版本中,Tapestry还没有提供对中文的支持。查找了Tapestry的邮件列表,看到如下的解决办法。
首先,可以写一个UTF8properties的java文件。该文件可以到w3c的网站上找到,代码如下:
- public class Utf8Properties extends Properties {
- /**
- * use serialVersionUID from JDK 1.1.X for interoperability
- */
- private static final long serialVersionUID = 5907218757225133892L;
- /**
- * Encoding used to read properties from a file
- */
- public static final String ENCODING = "UTF-8";
- /**
- * Characters used to write comment lines in a property file
- */
- private static final String COMMENT = "#!";
- /**
- * Possible Separator between key and value of a property in a property
- * file
- */
- private static final String keyValueSeparators = "=: \t\r\n\f";
- /**
- * Creates an empty property list with no default values.
- *
- * @see java.util.Properties#Properties()
- */
- public Utf8Properties() {
- this(null);
- }
- /**
- * Creates an empty property list with the specified defaults.
- *
- * @param defaults the defaults.
- * @see java.util.Properties#Properties(java.util.Properties)
- */
- public Utf8Properties(Properties defaults) {
- this.defaults = defaults;
- }
- /**
- * Reads a property list (key and element pairs) from the input
- * stream. The stream is assumed to be using the UTF-8
- * character encoding or compatible.
- * Characters can be written with their unicode escape sequence.
- *
- * @param inStream the input stream.
- * @exception IOException if an error occurred when reading from the
- * input stream.
- * @throws IllegalArgumentException if the input stream contains a
- * malformed Unicode escape sequence.
- * @see java.util.Properties#load(java.io.InputStream)
- */
- public synchronized void load(InputStream inStream) throws IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(inStream, ENCODING));
- String line = in.readLine();
- while(line != null) {
- line = removeWhiteSpaces(line);
- if(!line.equals("") && COMMENT.indexOf(line.charAt(0)) == -1) {
- // Removes the beginning separators
- String property = line;
- // Reads the whole property if it is on multiple lines
- while(continueLine(line)) {
- property = property.substring(0, property.length() - 1);
- line = in.readLine();
- property += line;
- }
- //property = new String(property.getBytes(ENCODING), ENCODING);
- if(!property.equals("")) {
- int endOfKey = 0;
- // calculates the ending index of the key
- while(endOfKey < property.length() &&
- (keyValueSeparators.indexOf(property.charAt(endOfKey)) == -1)) {
- endOfKey++;
- }
- String key = property.substring(0, endOfKey);
- String value = property.substring(endOfKey + 1, property.length());
- key = loadConversion(key);
- value = loadConversion(removeWhiteSpaces(value));
- put(key, value);
- //// For debugging only
- //System.out.println("key: " + key);
- //System.out.println("value: " + value);
- //System.out.println("-----------");
- }
- }
- line = in.readLine();
- }
- }
- /**
- * A simple method to remove white spaces
- * at the beginning of a String
- * @param line the String to treat
- * @return the same String without white spaces at the beginning
- */
- public static String removeWhiteSpaces(String line) {
- int index = 0;
- while(index < line.length() && keyValueSeparators.indexOf(line.charAt(index)) != -1) {
- index++;
- }
- return line.substring(index, line.length());
- }
- /**
- * Replaces all characters preceded by a '\' with the corresponding special
- * character and converts unicode escape sequences to their value
- * @param line the String to treat
- * @return the converted line
- */
- private String loadConversion(String line) {
- StringBuffer val = new StringBuffer(line.length());
- int index = 0;
- // Replace all the "\." substrings with their corresponding escaped characters
- for(; index < line.length(); index++) {
- char currentChar = line.charAt(index);
- if(currentChar == '\\') {
- index++;
- currentChar = line.charAt(index);
- switch(currentChar) {
- case 't':
- currentChar = '\t';
- break;
- case 'r':
- currentChar = '\r';
- break;
- case 'n':
- currentChar = '\n';
- break;
- case 'f':
- currentChar = '\f';
- break;
- case 'u':
- index++;
- // Read the xxxx
- int value=0;
- for (int i=0; i<4; i++) {
- currentChar = line.charAt(index++);
- //System.out.println(currentChar);
- switch (currentChar) {
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- value = (value << 4) + currentChar - '0';
- break;
- case 'a': case 'b': case 'c':
- case 'd': case 'e': case 'f':
- value = (value << 4) + 10 + currentChar - 'a';
- break;
- case 'A': case 'B': case 'C':
- case 'D': case 'E': case 'F':
- value = (value << 4) + 10 + currentChar - 'A';
- break;
- default:
- throw new IllegalArgumentException(
- "Malformed \\uxxxx encoding.");
- }
- }
- // index must point on the last character of the escaped
- // sequence to avoid missing the next character
- index--;
- currentChar = (char) value;
- default:
- break;
- }
- }
- val.append(currentChar);
- }
- return val.toString();
- }
- /**
- * Replaces special characters with their '2-chars' representation.<br/>
- * For example, '\n' becomes '\\' followed by 'n'
- * @param line the String to treat
- * @return the resulting String
- */
- private String storeConversion(String line) {
- int length = line.length();
- StringBuffer outBuffer = new StringBuffer(length*2);
- for(int i = 0; i < length; i++) {
- char currentChar = line.charAt(i);
- switch(currentChar) {
- case '\\':
- outBuffer.append('\\');
- outBuffer.append('\\');
- break;
- case '\t':
- outBuffer.append('\\');
- outBuffer.append('t');
- break;
- case '\n':
- outBuffer.append('\\');
- outBuffer.append('n');
- break;
- case '\r':
- outBuffer.append('\\');
- outBuffer.append('r');
- break;
- case '\f':
- outBuffer.append('\\');
- outBuffer.append('f');
- break;
- default:
- outBuffer.append(currentChar);
- break;
- }
- }
- return outBuffer.toString();
- }
- /**
- * Indicates wether the property continues on the next line or not
- * @param line the beginning of the property that might be continued on the next line
- * @return true if the propertiy continues on the following line, false otherwise
- */
- private boolean continueLine(String line) {
- if(line != null && !line.equals("")) {
- return line.charAt(line.length() - 1) == '\\';
- }
- return false;
- }
- /**
- * The same method as java.util.Properties.store(...)
- *
- * @param out an output stream
- * @param header a description of the property list
- * @see java.util.Properties#store(java.io.OutputStream, java.lang.String)
- */
- public void store(OutputStream out, String header) throws IOException {
- BufferedWriter output;
- output = new BufferedWriter(new OutputStreamWriter(out, ENCODING));
- if (header != null) {
- output.write("#" + header);
- output.newLine();
- }
- output.write("#" + new Date());
- output.newLine();
- // we do not want that a Thread could modify this Utf8Properties
- // while storing it
- synchronized (this) {
- Enumeration e = keys();
- while(e.hasMoreElements()) {
- String key = storeConversion((String)e.nextElement());
- String val = storeConversion((String)get(key));
- output.write(key + "=" + val);
- output.newLine();
- }
- }
- output.flush();
- }
- }
然后将该文件编译后放到org\apache\tapestry\util包内。
接下来就可以修改其原文件了。要修改的原文件是org.apache.tapestry.internal.services包下的MessagesSourceImpl类。将该类的readProperties(Resource resource)方法中的java.util.Properties类改为我们编写的Utf8properties类。然后再修改org.apache.tapestry.internal.services包下的RequestImpl和ResponseImpl类文件。
将RequestImpl类文件中的方法改为如下内容:
- public String getParameter(String name)
- {
- String param = _request.getParameter(name);
- if(param != null)
- try
- {
- param = new String(param.getBytes("ISO-8859-1"),"utf-8");
- }
- catch (UnsupportedEncodingException ex)
- {
- //won't error
- }
- return param;
- }
- public String[] getParameters(String name)
- {
- String[] params = _request.getParameterValues(name);
- try
- {
- for(int i=params.length-1;i>=0;i--){
- params[i] = new String(params[i].getBytes("ISO-8859-1"),"utf-8");
- }
- }
- catch (UnsupportedEncodingException ex)
- {
- //won't error
- }
- return params;
- }
将ResponseImpl类文件中的方法改为如下内容:
- public PrintWriter getPrintWriter(String contentType) throws IOException
- {
- notBlank(contentType, "contentType");
- if(contentType.matches("text/html.*"))
- _response.setCharacterEncoding("utf-8");
- _response.setContentType(contentType);
- return _response.getWriter();
- }
- public OutputStream getOutputStream(String contentType) throws IOException
- {
- notBlank(contentType, "contentType");
- if(contentType.matches("text/html.*"))
- _response.setCharacterEncoding("utf-8");
- _response.setContentType(contentType);
- return _response.getOutputStream();
- }
最后重新编译打包就可以了。最后要注意的是此时我们所有应用用到的文件都要以utf-8格式进行编码.
该问题由LinuxBoy在邮件列表中提出,并得到了解决。
https://issues.apache.org/jira/browse/TAPESTRY-1294
评论
4 楼
foxgst
2007-08-30
5.0.5可以显示中文了。不过对于输入表单的中文没法正常提交,需要追加转换器。
TO KorbenZhang,把所有的页面都定义成了HTML文件,不是个优良解决方法。
TO KorbenZhang,把所有的页面都定义成了HTML文件,不是个优良解决方法。
3 楼
shiweili
2007-07-17
我在开发中遇到了中文参数没办法正常工作的情况。
Tapestry4.0.2、JBoss4.0.3
用的组件是:contrib:XTile
Java代码如下:
@SuppressWarnings("deprecation")
public void handleCallback(IRequestCycle cycle) {
Object[] params = cycle.getListenerParameters();//在上里页面传过来如果是中文参数就不会运行下面的代码。
......}
Html:
<span jwcid="@contrib:XTile" listener="ognl:listeners.handleCallback"
sendName="sendValue" receiveName="recvCompletions" />
有谁也遇到类似的问题吗?
Tapestry4.0.2、JBoss4.0.3
用的组件是:contrib:XTile
Java代码如下:
@SuppressWarnings("deprecation")
public void handleCallback(IRequestCycle cycle) {
Object[] params = cycle.getListenerParameters();//在上里页面传过来如果是中文参数就不会运行下面的代码。
......}
Html:
<span jwcid="@contrib:XTile" listener="ognl:listeners.handleCallback"
sendName="sendValue" receiveName="recvCompletions" />
有谁也遇到类似的问题吗?
2 楼
KorbenZhang
2007-07-16
不用这么复杂,在appModul中加入:
在改改web.xml的filter
我的没有问题。
http://mp2.crecg.com/tfan-dprhm/
public static PageResponseRenderer decoratePageResponseRenderer( @InjectService("PageMarkupRenderer") final PageMarkupRenderer markupRenderer, @InjectService("MarkupWriterFactory") final MarkupWriterFactory markupWriterFactory, final Object delegate) { return new PageResponseRenderer() { public void renderPageResponse(Page page, Response response) throws IOException { MarkupWriter writer = markupWriterFactory.newMarkupWriter(); markupRenderer.renderPageMarkup(page, writer); PrintWriter pw = response.getPrintWriter("text/html; charset=UTF-8"); writer.toMarkup(pw); pw.flush(); } }; }
在改改web.xml的filter
<filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
我的没有问题。
http://mp2.crecg.com/tfan-dprhm/
1 楼
Linuxboy
2007-07-09
貌似5.0.5已经解决……
发表评论
-
(3)Tapestry5学习小结:显示问题
2007-06-27 11:34 5342显示问题 我在做验证的 ... -
(2)Tapestry5学习小结:中文验证问题
2007-06-27 10:54 4375Tapestry5学习小结:中文验证问题 Tapestry5. ... -
(F1)Tapestry Upload:Tapestry Upload Component
2007-06-23 12:41 2888本文翻译出处 http://tapestry.apac ... -
(E1)Tapestry-Test
2007-05-28 16:06 3140本文翻译出处 http://tapestry.apache ... -
(D1)Tapestry-Spring Integration
2007-05-28 15:17 3793本文翻译出处 http://tapestry.apache ... -
(C15)Tapestry IoC:Service Builders Shadow Services
2007-05-28 13:45 2575本文翻译出处 http://tap ... -
(C14)Tapestry IoC:Service Builders Building Pipelines
2007-05-28 12:45 2449本文翻译出处 http://tapestry.apache. ... -
(C13)Tapestry IoC:Service Builders Strategy Pattern
2007-05-28 11:30 2181本文翻译出处 http://tap ... -
(C12)Tapestry IoC:Service Builders Chain of Command
2007-05-28 10:10 2222本文翻译出处 http://tap ... -
(C11)Tapestry IoC:Ordering by Constraints
2007-05-27 15:27 1991本文翻译出处 http://tap ... -
(C10)Tapestry IoC:Object Providers
2007-05-27 14:38 2174本文翻译出处 http://tapestry.apache ... -
(C9)Tapestry IoC:Starting the Registry
2007-05-27 11:44 1913本文翻译出处 http://tap ... -
(C8)Tapestry IoC:Symbols
2007-05-27 10:48 1947本文翻译出处 http://tapestry.apache ... -
(C7)Tapestry IoC:Case Insensitivity
2007-05-26 17:02 1621本文翻译出处 http://tapestry.apache ... -
(C6)Tapestry IoC:Type Coercion
2007-05-26 14:29 1719本文翻译出处 http://tap ... -
(C5)Tapestry IoC:Tapestry IoC Configurations
2007-05-26 09:19 1699本文翻译出处 http://tapestry.apache ... -
(C4)Tapestry IoC:Tapestry IoC Decorators
2007-05-25 10:19 1805本文翻译出处 http://tapestry.apache ... -
(C3)Tapestry IoC:Tapestry IoC Services
2007-05-24 13:04 1789本文翻译出处 http://tapestry.apache ... -
(C2)Tapestry IoC:Tapestry IoC Modules
2007-05-22 12:47 1940本文翻译出处 http://tapestry.apache ... -
(C1)Tapestry IoC:Introduction
2007-05-21 17:08 1947本文翻译出处 http://tapestry.apache ...
相关推荐
该包包含: Tapestry5最新中文教程.doc tapestry.pdf tapestry开发流程.docx Tapestry开发指南0.8.pdf tapestry用户手册.pdf
tapestry5组件说明使用及登陆修改等简单实例
本文介绍Tapestry框架版本5。本文利用Tapestry 5开发一个简单的具有创建/读/更新/删除功能的应用,在创建这个应用的过程中,本文体会到Tapestry带来的开发效率的提升。从多方面来讲解 Tapestry应用,比如应用的...
Tapestry5和jQuery集成.使用jQuery以极少的兼容问题完全替换Prototype 和 Scriptaculous库 标签:tapestry5
Tapestry是一个基于控件的框架以致于用它开发Web应用类似开发传统的GUI应用。你用Tapestry开发Web应用时你无需关注以操作为中心的(Operation-centric) Servlet API.引用Tapestry网站上的一句话:"Tapestry用对象...
强大的tapestry框架的学习入门资料,详细介绍了tapestry的常用开发文档。
是一本由多本Tapestry资料整合而成。包括一些Tapestry的实例。
1)解决了Tapestry5.3.8中文Bug问题 2)Tapestry 各种核心组件的使用 3)自带验证,自定义验证,验证码的生成 4)Tree组件的使用,Grid的各种使用(修改样式,排序,隔行换色等等),Loop组件的使用 5)集合Spring...
Tapestry~需要学习资料的进来看看 纯英文原版
最新Tapestry 5 電子書
在这里提醒一下大家,这个教程讲的是tapestry5而不是tapestry4,如果需要看tapestry4的话,请看我传的另外一本有关tapestry的教程,英文的那本,里面的例子超级详细,英语也不难,感觉属于tapestry4里的巅峰之作。
老外的一个ppt介绍Tapestry 5
Zubairov合作撰写了一篇文章,详细介绍Apache Tapestry 版本5——一个面向组件web框架。文章向读者展示了创建组件方法,并谈到了Tapestry中的IoC以及Ajax的相关特性 译者 沙晓兰 发布于 2008年7月2日 下午9时30...
Tapestry5最新中文教程.doc 作者 Renat Zubairov & Igor Drobiazko译者 沙晓兰 发布于 2008年7月2日 下午9时30分 社区 Java 主题 Web框架 ----------------------------------------- Tapestry5.1实例教程.pdf ...
Tapestry5 英文版入门技术指导!
Tapestry5.0.16文档和大家一起学习
Tapestry 4 官方文档中文版本,现在中文资料比较少,和大家共享一下
Tapestry5开发环境搭建(Eclipse),包括服务器搭建。。。
Tapestry 5开发指南(英文) Tapestry 5开发指南(英文) Tapestry 5开发指南(英文) Tapestry 5开发指南(英文)
最近在学习Tapestry,希望对你们有用