Velocity report - multi select

Questions and answers on developing, deploying and using plugins and JavaBeans

Velocity report - multi select

Postby wouter » Thu Sep 12, 2013 1:36 pm

Hi,

I am looking for the best way to incorporate values from a combobox in an Velocity template. I know of the :
Code: Select all
$valueLists.getDisplayValue


and

Code: Select all
#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

Code: Select all
#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:

Code: Select all
#foreach ($item in $valueLists.[my_valuelist])
#if ($!item.realValue.indexOf($[my_field])>-1)
$item.displayValue
#end
#end
User avatar
wouter
 
Posts: 19
Joined: Mon Jul 23, 2012 1:17 pm

Re: Velocity report - multi select

Postby ptalbot » Thu Sep 12, 2013 5:02 pm

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Velocity report - multi select

Postby wouter » Tue Sep 17, 2013 10:39 am

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.
User avatar
wouter
 
Posts: 19
Joined: Mon Jul 23, 2012 1:17 pm

Re: Velocity report - multi select

Postby ptalbot » Tue Sep 17, 2013 5:07 pm

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


You would have to do a split first:
Code: Select all
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:
Code: Select all
#set($values = $value.split("\s"))
#foreach($val in $values)
    $valueLists.getDisplayValue("yourValueList", $val)
#end
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Velocity report - multi select

Postby wouter » Wed Sep 18, 2013 12:49 pm

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:

Code: Select all
#set($values = $value.split("<br/>"))
#foreach($val in $values)
    $valueLists.getDisplayValue("yourValueList", $val)
#end


Looks like Velocity translates newlines into <br/> before rendering.

Thanks anyway. You pointed me in the right direction.
User avatar
wouter
 
Posts: 19
Joined: Mon Jul 23, 2012 1:17 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 25 guests

cron