Showing posts with label programmatic. Show all posts
Showing posts with label programmatic. Show all posts

Saturday, February 12, 2011

Sorting Programmatic Data with NULLs as the Last Rows

This scenario can be a very specific requirement. In fact, by using a database query, you should be able to achieve this by using NULLS LAST or FIRST in the order by clause. Unfortunately you can't do this on a programmatic ViewObject thus this blog hehehe.

Let's say you have a programmatic viewObject which doesn't rely on a sql query at all for sorting.

This should already give you an idea on what to expect. The natural way that nulls are ordered is that they come before alphabets. So by sorting departments for example, this is what we'll get.


But what we want is for DepartmentName to be ordered but anything that does not have a description should be the last one. Take note, we are not using panelCollection here where we can sort multiple columns at once.

So let's add one column to tell us whether this department value is null or not.





Then let's override the setSortBy method on the viewImpl to append our extra sort parameter.




with this, any sort we do will always consider sorting the null descriptions to be the last rows.

Monday, February 7, 2011

Popup from Popup

There are many ways on how to launch a popup from a popup, and I'm going to demonstrate here a "backingBean-based" of launching this.

So why go programmatic? The reason for this is because most of the time, I would prefer launching one popup at a time, meaning  that when I call the second popup, I first make sure to close the current popup.

So a straight forward sample in launching the popup declaratively looks like this.





As you might already know, this is achieved by simply calling af:showPopupBehavior.

Now let's go for the programmatic approach in making sure we first close the current popup before launching a 2nd one. As I have already mentioned, there are different ways of achieving this without binding your popup to a bean by using javascript for example (see Invoke popup from a popup by Luc Bors ).





Cheers.