AJAX :: xajax

Posted on 17th July 2005 by Nio in AJAX, 程序人生

What is xajax?

xajax is an open source PHP class library that allows you to easily create powerful, web-based, Ajax applications using HTML, CSS, JavaScript, and PHP. Applications developed with xajax can asynchronously call server-side PHP functions and update content without reloading the page.

How does xajax work?

The xajax PHP object generates JavaScript wrapper functions for the PHP functions you want to be able to call asynchronously from your application. When called, these wrapper functions use JavaScript's XMLHttpRequest object to asynchronously communicate with the xajax object on the server which calls the corresponding PHP functions. Upon completion, an xajax XML response is returned from the PHP functions, which xajax passes back to the application. The XML response contains instructions and data that are parsed by xajax's JavaScript message pump and used to update the content of your application.

Why should I use xajax instead of another Ajax library for PHP?

You should choose whatever library will best meet the needs of your project.

xajax offers the following features that, together, make it unique and powerful:

1. xajax's unique XML response / javascript message-pump system does the work for you, automatically handling the data returned from your functions and updating your content or state according to the instructions you return from your PHP functions. Because xajax does the work, you don't have to write javascript callback handler functions.

2. xajax is object oriented to maintain tighter relationships between the code and data, and to keep the xajax code separate from other code. Because it is object oriented, you can add your own custom functionality to xajax by extending the xajaxResponse class and using the addScript() method.

3. xajax works in Firefox, Mozilla, probably other Mozilla based browsers, Internet Explorer, and Safari.

4. In addition to updating element values and innerHTML, xajax can be used to update styles, css classes, checkbox and radio button selection, or nearly any other element attribute.

5. xajax supports passing single and multidimensional arrays and associative arrays from javascript to PHP as parameters to your xajax functions. Additionally, if you pass a javascript object into an xajax function, the PHP function will receive an associative array representing the properties of the object.

6. xajax provides easy asynchronous Form processing. By using the xajax.getFormValues() javascript method, you can easily submit an array representing the values in a form as a parameter to a xajax asynchronous function:

xajax_processForm(xajax.getFormValues('formId');

. It even works with complex input names like "checkbox[][]" and "name[first]" to produce multidimensional and associative arrays, just as if you had submitted the form and used the PHP $_GET array

7. Using xajax you can dynamically send additional javascript to your application to be run in response to a request as well as dynamically update element attributes.

8. xajax automatically compares the data returned from the PHP functions to the data that is already in the attribute of the element you have marked for change. The attribute is only updated with the new data if it will actually change what is already in the attribute. This eliminates the flicker often observed in applications that update content at a regular time interval with data which may or may not differ from extant content.

9. Each function registered to be accessible through xajax can have a different request type. All functions default to use POST unless GET is explicitly set. This is to encourage careful consideration of when to use GET requests

10. If no request URI is specified, xajax tries to autodetect the URL of the script. The xajax autodetection algorithm is sophisticated enough that, on most servers, it will work under a secure https:// protocol as well as http:// and with nonstandard ports.

11. xajax encodes all of its requests and responses in UTF-8 so that it can support a wider range of characters and languages. xajax has been successfully tested with various unicode characters including Spanish, Russian, Arabic, and Hebrew

12. Nearly all of the javascript generated by xajax is included into your web application through dynamic external javascript. When you view the source of your application in your browser, the markup will be not cluttered by JavaScript function definitions.

13. xajax can be used with the Smarty templating system by creating a variable in smarty that contains the xajax javascript:

$smarty->assign('xajax_javascript', $xajax->getJavascript());

Then you can use

{$xajax_javascript}

in your header template to use xajax on your site.
试了一下 Graffiti Wall - DEMO,对于中文的支持没有问题 :)

PHP 5.1 Beta 3 Available

Posted on 16th July 2005 by Nio in 程序人生

image [14-Jul-2005] PHP 5.1 Beta 3 is now available! If all goes well, this beta release will be followed by a release candidate within a couple of weeks.另外,前几天 PHP 4.4.0 正式版也发布了(ChangeLog)。

John Lim 对其开发的 ADOdb 进行了 PHP 5.1 Beta 3 的 PDO 兼容性测试,发现了如下几个问题:# The pgsql driver currently does not support commit/rollback. All statements are autocommited.
(当前 pgsql 驱动还不支持 commit/rollback 事务,所有语句都是自动提交执行)

# The oci driver for Oracle does not support getColumnMeta(), so checking field types and names dynamically is not possible at run-time.
(Oracle 的 oci 驱动不支持 getColumnMeta(),所以在运行时不可能动态检测到字段类型与字段名)

# The mysql driver seems ok, except that it runs by default in unbuffered mode, which only allows a single query to execute.
(除了默认运行在 unbuffered 模式下之外,mysql 驱动还算比较 OK,unbuffered 模式只允许执行单个请求)

