Following on from an earlier article(Using inputNumberSlider with Dates) where I showed you how you could use an <af:inputNumberSlider> to display formatted date strings rather than numbers, I've been expanding into other uses for the slider components.
Specifically the most recent use case was to represent text labels for the number "stops" on the slider so that it could be used as a way of filtering datasets. So this is what it looks like:
So, no problem you say, the previous article shows pretty much how to do that - why a new one? Well the twist here is in the form of tables.
What if I want to use the slider in a table, and I want to have different slider labels for different rows, like this:
Well that's a bit more of a problem. Why you ask? It's because of the way that tables work. When you define a table, each row is stamped out from the same set of components. So If I have one converter that say converts numbers to Domain, Kingdom, Phylum etc. associated with the slider then that's the converter that I'm going to use for every row as it's stamped out. I can't use a different converter per row. (Well OK I could use EL to specify a different converter value for each but then I'd need to define as many converters as I have value lists and plus I would have to know in advance what all the possible lists of filter values are. In this case, the reality is that the values shown in the sliders come from user configuration rather than being baked into the application anyway, so a hardcoded solution is out) .
So my aim here was to build a converter that could be used generically with as many different lists as required. You can download the resulting code from here.
If you take a look at the demo you will see that the converter is defined by name in the faces-config.xml and then associated with the inputSlider
<af:inputNumberSlider value="..." minimum="0" maximum="3" minorIncrement="1"
<f:attribute name="imsConverterMeasureElements" value="John,Paul,Ringo,George"/>
The actual list of elements which will be displayed as labels for each slider stop are then passed as a comma delimited string using the <f:attribute> tag.
This version of the converter always assumes a zero indexed list and the labels are assigned in order from zero. So selecting George in the slider above will translate into a value of 3. It would be perfectly possible to adapt the code to allow specific mapping between a number and the label, e.g. if you wanted a 1 based list you might pass a definition string like this:
You'd just need to do a little more parsing in the converter itself to make this work though.
Even with no change you can use the converter out of the box with <af:inputRangeSlider>. Here's a version with Roman numerals:
Finally on the matter of datatypes there is a slight twist when using a model attribute of type oracle.job.domain.Number. The ismsConverter will handle the basic Java types, float, int, long double etc. and then there us a second converter called ismsJboConverter that handles the JBO Number type. All of this is shown in the demo.