Ultimate Solution to Tomcat Encoding Problems

Edit server.xml and insert URIEncoding="UTF-8":

<Connector connectionTimeout="20000" port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1" redirectPort="8443"/>

Running from Eclipse

Edit Servers/SERVER_NAME/server.xml; and

Restart Eclipse to take effect.

Running in a Standalone Server

Edit TOMCAT_ROOT/server.xml; and

Restart Tomcat to take effect.

Access Web Flow Variables from Java Code

Occasionally, you may need to access web flow variables from Java code instead of using EL. To obtain a web flow variable, you simply use request.getAttribute(varName). List of var names are:

Spring Web Flow Tip: Result of evaluate in transition May Interrupt the Transition

If you use an <evaluate> within a <transition>, be ware that the outcome of evaluate actions may cancel the execution of the transition if the result is false, no. As the result, the flow stays at the current view-state. To avoid such behavior, you should use <set> instead.

Caller Flow:

Auto Height Resized TileList

<mx:TileList id="tile" borderStyle="solid" borderColor="red" right="10" left="10" top="391" updateComplete="tile1_updateCompleteHandler(event)">
</mx:TileList>

 

protected function tile1_updateCompleteHandler(event:FlexEvent):void {
    var rc: int = Math.ceil( ArrayCollection(tile.dataProvider).length / tile.columnCount);
    if (tile.rowCount!=rc) tl.rowCount = rc;
}

Tip: cd to the folder that contains the script launched

Unix/Linux:

#!/bin/sh
LAUNCH_FOLDER=`dirname "$0"`;
cd $LAUNCH_FOLDER;

Windows:

cd %~dp0

You can get a lot more information using different modifiers:

Tip: RegEx 检查非ASCII字符

如下的regular expression可用于检查string是否含非ASCII字符:

[^\u0000-\u007F]*

非ASCII字符可用于排除非英文的输入。

Flush Writers in Java

用Writer打印内容到console或者浏览器时,必须要考虑到flush。如果你用writer打印出很多内容,而程序结束时,writer如果没有被flush则用户完全看不到或者不会看到完整的信息。例如:

public static void main(String[] args) {
PrintWriter log = new PrintWriter(System.out);
log.println("Hello, Jack")
}

运行后,没有任何显示。这是因为"Hello, Jack"被buffer了,至少两种方法可以解决这个问题

设计模式之Item Render

Pattern name: Item Render

Motivation: 对于包含多Item的UI Component(如Tree, Table, DataGrid, etc) Item Containers来说,其行为大多固定,需要时常改变的是Item的显示。如果将显示实现放在这些item containers的class内,那么不仅这些classes的可重复利用性受到破坏,代码也难以管理。这时应该考虑将item的显示逻辑分离出来。

Approach: 将item显示逻辑独立出来放到item render class/function中。

建设更强的Build系统 Recent Build Improvement: obfuscated log4j.properties + ANT logging

自动更新log4j.properties里面的类名 Auto-update of class names in log4j.properties after obfuscation

期待已久的功能。实现起来不难 - 不外乎从混淆的log里面分析出原始及重新命名的类名,更新log4j.properties即可。

因是在build-obf.xml内实现的,故大部分build文件无需更改就可以享受此功能。注: 所有目标目录下的任何名为log4j.properties的文件将都会被更新。

使用Task将ANT输出log到文件里 ANT logging to file – Task <logtofile>

以前我们为了解决ANT logging to file, 可以使用如下的命令在影响ANT console输出的情况下log到文件:

ant -logger ant.DefaultLoggerWithFileOutput -DANT_LOG_OUTPUT_FILE=C:/a/b.txt

这样实现了基本功能,但非常不方便,尤其在IDE里面我们喜欢一键运行而不是输如上的命令。现在新的方法是使用Task将log写到文件里:

Flex Consulting Training Services are Now Offered in Asia-Pacific (China, Japan, Korean, Hong Kong, Taiwan, Singapore, Australia, and New Zealand)

Get Consulted or Trained by Asia-Pacific Most Admired Flex Development House. 

Why do you need it? Reduce Risk and Stop Worrying.

logo_transbgWe assume you are like us. Initially, our team had many doubts about Flex:

  • Can we use Flex in this project? – Have others done this kind of large projects before? How did they do?
  • Is Flex being released too often?–If Yes, old bugs might never get fixed and new bugs pop up with new releases.
  • Flex 3 or Flex 4? Much more difficult to answer than it looks.
  • Does the AVM offer a decent garbage collection mechanism? Enterprise apps are very different from simple Flash animation clips.
  • Why it is so complicated to remote objects with Hibernate at the server side? So much unnecessary work to do.
  • Should we use MXML more or AS more? MXML is great but the ever changing format of MXML brings chore for updating.
  • So many open source frameworks, which ones shall we use? They can not be all good.
  • How to divide work among team members? Everything seems so coupled like spaghetti.

