Archive for the ‘Java’ Category

JSF - UICommand component not rendering properly

Wednesday, September 26th, 2007

It was discovered that in certain situations a UICommand component does not bind properly to its associated action method in the managed bean. The symptoms of this situation occur when you have a page with an action, and you click the action and nothing occurs. The page seems like it submits, but no code inside the action method of the managed bean gets executed and no errors are generated in the console!

Problem

The problem arises when you have a managed bean in request scope and you have a UICommand, either a commandLink or commandButton, associated to the bean. In addition this UICommand component has a rendered attribute tag (boolean value) that uses a managed bean method to tell it whether is renders or not. Even if the component gets rendered to the screen, the component does not get binded to the action method in the request scoped bean. This is a problem with JSF and may be due to the fact that the component gets rendered, but since the bean is not created until a request is submitted, the component never gets binded to an action. Therefore, nothing in the action method ever gets executed.

Analysis

Thus is seems like if you want to dynamically render a submit type component, such as a button or a link, you cannot effectivley do that with a bean in request scope. You’ll have to place it session scope, which will work fine. Another option is to render the buttons all the time, but based on some scenario, using the “disabled” attribute to prevent a user from using the action. The “disable” attribute can access a boolean method in the managed bean.

You could also use Javascript to hide the already rendered button on certain circumstance. However this would require javascript knowing the state of the domain objects/and or managed bean state.

Java, Flash or AJAX? How to choose…

Wednesday, September 26th, 2007

1. What data do you want to present? If it’s almostly entirely HTML, then DHTML or AJAX is a good choice

2. How much client-side business logic or data-crunching do you want to do? For example, Google Spreadsheet is ok for small simple sheets but it’s basically a HTML terminal window - all the logic is server-based, so response times are sluggish as the data is shunted back and forth to Google’s web server and presentation capabilities are limited (basic formatting, no charts)

3. Would you like to share code (e.g. libraries for business or value objects) between your client and server? Java is your only option. And yes, Google Web Toolkit will let you convert some Java code to Javascript to run in the browser, but it’s scope is very limited. A common language means you can also move functionality from server to client or vice-versa with ease.

4. How easy would you like your design, development and debugging process to be? Let me guess - very easy? Good choice. While AJAX-aware IDE’s and design tools are coming, they are far from mature and only cover certain tasks, like placing your display or input widgets and (if you’re lucky) handling some of your web remoting needs. On the other hand, the range of Java tools is nothing short of stunning; the free Netbeans and Eclipse tools are excellent, and IntelliJ IDEA is still remarkably advanced and intuitive with nearly telepathic refactoring and completion/intention options.

5. Do you like fast responsive applications? Java is considerably faster than DHTML and the ability to migrate logic from server to client means that you can do more without a network round-trip.

6. Do you need offline support? Standard Java readily supports this today; you need proprietary solutions to do this with AJAX and Flash.

7. Do you need security? Java provides a rich mature security and permissions framework; in contracts, Javascript and browser caching/access model expose new security issues continually. Brendan Eich (designer of Javascript) of Mozilla acknowledges this and advocates a new model (which is not yet available)

So there’s only a few reasons why you might choose Flash or AJAX:

  • your customers have specifically rejected Java; check the above questions with them first so they know what’s involved with Flash or AJAX (essentially, greater cost and significantly greater risk)
  • speed of startup outweighs all the above listed considerations; AJAX probably wins in this case but transferring Javascript, HTML and XML across the web is not for free; run a debugging proxy behind your browser and watch the kilobytes fly when starting say GMail or Google Spreadsheet
  • you’re building an application that primarily involves graphical content or animation; Flash is a natural in this domain with excellent support from content authoring tools