Monday, June 10, 2013

Icefaces 3.x : Handling session expired page redirection using jsf.ajax

Standard JSF solution for redirect session expired page.
Without handling page redirection in case of session expiration in JSF standard implementation, you will get the Internal server error with javax.faces.application.ViewExpiredException thrown from JSF engine.



If you're working with standard implementation of JSF (no extended jsf component like myfaces or icefaces), the solution for redirecting page when session has expired is simply to define <error-page> tag in web.xml like this.

  <error-page>
  <exception-type>javax.faces.application.ViewExpiredException</exception-type>
  <location>/faces/target.xhtml</location>
  </error-page>

After applying error handling for ViewExpiredException, client still receive Internal Server Error but page redirection is completely loaded (Actually the page is forwarded instead of redirected).



But this method cannot be used to handle the same case in Icefaces 3.x!
Icefaces has its own mechanism for handling view states. Components shown in web browser are updated from server by controller called bridge which is javascript ajax that manage connection states.
When session expired is detected, popup message appear to show status.


Using jsf.ajax to handing session expired error and redirect to another page.

Standard JSF2.x implementation support Ajax by providing jsf.js as javascript resource. By adding the following tag with <head> tag of html document you can use several functions supported by ajax library.
<h:outputScript library="javax.faces" name="jsf.js"/>

Using Icefaces, you don't need to include above tag into your page source. It bundles this file automatically so you can write call back function jsf.ajax.addOnError that supported by jsf.js to receive exceptions from the bridge. Put the following javascript somewhere in body tag to detect SessionExpiredException.

<script type="text/javascript">
   jsf.ajax.addOnError(function(data) {
if (data.responseText.indexOf("SessionExpiredException") > 0) {
   window.location = "page2.jsf";
        }
   });
</script>

Whenever the bridge javascript caught SessionExpiredException, the added call back function will redirect to another page.


Although the redirection is completed, you still see a popup message just a second before redirection. To get rid of the popup message, you have to add the following context parameter to web.xml.

  <context-param>
    <param-name>org.icefaces.disableDefaultErrorPopups</param-name>
    <param-value>true</param-value>
  </context-param>





Saturday, June 8, 2013

Installing Virtual Box's Guest Additions for Cent OS 6.4

Why Guest Additions installation failed?
Virtual Box's Guest Additions for Linux based guest OS need to compile kernel modules while it is installing additional components. Your Linux need compilation tools and kernel development libraries so that installer can use them to compile kernel modules.



Packages required for installing Virtual Box's Guest Additions
Before install Virtual Box's Guest Additions, You should install compilation and kernel development tools using root account.

#yum install gcc automake libtool kernel-devel

Then mount VBOXADDITIONS image by selecting from Virtual Box's menu.

Devices -> Install Guest Additions..

Installation
After VBOXADDITIONS image has been mounted, In terminal window, go to mounted point and run installation script.

#cd /media/VBOXADDITIONS_4.X.X
#./VBoxLinuxAdditions.run

Installation should pass without [FAIL] status. Shutdown Linux and start up again.

After Linux has been started, you can do the following features come from the guest additions.

  • Move the mouse into or off the guest screen seamlessly.
  • Working with guest OS in full screen mode.

And by enabling some features in Virtual Box's devices menu, you can do the following tasks.

  • Drag files or folders from host OS into guest OS desktop screen.
  • Copy some text from application which run on host OS and then paste it into application which run on guest OS.