Velocity report - multi select

Hi,

I am looking for the best way to incorporate values from a combobox in an Velocity template. I know of the :

$valueLists.getDisplayValue

and

#foreach ($item in $valueLists.<valuelistname>)

I want to show all selected items from a combox field in Servoy as past of my VR.

I tried using

#if ($!item.realValue.indexOf($field)>0)

as part of my foreach, but that does not work.

What would be the best way to handle this?

W.

P.S. full code for the foreach is:

#foreach ($item in $valueLists.[my_valuelist]) 
#if ($!item.realValue.indexOf($[my_field])>-1)
$item.displayValue
#end
#end

Not sure what you are asking…

A value list has no concept of ‘selection’…
There’s no selected value in the value list, this is something that happens in the dropdown (if it is set to multi select), and you will retrieve the selected values in a submit of a form, or eventually use jQuery to get a hold of the selected items. But this is something that happens in the browser, then to retrieve these in Servoy you need to submit.

Hi,

My mistake. I was talking about a combobox. Should have been a checkbox off course.

What I want to do is show the selected values from a checkbox field in an VR.

For example: In the DB there will be a value like “2\n3” when two items are checked in a checkbox field in Servoy. $valueLists.getDisplayValue does not work here because that only returns one value.

Hope this helps.

W.

application.getValueListDisplayValue('valueList', "2\n3") wouldn't work either.

You would have to do a split first:

var values = "2\n3".split("\s");
for (var i = 0; i < values.length; i++) {
	application.output(application.getValueListDisplayValue('valueList',values[i]));
}

So in a template you could do something like this:

#set($values = $value.split("\s")) 
#foreach($val in $values) 
    $valueLists.getDisplayValue("yourValueList", $val) 
#end

Hi Patrick,

Thanks for the respons. This was actually my first try, but using “\n” in place of “\s”. Both are wrong as it turns out.

This is the working code:

#set($values = $value.split("
"))
#foreach($val in $values)
    $valueLists.getDisplayValue("yourValueList", $val)
#end

Looks like Velocity translates newlines into
before rendering.

Thanks anyway. You pointed me in the right direction.