Search in sources :

Example 1 with DataAdapterList

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"));
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ValueList(com.servoy.j2db.persistence.ValueList) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with DataAdapterList

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);
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) BasicTagStringTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.BasicTagStringTypeSabloValue) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ValueList(com.servoy.j2db.persistence.ValueList) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with DataAdapterList

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;
}
Also used : DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList)

Example 4 with DataAdapterList

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;
}
Also used : IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList)

Example 5 with DataAdapterList

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);
}
Also used : Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) WebComponent(com.servoy.j2db.persistence.WebComponent) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)6 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)5 Form (com.servoy.j2db.persistence.Form)4 FormElement (com.servoy.j2db.server.ngclient.FormElement)4 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)4 ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 Dimension (java.awt.Dimension)3 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)2 IValueList (com.servoy.j2db.dataprocessing.IValueList)2 TabPanel (com.servoy.j2db.persistence.TabPanel)2 ValueList (com.servoy.j2db.persistence.ValueList)2 WebComponent (com.servoy.j2db.persistence.WebComponent)2 List (java.util.List)2 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)1 BasicTagStringTypeSabloValue (com.servoy.j2db.server.ngclient.property.types.BasicTagStringTypeSabloValue)1 BrowserConverterContext (org.sablo.specification.property.BrowserConverterContext)1