use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.
the class JSForm method removeVariableFromScopes.
private void removeVariableFromScopes(ScriptVariable var) {
List<IFormController> controllers = application.getFormManager().getCachedFormControllers(getForm());
for (IFormController formController : controllers) {
FormScope formScope = formController.getFormScope();
formScope.updateProviderswithCopy(getForm(), getForm());
formScope.remove(var);
}
}
use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.
the class JSForm method addVariableToScopes.
private void addVariableToScopes(ScriptVariable var) {
List<IFormController> controllers = application.getFormManager().getCachedFormControllers(getForm());
for (IFormController formController : controllers) {
FormScope formScope = formController.getFormScope();
formScope.put(var, true);
}
}
use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.
the class RuntimeWebComponentTest method arrayPropDirectAccess.
@Test
public void arrayPropDirectAccess() throws Exception {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("testForm");
Assert.assertNotNull(form);
FormScope formScope = form.getFormScope();
Context cx = Context.enter();
try {
// CHECK INITIAL DEFAULT VALUE FROM SPEC
RhinoMapOrArrayWrapper stringArrayProp = (RhinoMapOrArrayWrapper) cx.evaluateString(formScope, "elements.testComponent.stringArray", "Evaluation Test Script", 1, null);
Assert.assertArrayEquals(new String[] { "a", "b", "c" }, ((List<String>) stringArrayProp.getWrappedValue()).toArray());
// same check as above but directly inside Rhino
Boolean testResult = (Boolean) cx.evaluateString(formScope, "(elements.testComponent.stringArray.length === 3) && elements.testComponent.stringArray.every(function(this_i, i) { return this_i == [\"a\", \"b\", \"c\"][i] } ) ", "Evaluation Test Script", 1, null);
Assert.assertTrue(testResult.booleanValue());
// ADD ELEMENT TO EXISTING VALUE
cx.evaluateString(formScope, "elements.testComponent.getStringArray().push(\"d\") ", "Evaluation Test Script", 1, null);
// CHECK CHANGED VALUE
stringArrayProp = (RhinoMapOrArrayWrapper) cx.evaluateString(formScope, "elements.testComponent.stringArray", "Evaluation Test Script", 1, null);
Assert.assertArrayEquals(new String[] { "a", "b", "c", "d" }, ((List<String>) stringArrayProp.getWrappedValue()).toArray());
// same check as above but directly inside Rhino
testResult = (Boolean) cx.evaluateString(formScope, "(elements.testComponent.stringArray.length === 4) && elements.testComponent.stringArray.every(function(this_i, i) { return this_i == [\"a\", \"b\", \"c\", \"d\"][i] } ) ", "Evaluation Test Script", 1, null);
Assert.assertTrue(testResult.booleanValue());
// ASSIGN DIFFERENT ARRAY BY REF TO PROPERTY
cx.evaluateString(formScope, "elements.testComponent.stringArray = ['1', '2', '3']", "Evaluation Test Script", 1, null);
// CHECK NEW VALUE
stringArrayProp = (RhinoMapOrArrayWrapper) cx.evaluateString(formScope, "elements.testComponent.stringArray", "Evaluation Test Script", 1, null);
Assert.assertArrayEquals(new String[] { "1", "2", "3" }, ((List<String>) stringArrayProp.getWrappedValue()).toArray());
// same check as above but directly inside Rhino
testResult = (Boolean) cx.evaluateString(formScope, "(elements.testComponent.stringArray.length === 3) && elements.testComponent.stringArray.every(function(this_i, i) { return this_i == [\"1\", \"2\", \"3\"][i] } ) ", "Evaluation Test Script", 1, null);
Assert.assertTrue(testResult.booleanValue());
} finally {
Context.exit();
}
}
use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.
the class RuntimeWebComponentTest method arrayPropAccessThroughGetterAndSetter.
@Test
public void arrayPropAccessThroughGetterAndSetter() throws Exception {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("testForm");
Assert.assertNotNull(form);
FormScope formScope = form.getFormScope();
Context cx = Context.enter();
try {
// CHECK INITIAL DEFAULT VALUE FROM SPEC
RhinoMapOrArrayWrapper stringArrayProp = (RhinoMapOrArrayWrapper) cx.evaluateString(formScope, "elements.testComponent.getStringArray()", "Evaluation Test Script", 1, // this used to fail with an exception when RuntimeLegacyComponent gave null scope in getter code
null);
Assert.assertArrayEquals(new String[] { "a", "b", "c" }, ((List<String>) stringArrayProp.getWrappedValue()).toArray());
// same check as above but directly inside Rhino
Boolean testResult = (Boolean) cx.evaluateString(formScope, "(elements.testComponent.getStringArray().length === 3) && elements.testComponent.getStringArray().every(function(this_i, i) { return this_i == [\"a\", \"b\", \"c\"][i] } ) ", "Evaluation Test Script", 1, null);
Assert.assertTrue(testResult.booleanValue());
// ADD ELEMENT TO EXISTING VALUE
cx.evaluateString(formScope, "elements.testComponent.getStringArray().push(\"d\") ", "Evaluation Test Script", 1, null);
// CHECK CHANGED VALUE
stringArrayProp = (RhinoMapOrArrayWrapper) cx.evaluateString(formScope, "elements.testComponent.getStringArray()", "Evaluation Test Script", 1, null);
Assert.assertArrayEquals(new String[] { "a", "b", "c", "d" }, ((List<String>) stringArrayProp.getWrappedValue()).toArray());
// same check as above but directly inside Rhino
testResult = (Boolean) cx.evaluateString(formScope, "(elements.testComponent.getStringArray().length === 4) && elements.testComponent.getStringArray().every(function(this_i, i) { return this_i == [\"a\", \"b\", \"c\", \"d\"][i] } ) ", "Evaluation Test Script", 1, null);
Assert.assertTrue(testResult.booleanValue());
// ASSIGN DIFFERENT ARRAY BY REF TO PROPERTY
cx.evaluateString(formScope, "elements.testComponent.setStringArray(['1', '2', '3'])", "Evaluation Test Script", 1, null);
// CHECK NEW VALUE
stringArrayProp = (RhinoMapOrArrayWrapper) cx.evaluateString(formScope, "elements.testComponent.getStringArray()", "Evaluation Test Script", 1, null);
Assert.assertArrayEquals(new String[] { "1", "2", "3" }, ((List<String>) stringArrayProp.getWrappedValue()).toArray());
// same check as above but directly inside Rhino
testResult = (Boolean) cx.evaluateString(formScope, "(elements.testComponent.getStringArray().length === 3) && elements.testComponent.getStringArray().every(function(this_i, i) { return this_i == [\"1\", \"2\", \"3\"][i] } ) ", "Evaluation Test Script", 1, null);
Assert.assertTrue(testResult.booleanValue());
} finally {
Context.exit();
}
}
use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.
the class BasicFormController method initForJSUsage.
/**
* Initialize this FormController(or related classes/methods) to be used in javascript
*/
public synchronized JSForm initForJSUsage(CreationalPrototype creationalPrototype) {
if (formScope == null) {
try {
// make scope for state delegation via prototype mechanism
List<Form> forms = application.getFlattenedSolution().getFormHierarchy(form);
List<ISupportScriptProviders> scriptProviders = new ArrayList<ISupportScriptProviders>();
for (Form frm : forms) {
scriptProviders.add(new RuntimeSupportScriptProviders(application, frm));
}
formScope = new FormScope(this, scriptProviders.toArray(new ISupportScriptProviders[scriptProviders.size()]));
if (formModel != null) {
ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
// $NON-NLS-1$
formScope.putWithoutFireChange("foundset", formModel);
}
// create JS place holder for this object
scriptableForm = new BasicFormController.JSForm(this);
// set parent scope
NativeJavaObject formObject = new NativeJavaObject(formScope, scriptableForm, ScriptObjectRegistry.getJavaMembers(FormController.JSForm.class, formScope));
// $NON-NLS-1$
formScope.putWithoutFireChange("controller", formObject);
// register the place holder 'scriptableForm' in CreationalPrototype scope
creationalPrototype.setLocked(false);
// $NON-NLS-1$
creationalPrototype.put(((Integer) creationalPrototype.get("length", creationalPrototype)).intValue(), creationalPrototype, formScope);
creationalPrototype.put(getName(), creationalPrototype, formScope);
creationalPrototype.setLocked(true);
formScope.createVars();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.initFormScope") + ": " + getName(), ex);
return null;
}
}
return scriptableForm;
}
Aggregations