use of com.servoy.j2db.server.ngclient.DataAdapterList in project servoy-client by Servoy.
the class PersistFieldInstanceTest method testTabPanelWithTabs.
@Test
public void testTabPanelWithTabs() throws RepositoryException {
Form form = solution.getForm("test");
Assert.assertNotNull(form);
Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
tabForm.setNavigatorID(-1);
DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(tabForm, client));
TabPanel tabpanel = form.createNewTabPanel("tabpanel");
tabpanel.createNewTab("tab1", null, tabForm);
tabpanel.createNewTab("tab2", null, tabForm);
List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
Assert.assertEquals(1, formElements.size());
WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
List<Map<String, Object>> tabs = (List) wc.getProperty("tabs");
Assert.assertEquals(2, tabs.size());
Map<String, Object> map = tabs.get(1);
Assert.assertSame(tabForm.getName(), map.get("containsFormId"));
}
use of com.servoy.j2db.server.ngclient.DataAdapterList in project servoy-client by Servoy.
the class PersistFieldInstanceTest method testSettingTextOfTabInTabpanel.
@Test
public void testSettingTextOfTabInTabpanel() throws RepositoryException, JSONException {
Form form = solution.getForm("test");
Assert.assertNotNull(form);
DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
tabForm.setNavigatorID(-1);
TabPanel tabpanel = form.createNewTabPanel("tabpanel");
tabpanel.createNewTab("tab1", null, tabForm);
tabpanel.createNewTab("tab2", null, tabForm);
List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
Assert.assertEquals(1, formElements.size());
WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
TypedData<Map<String, Object>> changes = wc.getAndClearChanges();
Assert.assertEquals(0, changes.content.size());
List<Map<String, Object>> tabs = (List) wc.getProperty("tabs");
Assert.assertEquals(2, tabs.size());
Map<String, Object> map = tabs.get(0);
map.put("text", new BasicTagStringTypeSabloValue("a test", null));
changes = wc.getAndClearChanges();
Assert.assertEquals(1, changes.content.size());
String json = JSONUtils.writeChangesWithConversions(changes.content, changes.contentType, null);
JSONAssert.assertEquals("{\"tabs\":{\"vEr\":1,\"g\":[{\"op\":[0,0,0],\"d\":[{\"rt\":\"servoydefault-tabpanel.tab\",\"vEr\":1,\"u\":[{\"k\":\"text\",\"v\":\"a test\"}]}],\"svy_types\":{\"0\":\"JSON_obj\"}}]},\"svy_types\":{\"tabs\":\"JSON_arr\"}}", json, true);
}
use of com.servoy.j2db.server.ngclient.DataAdapterList in project servoy-client by Servoy.
the class TagStringPropertyType method createNewTagStringTypeSabloValue.
protected BasicTagStringTypeSabloValue createNewTagStringTypeSabloValue(String designValue, DataAdapterList dataAdapterList, boolean tagParsingAllowed, boolean htmlParsingAllowed, PropertyDescription propertyDescription, WebFormComponent component, INGApplication application, boolean basedOnFormElementValue) {
BasicTagStringTypeSabloValue sabloValue;
TagStringConfig config = (TagStringConfig) propertyDescription.getConfig();
// this setting is decided at design/form-element time and won't change even if the value gets changed from rhino
boolean wouldLikeToParseTags = component == null ? false : wouldLikeToParseTags(config, component.getFormElement());
// if "wouldLikeToParseTags && !config.useParsedValueInRhino()" is true, we will never have a null previous value so we can still reach DAL
// the "&& !config.useParsedValueInRhino()" is an optimization; because if config.useParsedValueInRhino() is true, then no new value set from Rhino or scripting will be able to handle tags any more - so there's no need to hang on to DAL (if this changes, you can remove this check)
boolean needsToKeepDAL = (wouldLikeToParseTags && !config.useParsedValueInRhino());
DataAdapterList dal = (needsToKeepDAL ? dataAdapterList : null);
String newDesignValue = designValue != null && designValue.startsWith("i18n:") ? application.getI18NMessage(designValue.toString().substring(5)) : designValue;
if (newDesignValue == null) {
sabloValue = needsToKeepDAL ? new BasicTagStringTypeSabloValue(null, dal) : null;
} else if (// tagParsingAllowed is a security feature so that browsers cannot change tagStrings to something that is then able to show random server-side data
tagParsingAllowed && wouldLikeToParseTags && newDesignValue.contains("%%")) {
// data links are required; register them to DAL; normally DAL can't be null here
if (designValue != newDesignValue || designValue.contains("%%i18n:")) {
sabloValue = new I18NTagStringTypeSabloValue(newDesignValue, dal, component.getDataConverterContext(), propertyDescription, component.getFormElement(), designValue);
} else {
sabloValue = new TagStringTypeSabloValue(newDesignValue, dal, component.getDataConverterContext(), propertyDescription, component.getFormElement());
}
} else // just some static string
{
String staticValue = newDesignValue;
if (// htmlParsingAllowed is a security feature so that browsers cannot change tagStrings to something that is then able to execute random server-side javascript
htmlParsingAllowed && HtmlUtils.startsWithHtml(staticValue)) {
staticValue = HTMLTagsConverter.convert(staticValue, component.getDataConverterContext(), false);
}
// no data links required
if (designValue != newDesignValue || designValue.contains("%%i18n:")) {
sabloValue = new BasicI18NTagStringTypeSabloValue(staticValue, dal, designValue);
} else {
sabloValue = new BasicTagStringTypeSabloValue(staticValue, dal);
}
}
return sabloValue;
}
use of com.servoy.j2db.server.ngclient.DataAdapterList in project servoy-client by Servoy.
the class TagStringPropertyType method toSabloComponentValue.
@Override
public BasicTagStringTypeSabloValue toSabloComponentValue(Object rhinoValue, BasicTagStringTypeSabloValue previousComponentValue, PropertyDescription pd, IWebObjectContext componentOrService) {
if (rhinoValue != null && !RhinoConversion.isUndefinedOrNotFound(rhinoValue)) {
// this code can interpret the new value as a static one or a a tag-aware one depending on the property's config: USE_PARSED_VALUE_IN_RHINO_CONFIG_OPT
String newDesignValue = rhinoValue instanceof String ? (String) rhinoValue : rhinoValue.toString();
DataAdapterList dal = previousComponentValue != null ? previousComponentValue.getDataAdapterList() : null;
if (dal == null && componentOrService != null && componentOrService.getUnderlyingWebObject() instanceof WebFormComponent) {
dal = (DataAdapterList) ((WebFormComponent) componentOrService.getUnderlyingWebObject()).getDataAdapterList();
}
return createNewTagStringTypeSabloValue(newDesignValue, dal, !((TagStringConfig) pd.getConfig()).useParsedValueInRhino(), true, pd, componentOrService.getUnderlyingWebObject() instanceof WebFormComponent ? ((WebFormComponent) componentOrService.getUnderlyingWebObject()) : null, ((IContextProvider) componentOrService.getUnderlyingWebObject()).getDataConverterContext().getApplication(), false);
}
return null;
}
use of com.servoy.j2db.server.ngclient.DataAdapterList in project servoy-client by Servoy.
the class PersistFieldInstanceTest method testCustomComponentWithFormProperty.
@Test
public void testCustomComponentWithFormProperty() throws RepositoryException, JSONException {
// TODO this should become a test on form uuid in the inner html/bean xml instead of the form name..
Form form = solution.getForm("test");
Assert.assertNotNull(form);
DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
// as client's "inDesigner" == true we will generate an error bean because legacy Bean usage for custom web components with custom object/array types is depreacated and not fully working (in designer at least)
// so we will check that it generates an error bean (that means no props are set)
// TODO maybe this can be uncommented after https://support.servoy.com/browse/SVY-9459 is done
// Bean bean = form.createNewBean("mycustombean", "my-component");
// bean.setInnerHTML("{atype:{name:'name',form:'tabform'}}");
List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
// Assert.assertEquals(1, formElements.size());
// WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null);
@SuppressWarnings("unchecked") WebComponent // form.removeChild(bean);
webComponent = form.createNewWebComponent("mycustombean", "my-component");
webComponent.setProperty("atype", new ServoyJSONObject("{name:'name',form:'tabform'}", false));
formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
Assert.assertEquals(1, formElements.size());
WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
Map<String, Object> type = (Map<String, Object>) wc.getProperty("atype");
Assert.assertEquals("name", type.get("name"));
Assert.assertEquals("tabform", type.get("form"));
Assert.assertEquals(0, wc.getAndClearChanges().content.size());
TypedData<Map<String, Object>> props = wc.getProperties();
String json = JSONUtils.writeDataWithConversions(props.content, props.contentType, null);
JSONAssert.assertEquals("{\"atype\":{\"rt\":\"my-component.mytype\",\"vEr\":2,\"v\":{\"form\":\"tabform\",\"name\":\"name\"}},\"svyMarkupId\":\"sf331d64ddc0c17747371b7740e3e3447\",\"svy_types\":{\"atype\":\"JSON_obj\"}}", json, true);
}
Aggregations