If you are a project manager or a team leader, you'll probably have the same set of doubts. We wish we could have someone to help us answer those questions. Sadly, back then we have no one to turn to as Flex was a new kid on the RIA programming block.

We walked bravely along the Flex way and we found answers to above questions. On this road, we also experienced thousands of wrong ways to do Flex projects too. We could have finished Flex projects much much earlier if there were decent Flex consulting services available. Now, you do not have to do flex projects in the hard way.

DragDrop时, 使用DragEvent.dragInitiator来获得Drag源头, 而非DragEvent.relatedObject

问题描述:

在进行DragDrop时, 我使用了DragDrop.relatedObject来获得Drag触发的UIComponentpng-1048

如: var dargUI:TileList = e.relatedObject as TileList;

在AIR中运行, 可用且没有任何错误, 但当使用浏览器版本时, e.relatedObject为null, 上一行代码报错.

 

在包含`NOT`的SQL中需尤其注意NULL的情况 Beware NULL Values When SQL Contains `NOT`

MySQL运算:

SELECT NULL != 1 => NULL (false)

SELECT NULL = 1 => NULL (false)

SELECT NULL IN ('A', 'B') => NULL (false)

SELECT NULL NOT IN ('A', 'B') => NULL (false)

当你书写如下SQL(返回所有t.attr不为1或者2的行) - When you write the below SQL:

SELECT * FROM table_ t WHERE t.attr NOT IN (1, 2)

很可能应该是 - Probably what you really mean is:

SELECT * FROM table_ t WHERE t.attr IS NULL OR t.attr NOT IN (1, 2)

这样表述的情况是:只要t.attr不是1,也不是2, 但t.attr值可以为NULL。

Flex纯净代码 Flex Code with Zero Warning

04 Flex Builder 的“Problems”view 展示了所有的Error及Warning,但下面两种Warning我个人认为是不应该warn的:

1. Warning: 1084: var 'x' will be scoped to the default namespace: X: internal. It will not be visible outside of this package

当你的Variable scope为(default)时,以上Warning会出现。按照AS3的语言参考,(default)是完全合法的scope.

时区时间 Time in a Specified Timezone

Leopard_04 某个时间点在所有的时区里都是同一个时间点(即Date object相等),但人为表示却各不相同(Format有不同)。

Tomcat的中文乱码解决方法 Fixing Encoding Problems of Tomcat, Especially in Eclipse Context

Leopard_02 情景:有一个Servlet专门处理图片下载,给个相对地址,它返回实际图片内容:

http://HOST:8080/servlet/getImage?path=pic.jpg

ListBase进行拖拽时collectionChangeHandler()报错的解决方法

在基于ListBase进行拖拽以移动对象时, 时常会出现如下错误:png-0673

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at mx.controls.listClasses::ListBase/collectionChangeHandler()
[C:\autobuild\3.4.0\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:8190]

Flash Builder 4 Beta 2 新功能概览 New Features of Flash Builder 4 Beta 2

flash_builder_logo 本篇文章基于若干ADC的Flash Builder v4b2介绍文章及作者的实际试验。

Ctrl + Alt + H Call Hierarchy View 函数/方法调用层次关系

目的:用于了解代码运行

功能:利用它,我们可以轻松了解某个函数被哪些函数调用。

不使用继承来轻松获得被保护变量 Access protected/default Variables Without Inheritance in AS3

png-0025 在Flex中,为了获得较大的控制权,我们往往需要获得被保护的变量。举例来说,有一个TextArea被用来输出log。一般的情况下,每增加一行log, 我们直接将TextArea scroll到底部,所以最新的log信息一直可以被看到。然而有时从服务器返回的log有几百行至多,如果TextArea直接翻到底部,用户不得不向上翻(最重要的信息往往在前面)。我们的目标是每次log被加到TextArea,显示新加log信息的第一行。实现这个,我们必须使用TextArea.textField (protected) 或 TextArea.getTextField(internal, default)以获得行数信息。

TIP: 解决无法找到AS类错误 &quot;Access of undefined property of ClassA&quot;

在Flex/Flash BuildernewSampleProject_wizbanner中类已存在,也已经import,按Ctrl+Click也能直接点入这个类的源文件,但依然显示"Access of undefined property of ClassA" (假设此类名为ClassA).

造成这个错误的可能原因之一是package name与实际路径不符,如ClassA.as在src/com/test下,但类中“package com.test.a”. 一般在重新命名或移动packages时常有发生,只需更新类中"package ..."一行即可。

数据库连接泄露 Connection Leak Causes 'pool error Timeout waiting for idle object'

leak-main_Full 在使用DBCP数据库连接池时,如果遇到Exception “pool error Timeout waiting for idle object”,这意味着数据库连接泄露。解决这个问题的方法很简单,就是任何连接使用后,必须关闭它。示例代码:

Syndicate content