Wei Geng

Greenhorn
+ Follow
since Dec 10, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Wei Geng

May I know how to develop Jruby + rails in Eclipse? Which plugin need to install?

Thanks!
12 years ago
Hi,

I have one question about how to transfer object instance when using Hibernate lazy-loading.

In order to improve the performance, we usually use the lazy-loading on 'One-To-Many'. However, the lazy-loading can only be used under the Hibernate Session scope.

Assuming that the transaction scope was set on the methods of 'Service' tier, we can get the Entity object by calling the 'Service' method, but can't visit the lazy-loaded Collection member of this Entity object outside the 'Service' method, for example, in the 'View' tier. Because the Session has been closed outside the 'Service' method.

So how can we transfer the lazy-loaded Collection type member outside the Session scope? If we directly return the new Collection by copying the elements of the lazy-loaded Collection, I think it may break the Hibernate's original intention on Object Orientation.

Can anybody help to provide a best practice?

Thanks!


There is a tricky approach to realize your request.

Two steps:
1. Set the 'onchange' attribute of <h:selectOneMenu> to 'submit()'.
2. In the corresponding valueChangeListener method, invoke the action method you want to use and invoke renderResponse method. Like following:


The principle as following:
Once the selection changed, a submission will be performed. The valueChangeListener method will be invoked first. Then you can freely invoke your action as any simple, normal methods. At last invoking renderResponse method will let system directly render the response to browser, jumping over the following normal JSF phases. In the other word, other actions or actionListeners will not process any more.
14 years ago
JSF
I have no idea how to implement the synchronization without using bean logic.

I wrote some codes with bean logic. Hope it helpful. By the way, I am also newbie in RichFaces. If anything wrong with my codes, please help to advise.

Thanks!

For POJO Bean:



For managed bean:



For JSP Page:
14 years ago
JSF

Fan He wrote:I've met the similar problem that only the first time the panel can be displayed. From the second time (after the panel was hide for once) you will never see the panel.

The following alternative method may help:



Thanks for your reply and your alternative method.

However, I really want to know the root cause of that issue.

Did us make anything wrong with the code or is it actually a bug of RichFaces?

14 years ago
JSF
Hi luca,

I am also a novice on RichFaces. But I think I can answer your question.

The keypoint is that the RichFaces will refresh the page content by Ajax. In other word, the new response from server will first scan the DOM tree. When it finds the mark of component in DOM tree, it will refresh the content of component.

In you case, when the page first time loaded from server to the browser, due to the 'render' attribute of 'mypanel' is 'false', there isn't any corresponding content about 'mypanel' rendered to page. After clicking the button, the 'render' attribute of 'mypanel' is set to 'true'. When the new response sent to browser, the browser failed to find the mark of 'mypanel' in DOM tree. Therefore, no change will be shown on the page.

To solve this problem, the recommended method is to place the component (which attribute is 'false' initially) into a container componet. And try to reRender this component every time.

Since this container will be rendered every time. When the new response sent to browser, the browser will be able to find the 'mypanel' successfully.

Just like following, very simple:


You can also use the <rich:panel> or other container component instead <h:panel>.

I hope it is helpful. Good luck!

14 years ago
JSF
Hi all,

I met some trouble when I used the RichFaces contextMenu and modalPanel together.

I hope to show the modalPanel by clicking the context menu item.

For the first time I clicked the menu item, the modal was showed. However, the second time, the menu item even didn't execute. Then the third time, everything went well again. And then 4th time failed, 5th time succeeded, 6th time failed..., alternately.

Thus, 50% succeeded and 50% failed. It's too weird.




When I remove the code on line 10.


The actionListener of menuItem can be executed successfully every time.

Can anybody help to advise the reason?

Thanks in advance!



14 years ago
JSF
Maybe you can try java.text.SimpleDateFormat class.

This class allows us to format the Date into a certain pattern (i.e. yyyy-MM-dd HH:mm:ss) and also can parse the a String to Date with a pattern.

