After reading the knowledge base article titled "Obtain data from external database"

I followed the instructions (added the select box and chose beanshell binder) and tried to populate the dropdown list with a FormRowSet object populated with FormRow objects using this code:

testscript.bsh
import org.joget.apps.form.model.*;

public FormRowSet test() {
	FormRowSet f = new FormRowSet();
	f.setMultiRow(true);
	FormRow r = new FormRow();
	FormRow rr = new FormRow();
	r.put("test1","tester1");
	rr.put("test2","tester2");
	f.add(r);
	f.add(rr);
	return f;
}

return test();

The code gets executed when I go to the preview pane, but when it renders I get a bunch of json and not the drop down in the form I'm expecting. In the log file I see this error:

error.out
Oct 10, 2011 3:51:13 PM org.joget.apps.form.service.FormService previewElement

SEVERE: Error generating element html
java.util.NoSuchElementException: Hashtable Enumerator
        at java.util.Hashtable$Enumerator.nextElement(Hashtable.java:1021)
        at java.util.Hashtable$Enumerator.next(Hashtable.java:1032)
        at org.joget.apps.form.service.FormUtil.getElementPropertyOptions(FormUtil.java:741)
        at org.joget.apps.form.lib.SelectBox.getOptionMap(SelectBox.java:38)
        at org.joget.apps.form.lib.SelectBox.renderTemplate(SelectBox.java:81)
        at org.joget.apps.form.model.Element.render(Element.java:167)
        at org.joget.apps.form.service.FormService.generateElementDesignerHtml(FormService.java:123)
        at org.joget.apps.form.service.FormService.previewElement(FormService.java:54)
        at org.joget.apps.form.service.FormService.previewElement(FormService.java:35)
        at org.joget.apps.app.controller.FormBuilderWebController.previewElement(FormBuilderWebController.java:118)

Another odd thing. When I modify the code portion to only add a single FormRow to the FormRowSet (only call f.add(r) and comment out f.add(rr)) it seems to work. The preview shows my form with a single item in the drop down list.

So. My question is what am I doing wrong and how do I populate the drop down with multiple items from beanshell?

Thanks,

Andrew

  • No labels

4 Comments

  1. This is with the BETA2 release of v3 if that makes a difference.

  2. Hi Andrew,

    The correct way to doing it is as below:

    import org.joget.apps.form.model.*;
    import org.joget.apps.form.service.*;
    
    public FormRowSet test() {
    	FormRowSet f = new FormRowSet();
    	f.setMultiRow(true);
    
    	FormRow r1 = new FormRow();
    	r1.put(FormUtil.PROPERTY_VALUE, "test1");
    	r1.put(FormUtil.PROPERTY_LABEL, "tester1");
    	f.add(r1);
    
    	FormRow r2 = new FormRow();
    	r2.put(FormUtil.PROPERTY_VALUE, "test2");
    	r2.put(FormUtil.PROPERTY_LABEL, "tester2");
    	f.add(r2);
    
    	return f;
    }
    
    return test();

    Hope it's help.

    Regards,

    Owen

    1. That is exactly what I needed.  Thank you!  

  3. thanks too. really help.