popup menu based on a valuelist

I’m trying to create a method that shows a valuelist when I click on a button. (I do not want a combobox type of valuelist, just a button that shows a menu containing the values from a certain valuelist). Up till my method is:

var vdataset = application.getValueListItems('find')
var menu = new Array()
for (var i = 1 ; i <= vdataset.getMaxRowIndex() ; i++ )
	{
	menu[i-1] = plugins.popupmenu.createMenuItem((vdataset.getvalue*i, 1), myMethod),
	menu[i-1].setMethodArguments (i+ 'arg1','arg2');
	}

but when I attach the method to a button and click on it, nothing happens. Does anybody know what I do wrong?

var vdataset = application.getValueListItems('find')
var menu = new Array()
for (var i = 1 ; i <= vdataset.getMaxRowIndex() ; i++ )
	{
	menu[i-1] = plugins.popupmenu.createMenuItem((vdataset.getvalue*i, 1), myMethod),
	menu[i-1].setMethodArguments (i+ 'arg1','arg2');
	}

Looks like your issue is in vdataset.getvalue*i, 1).

  • should be (
    And getvalue() is not a known function of a dataset, getValue() is (caps sensitive).
    Also you end that line with a comma instead of a semi-colon.

So your code should look like this

var vdataset = application.getValueListItems('find')
var menu = new Array()
for (var i = 1 ; i <= vdataset.getMaxRowIndex() ; i++ )
	{
	menu[i-1] = plugins.popupmenu.createMenuItem((vdataset.getValue(i, 1), myMethod);
	menu[i-1].setMethodArguments (i+ 'arg1','arg2');
	}

Hope this helps.

Wow, that was really very stupid of me.
However, I tried the method with your advise and it still won’t show up. It now reads:

var vdataset = application.getValueListItems('find')
var menu = new Array()
for (var i = 1 ; i <= vdataset.getMaxRowIndex() ; i++ )
   {
   menu[i-1] = plugins.popupmenu.createMenuItem(vdataset.getValue(i, 1), myMethod);
   menu[i-1].setMethodArguments (i+ 'arg1','arg2');
   }

When I put on the debugger, it says:

menu [com.servoy.extensions.plugins.popupmenu.swing.ScriptableJMenuItem[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=apple.laf.AquaMenuBorder@b4b8ed,
flags=264,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,
bottom=0,right=0],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=]]

Ah yes, you do need to actually show the menu.
Make sure your button has a name property set.

Add the following to your method:

var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{
	plugins.popupmenu.showPopupMenu(elem, menu);
	//or you can set the coordinates : plugins.popupmenu.showPopupMenu(10, 10, menu);
}

Hope this helps.

Thank you so much!

ROCLASI:
Ah yes, you do need to actually show the menu.
Make sure your button has a name property set.

Add the following to your method:

var elem = elements[application.getMethodTriggerElementName()]

if (elem != null)
{
plugins.popupmenu.showPopupMenu(elem, menu);
//or you can set the coordinates : plugins.popupmenu.showPopupMenu(10, 10, menu);
}




Hope this helps.