Please read the Java SE API. It will be helpful.

14 years ago
I guess what you want to do is to trigger the page refresh by changing the value of selectOneMenu, right?

When the attribute onchange="submit()" executes, the JSF will run the whole lifecycle, of course, including the actionListener invoking. So you will see the actions are executed.

You are supposed to change the normal lifecycle flow. How to do it?

Very easy:

You should add a ValueChangeListener method for your selectOneMenu and make sure to invoke the FacesContext.renderResponse() method before return. Just like this:


When you select the new item of selectOneMenu, the valueChangeEvent will be triggered. Before valueChangeListener returns, renderResponse() method will jump over the following phase(ie. actionListener) and render the component directly. Thus, the actions will not be executed.


14 years ago
JSF
I guess what you want to do is to trigger the page refresh by changing the value of selectOneMenu, right?

When the attribute onchange="submit()" executes, the JSF will run the whole lifecycle, of course, including the actionListener invoking. So you will see the actions are executed.

You are supposed to change the normal lifecycle flow. How to do it?

Very easy:

You should add a ValueChangeListener method for your selectOneMenu and make sure to invoke the FacesContext.renderResponse() method before return. Just like this:


When you select the new item of selectOneMenu, the valueChangeEvent will be triggered. Before valueChangeListener returns, renderResponse() method will jump over the following phase(ie. actionListener) and render the component directly. Thus, the actions will not be executed.


14 years ago
JSF
I suggest you to read the book of 'JavaServer Faces in Action', the author of which is Kito Mann.

In this book, the first sample is very similar with the case you described.

The keypoint:

1. Bind the GridPanel with the member variable of the backing-bean with 'binding' attribute of component Tag.
2. Write an method as actionListener.
3. When the button triggers the actionListener method, in this method, you can manipulate the GridPanel Java instance with Backing-Bean member varialbe, getting the child-component collection and adding the new component into it. In the following View-Restore phase, the new element will appear on page.

I hope it can be helpful.
14 years ago
JSF

Tim Holloway wrote:You should never assume that property getters on a backing bean will be called only once. In particular, don't do any side (state-changing) logic in getters for that reason. The bean's properties will be retrieved at multiple times in the JSF lifecycle as needed to prepare for update, display, and validate.

As far as the second question goes, I haven't studied that.




Thanks for your answer to the first question.

Regarding to the second one, I guess I've got it.

According to the book 'Core JSF Programming', the method that is binded to 'actionListener' attribute in component tag will always been invoked earlier than the progressAction method of <f:actionListener> ActionListener.

In my opinion, <f:setPropertyActionListener> is a kind of <f:actionListener>. Therefore, its progressAction method will not be invoked until 'actionListener' attribute method finished.

I have made a test and it proved my guess.
14 years ago
JSF
I wrote a very simlpe JSF page like this:


And the managed bean class like this:



When I input a name and submitted this page, the console output is:


I have 2 questions:
1. Why the getUserName() method was invoked twice by system? I supposed 1 time is correct.
2. When the tag <f:setPropertyActionListener/> be executed? It was said it will be executed before simple actionListener. However, it seems that this tag was not executed until 'sayHello' actionListener finished.

Please help, thanks!
14 years ago
JSF
Yes, POI is a great project that implement the excel operation with Java. However, there was still a weak point for POI. POI can 'operate' the 'existing' Pivot table, but not 'create' a new pivot table in the excel file.

It is the reason why I hope to find a new free lib.

Thank you anyway.

I am looking forwards more answers for my question...
[ October 15, 2008: Message edited by: Wei GENG ]
Hello, everyone.

Does anybody know where can I find a free lib which is able to deal with the Excel Pivot table?

In my project, I hope to manipulate the Excel data to generate pivot table with the implement of pure java, instead of VBA.

I had ever search on google, but most of lib's are not free. Can anybody introduce a toll-free one?

Thanks!

Wei