Search in sources :

Example 1 with JSONWrapperList

use of com.servoy.j2db.util.JSONWrapperList in project servoy-client by Servoy.

the class ValuelistPropTest method valueListAttachDetach.

@Test
public void valueListAttachDetach() throws JSONException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    // (SVY-12336)
    // assign a foundset and a column with foundset linked dp and valuelist linked to that dp; then set foundset to null, clear columns and set back all this; no exception should happen
    Context cx = Context.enter();
    try {
        cx.evaluateString(form.getFormScope(), "elements.myCustomComponent.myFoundset = foundset;" + "elements.myCustomComponent.columns = [{ myDataprovider: 'test1', myValuelist: 'myVl1' }];", "a", 1, null);
        String changes = NGUtils.formChangesToString(((Container) form.getFormUI()), FullValueToJSONConverter.INSTANCE);
        JSONObject changesJSON = new JSONObject(changes);
        JSONObject col0JSON = changesJSON.getJSONObject("changes").getJSONObject("myCustomComponent").getJSONObject("columns").getJSONArray("v").getJSONObject(0).getJSONObject("v");
        Assert.assertArrayEquals("data should get sent to client", new String[] { "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10", "value11", "value12", "value13", "value14", "value15", "value16", "value17", "value18" }, new JSONWrapperList(col0JSON.getJSONObject("myDataprovider").getJSONArray("vp")).toArray());
        Assert.assertEquals("valuelist should get sent to client", 4, col0JSON.getJSONObject("myValuelist").getJSONArray("values").length());
        // detach valuelist in column + change foundset prop. value - detach should have cleared registered property change listener for foundset and changing the foundset would result in a NPE if those listeners were still executed for disposed valuelist prop.
        cx.evaluateString(form.getFormScope(), "elements.myCustomComponent.columns = [];" + "elements.myCustomComponent.myFoundset = databaseManager.getFoundSet(foundset.getDataSource());" + "elements.myCustomComponent.myFoundset.foundset.loadAllRecords();" + "elements.myCustomComponent.columns = [{ myDataprovider: 'test2', myValuelist: 'myVl2' }];", "a", 1, null);
        changes = NGUtils.formChangesToString(((Container) form.getFormUI()), FullValueToJSONConverter.INSTANCE);
        changesJSON = new JSONObject(changes);
        col0JSON = changesJSON.getJSONObject("changes").getJSONObject("myCustomComponent").getJSONObject("columns").getJSONArray("v").getJSONObject(0).getJSONObject("v");
        Assert.assertArrayEquals("data should get sent to client", new String[] { "valueA", "valueB", "valueC", "valueD", "valueE", "valueF", "valueG", "valueH", "valueI", "valueJ", "valueK", "valueL", "valueM", "valueN", "valueO", "valueP", "valueQ", "valueR" }, new JSONWrapperList(col0JSON.getJSONObject("myDataprovider").getJSONArray("vp")).toArray());
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) Container(org.sablo.Container) JSONObject(org.json.JSONObject) JSONWrapperList(com.servoy.j2db.util.JSONWrapperList) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Aggregations

IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)1 JSONWrapperList (com.servoy.j2db.util.JSONWrapperList)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1 Context (org.mozilla.javascript.Context)1 Container (org.sablo.Container)1