2007年5月7日星期一

Question on JSF state saving

JSF state is restored or used in "Restore View" of JSF life cycle. These state can be stored in 2 places:client and server. There are some links about the difference of them:

http://www.jroller.com/page/mert?entry=state_saving_method_client_side
http://www.jroller.com/page/cagataycivici?entry=jsf_state_saving_best_of
http://www.jroller.com/page/cenkcivici?entry=changing_default_state_management_method

These states are used to store data about the JSF component tree(the elements in f:view), including components and component id. They can be seen between 2 request. That is the difference from backend bean. At first thought most of components have no state, or just have a value which presents its state. A text field has state? But YES. Disable/Enable is a common state. In the component implement java code, saveState and restoreState methods deal all these work: choose some attributes and save them to an object which can be found as a hidden field named javax.faces.ViewState in client's browser source code. It was Base64 encoding. And of course, the view state has been configurated to be stored in the client. In Sun's webui implement, many attributes are stored in view state, such as javascript event method and style.

Some component such as Table can be very complex and has its own states such as the current page number and ordered column. If these states doesn't be stored in component tree, we have to save them in hidden input field.

Myfaces even has a component t:saveState just for storing data. See here.

This technology is powerful when user's action is within one page. When page is refreshed, all he has done are saved. If he just jumps between page, navigate from one page to another page, then the state of a page is discarded, and more it is useless. In one page scenario, AJAX is also a good choice. They all improve user's experience.

Somebody provides stateless approach.

There is a cool tool called FacesTrace to monitor JSF application. It displays not only session data, but also the whole JSF life cycle dynamically.

2007年5月4日星期五

test code and use Microsoft Writer

test code
if (component instanceof ValueHolder && (null != (converter = ((ValueHolder)


the css please refers here. make sure that css code block should be placed in <head> and started with .post.

  In your blog, you should enbrace your code with <code> tag in HTML view.  And in your code block, you cann't use <> these simble. You change it into HTML code by some tools like phpfi. It also provides highlighting feature.

  But this approach is some boring. Later I found M$ Live Writer. It is cool. You can edit blog on offline mode and post it when online. You also can download blog item, modify it, and update it to Blogger. You also can delete blog by Writer although Writer didn't remind you. The editor is css-enable. And more interesting it is extensible.

  It's disadvantage I found until now is that it cann't upload image file(Blogger does not support it). It can just add a image link.

  (6.4 add)Today Writer beta2 is released. It has many nice feature. The biggest imprement is that my article can use tag. Well Done! It looks really cool! I think Microsoft will let it more powerful.

  The reason of Writer's existen is:1)It provide offline edit mode; 2)It is WYEIWYS editor; 3) web editor is not so much convenient until now. You will find these problem specially when the article is some long.

2007年5月3日星期四

use ajax4jsf

Ajax4JSF is a framework which inserts AJAX function to JSF. It is easy to transform orginal JSF code to Ajax-able. Ajax4JSF just changed the way of http message.
It's document is here. It has a simple example. Look at blow code:


the reRender property points out whose data in JSF component tree should be return from server. After JSF engine renders that component, Ajax4JSF then sends response. So this approach didn't do harsh to JSF. We can code in JSF bean:

private HtmlOutputText rep2 = new HtmlOutputText();
......
String style="border-color: rgb(204, 0, 255); backgroun.....";
this.rep2.setStyle(style);

We can see the benefit of JSF component model. But this model don't consider the position of the javascript or it is hard to add javascript function. For example, if we want to hightlight the outputText, Should I write a new class extends HtmlOutputText which has a cool appearance? Maybe a Decrtor Pattern is better. No matter which approach we use, we should encapsulate the javascript into JSF component and give user a consistent usage. On the other hand, If we have a JSF component which is not ajax-able but provides hightlight function, we can use it directly in Ajax4JSF. So the problem is the matter of JSF instead of Ajax4JSF.