# Binding does not appear to work properly with pgsql and mysql with ? parameters. This might be a be bug in my code, and not a PDO issue. I haven't tested oci binding yet.
(对于 pgsql 和 mysql,binding 使用 ? 参数时不能正确运行,这可能是 ADOdb 的一个 bug,而不是 PDO 的问题。目前为止我还没有测试过 oci 的 binding)

百度 MP3 批量下载程序 v2.0 beta5 发布!

Posted on 14th July 2005 by Nio in BaiduMp3, 程序人生

ChangeLog:

*) 修复删除多个正在下载任务时出错的 BUG。
*) 无论窗口处于什么状态,都显示托盘图标(Tray icon)。
*) 修复由于百度修改下载页面而导致无法获取下载地址的 BUG。

请到此处下载 BaiduMp3_v2.0beta5.exe (316.416 KB)

Java :: Exception management

Posted on 12th July 2005 by Nio in 程序人生

Exception management and error tracking in J2EE
SummaryThink back on your last J2EE project. Did you encounter situations when errors were never logged—or logged more than once? Did you spend countless hours tracking down a bug, whose real cause was that someone swallowed an exception somewhere? Did your users see a stack trace? If so, chances are, you might need a common strategy for exception management and some complementing code. This article provides the basis for developing a set of policies along with a supporting framework for error handling in the J2EE world.
在最初的时候,Java 的异常处理让大家眼前一亮,但对于使用 checked exception(检查异常?)还是 unchecked exception(不检查异常?),有两个对立的观点:一方支持使用 checked exception,理由是调用者应该根据当前环境对抛出的异常进行处理;而另一方则支持使用 unchecked exception,因为一堆 try …. catch 块使得代码变得凌乱,而且经常是没办法即时对当前检测到的异常进行处理。很多人开始都是很敬业地对每一个可能异常进行检查,但在经历了N多N多的 catch 块之后,开始厌烦了,于是倾向于 unchecked exception,慢慢也就形成了一套简单的规则: 1. If it makes sense to handle the exception, do so
2. If you can't handle it, throw it
3. If you can't throw it, wrap it in an unchecked base exception and then throw it

仔细阅读此文会对今后处理异常有所帮助。作者处理异常的观点是: 1. Use unchecked exceptions: By using checked exceptions, clients are forced to take a position on errors they can rarely handle. Unchecked exceptions leave the client with a choice. When using third-party libraries, you don't control whether exceptions are modeled as checked or unchecked ones. In this case, you need unchecked wrapper exceptions to carry the checked ones. The biggest tradeoff in using only unchecked exceptions is that you can't force clients to handle them anymore. Yet, when declared as part of the interface, they remain a crucial element of the contract and continue to be part of Javadoc documentation.

2. Encapsulate error handling and install a handler on top of each tier: By having a safety net, you can focus on handling only exceptions relevant to business logic. The handler performs the safe touchdown for the remaining exceptions at the specific tier executing standardized steps: logging, system management notification, transformations, etc.

3. Model the exception hierarchy using a "simple living" approach: Don't automatically create new exception classes whenever new error types are discovered. Ask yourself if you are simply dealing with a variation of another type and if the client code is likely to explicitly catch it. Remember that exceptions are objects whose attributes can, at least to some extent, model the variation of different situations. Less than a handful of exception classes will most likely prove enough to satisfy a starting point, and only those that are likely to be handled need specialized attributes.

4. Give meaningful messages to end users: Unhandled exceptions represent unpredictable events and bugs. Tell this to the user and save the details for the technical staff.
另一篇文章:Best practices in EJB exception handling

夏 Zzzz….

Posted on 9th July 2005 by Nio in 日常生活

炎热的夏天,即使 BLOG 都懒……

这周经常在外边跑,人都快中暑了,总算把“生育服务证”给办好了,还陪 shxll 去医院做了检查,北京这边对于新生命从在胎中开始就进行跟踪、定期检查了,是为了优育吧,呵呵,据说小孩出生之后,还会继续跟踪一两年,甚至过来家访之类的,不知道要不要收费 ;)

公司两个办公室的人合到了一个办公室中,变得格外热闹,花草树木都多了很多,感觉想是在热带雨林,当然,温度也升高了不少,中央空调的凉快已经成了过去时。中午 CS 训练也就变成警匪都在一个屋了,唧唧喳喳还真是热闹,变得更加有趣;当然我也更加能蒙了,动不动就是将对方爆头,哈哈哈 :D 。现在周围的朋友都开始玩 WOW 了,我的机器玩不了,shxll 的机器倒是可以玩,但是现在我俩都没时间顾及这个了,也怕她玩游戏费神,伤了宝宝,HOHO,新生命安全第一。

这几周都没去锻炼身体,下周看看能不能有时间去打打羽毛球吧,活动活动筋骨。