Fork me on GitHub

n. Slang a rough lawless young Kuali developer.
[perhaps variant of Houlihan, Irish surname]
kualiganism n

Blog of an rSmart Java Developer. Full of code examples, solutions, best practices, et al.

Wednesday, December 21, 2011

Kuali Parameterized ValueFinder Implementation


Sometimes it is necessary to dynamically build a values finder based on some outside influence (sometimes another values finder). This is how to create a value finder that uses input from another source. I am going to use an example where we want to give a list of available mileages for a user to select from. We only want to show mileages to the user based on the date their travel arrangements are made during. If we don't limit in this way, the number of available mileages to choose from will be infinite and indistinguishable. What we need is a list of mileages based on a date determined by the trip information already in the form. This is how we do that.


1. Create a JstlFunctions class with static methods

getOptionsList is the only public method in the class.

You can see it returns a List because this will eventually be used with a JSP or JSTL tag file which do not support parameterized types. You can see that parameters are passed in as a Map called params. This is used via the addParametersToFinder method here:

2. Create a JSTL TLD

Now that we have our class and our public method that will create our finder for us, we will need some way to invoke it. The best way to do this is by using the static method through a tag. We can create this tag easily with a TLD.

3. Use it in a JSP

In our JSP, we will need to define a Map to add parameters to. You saw earlier that our getOptionsList method takes a Map with parameters in it.

Then, we need to assign some value to the Map:

Above we have assigned ${perDiemExpense.mileageDate} to the queryDate parameter in our Map! Now we just need our dropdown.

Now you can see where getOptionList is actually used. Now we have a dropdown list of mileage rates based on the date of the mileage since mileage rates can vary by date.

1 comment:

  1. This is an awesome post but the indentation makes the code a bit unreadable. Could you change that perhaps?