Pages

Sunday, February 13, 2011

Adding very basic AJAX Support to our JSF 2.x pages.

The last couple of days i tried to find out how to add AJAX support to my JSF UI components, so i can update them without refreshing the page... and also because other benefits of using AJAX.

A couple of guys from stackOverflow helped me out, and it was a complete success.

1-This is the selectOneMenu where the user picks a desired item
<h:selectOneMenu value="#{searchController.selectedCategory}">
<f:selectItems value="#{searchController.formatedCategories()}"></f:selectItems>
<!-- in f:ajax listener is not needed, but we can add it if we need it -->
<f:ajax event="change" execute="@this" listener="#{searchController.selectedCategoryMenu}"
render="menuType" />
</h:selectOneMenu>


2-This is how the new element that needs to be rendered looks like(The rendered attribute controls when each panel should be rendered)

<h:panelGroup id="menuType">
<h:panelGroup rendered="#{searchController.selectedCategory == 'cat1'}">
                                 //...
</h:panelGroup >
                         <h:panelGroup rendered="#{searchController.selectedCategory == 'cat2'}">
                                 //...
</h:panelGroup >
                        <h:panelGroup rendered="#{searchController.selectedCategory == 'cat3'}">
                                 //...
</h:panelGroup >
</h:panelGroup>



3(Optional)-Handling the change even in the managed bean

public void selectedCategoryMenu(AjaxBehaviorEvent e) { //...
}

This was my first experience combining JSF and AJAX. I was surprised how easy it was, a way easier than i thought.

Sunday, February 6, 2011

Mercurial installation bug

For those who use Mercurial as a project management tool:

The other day i was installing Mercurial from http://mercurial.selenic.com/
And i found that in winXP, when doing "hg commit" or "hg ci", this latest version returns an error, that says:
no username supplied (see "hg help config")
The solution is to add the following lines of code inside the file mercurial.ini:



[ui]
username = "your windows user name" (no quotes)

The file can be found at:
 C:\Program files\Mercurial\mercurial.ini
For some reason, the instalation does not add that information to the .ini file

Tuesday, February 1, 2011

web programmers most powerful weapon

The MVC(Model View Controller) Pattern
Today the most of the existing web frameworks that exist since web 2.0 support separation of concerns by using variations of the MVC pattern. It is an architectural pattern used to isolate business logic from user interface.


Model: The model is represented by the content(often stored in a DB) and it is displayed by the view.
It should be created without concern of its look and feel.
Examples: Entities that use ORM technologies, other backup classes that are included in the domain model, EJB calls...

View:The view are all the parts of the application that the user sees. We could say that it is the model presented graphically.
Examples: XHTML, WML and others...

Controller:The controller is the part that recives the infromation from the View about the desires of the user. The controller gets, converts, validates the data, invokes bussiness logic and generates the markup for the view to display.

In the image below you can see how each part should interact.

Share with your friends