Search in sources :

Example 6 with IRecord

use of com.servoy.j2db.dataprocessing.IRecord in project servoy-client by Servoy.

the class WebClientsApplication method init.

/**
 * @see wicket.protocol.http.WebApplication#init()
 */
@Override
protected void init() {
    // TODO this is a workaround to allow mobile test client that only starts Tomcat not to give exceptions (please remove if mobile test client initialises a full app. server in the future)
    if (ApplicationServerRegistry.get() == null)
        return;
    getResourceSettings().setResourceWatcher(new ServoyModificationWatcher(Duration.seconds(5)));
    // getResourceSettings().setResourcePollFrequency(Duration.seconds(5));
    getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true);
    getResourceSettings().setDefaultCacheDuration((int) Duration.days(365).seconds());
    getMarkupSettings().setCompressWhitespace(true);
    getMarkupSettings().setMarkupCache(new ServoyMarkupCache(this));
    // getMarkupSettings().setStripWicketTags(true);
    getResourceSettings().setResourceStreamLocator(new ServoyResourceStreamLocator(this));
    getResourceSettings().setPackageResourceGuard(new ServoyPackageResourceGuard());
    // getResourceSettings().setResourceFinder(createResourceFinder());
    getResourceSettings().setThrowExceptionOnMissingResource(false);
    getApplicationSettings().setPageExpiredErrorPage(ServoyExpiredPage.class);
    getApplicationSettings().setClassResolver(new ServoyClassResolver());
    getSessionSettings().setMaxPageMaps(15);
    // getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
    getSecuritySettings().setCryptFactory(new CachingKeyInSessionSunJceCryptFactory());
    Settings settings = Settings.getInstance();
    // $NON-NLS-1$ //$NON-NLS-2$
    getDebugSettings().setOutputComponentPath(Utils.getAsBoolean(settings.getProperty("servoy.webclient.debug.wicketpath", "false")));
    if (// $NON-NLS-1$ //$NON-NLS-2$
    Utils.getAsBoolean(settings.getProperty("servoy.webclient.nice.urls", "false"))) {
        // $NON-NLS-1$
        mount(new HybridUrlCodingStrategy("/solutions", SolutionLoader.class));
        // $NON-NLS-1$
        mount(new HybridUrlCodingStrategy("/application", MainPage.class));
        mount(new // $NON-NLS-1$
        HybridUrlCodingStrategy(// $NON-NLS-1$
        "/ss", // $NON-NLS-1$
        SolutionLoader.class) {

            /**
             * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget)
             */
            @Override
            public boolean matches(IRequestTarget requestTarget) {
                return false;
            }
        });
    } else {
        // $NON-NLS-1$
        mountBookmarkablePage("/solutions", SolutionLoader.class);
        mount(new // $NON-NLS-1$
        BookmarkablePageRequestTargetUrlCodingStrategy(// $NON-NLS-1$
        "/ss", // $NON-NLS-1$
        SolutionLoader.class, // $NON-NLS-1$
        null) {

            /**
             * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget)
             */
            @Override
            public boolean matches(IRequestTarget requestTarget) {
                return false;
            }
        });
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    long maxSize = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false);
    if (maxSize > 0) {
        getApplicationSettings().setDefaultMaximumUploadSize(Bytes.kilobytes(maxSize));
    }
    // $NON-NLS-1$
    getSharedResources().putClassAlias(IApplication.class, "application");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(PageContributor.class, "pc");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(MaskBehavior.class, "mask");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(Application.class, "servoy");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(org.wicketstuff.calendar.markup.html.form.DatePicker.class, "datepicker");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(YUILoader.class, "yui");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(JQueryLoader.class, "jquery");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(TinyMCELoader.class, "tinymce");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(org.apache.wicket.markup.html.WicketEventReference.class, "wicketevent");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(org.apache.wicket.ajax.WicketAjaxReference.class, "wicketajax");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(MainPage.class, "servoyjs");
    // $NON-NLS-1$
    getSharedResources().putClassAlias(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class, "modalwindow");
    // $NON-NLS-1$
    PackageResource.bind(this, IApplication.class, "images/open_project.gif");
    // $NON-NLS-1$
    PackageResource.bind(this, IApplication.class, "images/save.gif");
    // $NON-NLS-1$//$NON-NLS-2$
    mountSharedResource("/formcss", "servoy/formcss");
    sharedMediaResource = new SharedMediaResource();
    // $NON-NLS-1$
    getSharedResources().add("media", sharedMediaResource);
    mount(new // $NON-NLS-1$ //$NON-NLS-2$
    SharedResourceRequestTargetUrlCodingStrategy(// $NON-NLS-1$ //$NON-NLS-2$
    "mediafolder", // $NON-NLS-1$ //$NON-NLS-2$
    "servoy/media") {

        @Override
        protected void appendParameters(AppendingStringBuffer url, Map<String, ?> parameters) {
            if (parameters != null && parameters.size() > 0) {
                // $NON-NLS-1$
                Object solutionName = parameters.get("s");
                if (solutionName != null)
                    appendPathParameter(url, null, solutionName.toString());
                // $NON-NLS-1$
                Object resourceId = parameters.get("id");
                if (resourceId != null)
                    appendPathParameter(url, null, resourceId.toString());
                StringBuilder queryParams = new StringBuilder();
                for (Entry<?, ?> entry1 : parameters.entrySet()) {
                    Object value = ((Entry<?, ?>) entry1).getValue();
                    if (value != null) {
                        Object key = ((Entry<?, ?>) entry1).getKey();
                        if (// $NON-NLS-1$ //$NON-NLS-2$
                        !"s".equals(key) && !"id".equals(key)) {
                            if (value instanceof String[]) {
                                String[] values = (String[]) value;
                                for (String value1 : values) {
                                    // $NON-NLS-1$
                                    if (queryParams.length() > 0)
                                        queryParams.append("&");
                                    // $NON-NLS-1$
                                    queryParams.append(key).append("=").append(value1);
                                }
                            } else {
                                // $NON-NLS-1$
                                if (queryParams.length() > 0)
                                    queryParams.append("&");
                                // $NON-NLS-1$
                                queryParams.append(key).append("=").append(value);
                            }
                        }
                    }
                }
                if (queryParams.length() > 0) {
                    // $NON-NLS-1$
                    url.append("?").append(queryParams);
                }
            }
        }

        @Override
        protected void appendPathParameter(AppendingStringBuffer url, String key, String value) {
            String escapedValue = value;
            // $NON-NLS-1$
            String[] values = escapedValue.split("/");
            if (values.length > 1) {
                StringBuilder sb = new StringBuilder(escapedValue.length());
                for (String str : values) {
                    sb.append(urlEncodePathComponent(str));
                    sb.append('/');
                }
                sb.setLength(sb.length() - 1);
                escapedValue = sb.toString();
            } else {
                escapedValue = urlEncodePathComponent(escapedValue);
            }
            if (!Strings.isEmpty(escapedValue)) {
                if (// $NON-NLS-1$
                !url.endsWith("/")) {
                    // $NON-NLS-1$
                    url.append("/");
                }
                // $NON-NLS-1$
                if (key != null)
                    url.append(urlEncodePathComponent(key)).append("/");
                url.append(escapedValue);
            }
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#decodeParameters(java.lang.String, java.util.Map)
			 */
        @Override
        protected ValueMap decodeParameters(String urlFragment, Map<String, ?> urlParameters) {
            ValueMap map = new ValueMap();
            // $NON-NLS-1$
            final String[] pairs = urlFragment.split("/");
            if (pairs.length > 1) {
                // $NON-NLS-1$
                map.add("s", pairs[1]);
                StringBuffer sb = new StringBuffer();
                for (int i = 2; i < pairs.length; i++) {
                    sb.append(pairs[i]);
                    // $NON-NLS-1$
                    sb.append("/");
                }
                sb.setLength(sb.length() - 1);
                // $NON-NLS-1$
                map.add("id", sb.toString());
            }
            if (urlParameters != null) {
                map.putAll(urlParameters);
            }
            return map;
        }
    });
    // $NON-NLS-1$
    getSharedResources().add("resources", new ServeResources());
    // $NON-NLS-1$
    getSharedResources().add("formcss", new FormCssResource(this));
    if (// $NON-NLS-1$
    settings.getProperty("servoy.webclient.error.page", null) != null) {
        getApplicationSettings().setInternalErrorPage(ServoyErrorPage.class);
    }
    if (// $NON-NLS-1$
    settings.getProperty("servoy.webclient.pageexpired.page", null) != null) {
        getApplicationSettings().setPageExpiredErrorPage(ServoyPageExpiredPage.class);
    }
    addPreComponentOnBeforeRenderListener(new IComponentOnBeforeRenderListener() {

        public void onBeforeRender(Component component) {
            if (component instanceof IServoyAwareBean) {
                IModel model = component.getInnermostModel();
                WebForm webForm = component.findParent(WebForm.class);
                if (model instanceof RecordItemModel && webForm != null) {
                    IRecord record = (IRecord) ((RecordItemModel) model).getObject();
                    FormScope fs = webForm.getController().getFormScope();
                    if (record != null && fs != null) {
                        ((IServoyAwareBean) component).setSelectedRecord(new ServoyBeanState(record, fs));
                    }
                }
            } else if (!(component.getParent() instanceof WebDataCompositeTextField)) {
                if (!component.isEnabled()) {
                    boolean hasOnRender = (component instanceof IFieldComponent && ((IFieldComponent) component).getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject()).getRenderEventExecutor().hasRenderCallback());
                    if (!hasOnRender) {
                        // onrender may change the enable state
                        return;
                    }
                }
                Component targetComponent = null;
                boolean hasFocus = false, hasBlur = false;
                if (component instanceof IFieldComponent && ((IFieldComponent) component).getEventExecutor() != null) {
                    if (component instanceof WebDataCompositeTextField && ((WebDataCompositeTextField) component).getDelegate() instanceof Component) {
                        targetComponent = (Component) ((WebDataCompositeTextField) component).getDelegate();
                    } else {
                        targetComponent = component;
                    }
                    if (component instanceof WebBaseSelectBox) {
                        Component[] cs = ((WebBaseSelectBox) component).getFocusChildren();
                        if (cs != null && cs.length == 1)
                            targetComponent = cs[0];
                    }
                    if (component instanceof WebDataHtmlArea)
                        hasFocus = true;
                    // always install a focus handler when in a table view to detect change of selectedIndex and test for record validation
                    if (((IFieldComponent) component).getEventExecutor().hasEnterCmds() || component.findParent(WebCellBasedView.class) != null || (((IFieldComponent) component).getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject()).getRenderEventExecutor().hasRenderCallback())) {
                        hasFocus = true;
                    }
                    // Always trigger event on focus lost:
                    // 1) check for new selected index, record validation may have failed preventing a index changed
                    // 2) prevent focus gained to be called when field validation failed
                    // 3) general ondata change
                    hasBlur = true;
                } else if (component instanceof WebBaseLabel) {
                    targetComponent = component;
                    hasFocus = true;
                }
                if (targetComponent != null) {
                    MainPage mainPage = targetComponent.findParent(MainPage.class);
                    if (mainPage.isUsingAjax()) {
                        AbstractAjaxBehavior eventCallback = mainPage.getPageContributor().getEventCallback();
                        if (eventCallback != null) {
                            String callback = eventCallback.getCallbackUrl().toString();
                            if (component instanceof WebDataRadioChoice || component instanceof WebDataCheckBoxChoice || component instanceof WebDataLookupField || component instanceof WebDataComboBox || component instanceof WebDataListBox || component instanceof WebDataHtmlArea || component instanceof WebDataCompositeTextField) {
                                // is updated via ServoyChoiceComponentUpdatingBehavior or ServoyFormComponentUpdatingBehavior, this is just for events
                                callback += "&nopostdata=true";
                            }
                            for (IBehavior behavior : targetComponent.getBehaviors()) {
                                if (behavior instanceof EventCallbackModifier) {
                                    targetComponent.remove(behavior);
                                }
                            }
                            if (hasFocus) {
                                StringBuilder js = new StringBuilder();
                                // $NON-NLS-1$ //$NON-NLS-2$
                                js.append("eventCallback(this,'focus','").append(callback).append("',event)");
                                // $NON-NLS-1$
                                targetComponent.add(new EventCallbackModifier("onfocus", true, new Model<String>(js.toString())));
                                // $NON-NLS-1$ //$NON-NLS-2$
                                targetComponent.add(new EventCallbackModifier("onmousedown", true, new Model<String>("focusMousedownCallback(event)")));
                            }
                            if (hasBlur) {
                                boolean blockRequest = false;
                                // if component has ondatachange, check for blockrequest
                                if (component instanceof ISupportEventExecutor && ((ISupportEventExecutor) component).getEventExecutor().hasChangeCmd()) {
                                    WebClientSession webClientSession = WebClientSession.get();
                                    blockRequest = webClientSession != null && webClientSession.blockRequest();
                                }
                                StringBuilder js = new StringBuilder();
                                // $NON-NLS-1$ //$NON-NLS-2$
                                js.append("postEventCallback(this,'blur','").append(callback).append("',event," + blockRequest + ")");
                                // $NON-NLS-1$
                                targetComponent.add(new EventCallbackModifier("onblur", true, new Model<String>(js.toString())));
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : ValueMap(org.apache.wicket.util.value.ValueMap) WebBaseSelectBox(com.servoy.j2db.server.headlessclient.dataui.WebBaseSelectBox) WebDataLookupField(com.servoy.j2db.server.headlessclient.dataui.WebDataLookupField) IRequestTarget(org.apache.wicket.IRequestTarget) Settings(com.servoy.j2db.util.Settings) IWiQuerySettings(org.odlabs.wiquery.core.commons.IWiQuerySettings) IRequestCycleSettings(org.apache.wicket.settings.IRequestCycleSettings) WiQuerySettings(org.odlabs.wiquery.core.commons.WiQuerySettings) WebDataCheckBoxChoice(com.servoy.j2db.server.headlessclient.dataui.WebDataCheckBoxChoice) WebBaseLabel(com.servoy.j2db.server.headlessclient.dataui.WebBaseLabel) WebDataCompositeTextField(com.servoy.j2db.server.headlessclient.dataui.WebDataCompositeTextField) IRecord(com.servoy.j2db.dataprocessing.IRecord) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) WebDataRadioChoice(com.servoy.j2db.server.headlessclient.dataui.WebDataRadioChoice) RecordItemModel(com.servoy.j2db.server.headlessclient.dataui.RecordItemModel) HybridUrlCodingStrategy(org.apache.wicket.request.target.coding.HybridUrlCodingStrategy) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) ISupportEventExecutor(com.servoy.j2db.ui.ISupportEventExecutor) FormScope(com.servoy.j2db.scripting.FormScope) IPageMapEntry(org.apache.wicket.session.pagemap.IPageMapEntry) Entry(java.util.Map.Entry) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) IBehavior(org.apache.wicket.behavior.IBehavior) WebDataComboBox(com.servoy.j2db.server.headlessclient.dataui.WebDataComboBox) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior) AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) IModel(org.apache.wicket.model.IModel) WebDataListBox(com.servoy.j2db.server.headlessclient.dataui.WebDataListBox) IComponentOnBeforeRenderListener(org.apache.wicket.application.IComponentOnBeforeRenderListener) AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) ServoyBeanState(com.servoy.j2db.component.ServoyBeanState) WebDataHtmlArea(com.servoy.j2db.server.headlessclient.dataui.WebDataHtmlArea) IModel(org.apache.wicket.model.IModel) RecordItemModel(com.servoy.j2db.server.headlessclient.dataui.RecordItemModel) Model(org.apache.wicket.model.Model) IFieldComponent(com.servoy.j2db.ui.IFieldComponent)

Example 7 with IRecord

use of com.servoy.j2db.dataprocessing.IRecord in project servoy-client by Servoy.

the class RecordItemModel method getValue.

/**
 * Gets the value for dataProviderID in the context of this record and the form determined using given component. The component is only used for getting the
 * form, otherwise it does not affect the returned value.
 *
 * @param component the component used to determine the form (in case of global or form variables).
 * @param dataProviderID the data provider id pointing to a data provider in the record, a form or a global variable.
 * @return the value.
 */
public Object getValue(Component component, String dataProviderID) {
    Object value = null;
    WebForm webForm = component.findParent(WebForm.class);
    if (webForm == null) {
        // component.toString() may cause stackoverflow here
        // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        Debug.error(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        "Component " + component.getClass() + " with dp: " + dataProviderID + "  already removed from its parent form.", new RuntimeException());
        return null;
    }
    FormScope fs = webForm.getController().getFormScope();
    IRecord record = (IRecord) RecordItemModel.this.getObject();
    if (ScopesUtils.isVariableScope(dataProviderID)) {
        value = webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().get(null, dataProviderID);
    } else if (record != null) {
        value = record.getValue(dataProviderID);
    }
    if (value == Scriptable.NOT_FOUND && fs != null && fs.has(dataProviderID, fs)) {
        value = fs.get(dataProviderID);
    }
    if (value instanceof DbIdentValue) {
        value = ((DbIdentValue) value).getPkValue();
    }
    if (value == Scriptable.NOT_FOUND) {
        value = null;
    } else if (!(record instanceof FindState)) {
        // use UI converter to convert from record value to UI value
        value = ComponentFormat.applyUIConverterToObject(component, value, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
    }
    return value;
}
Also used : FindState(com.servoy.j2db.dataprocessing.FindState) WebForm(com.servoy.j2db.server.headlessclient.WebForm) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) IRecord(com.servoy.j2db.dataprocessing.IRecord) FormScope(com.servoy.j2db.scripting.FormScope)

Example 8 with IRecord

use of com.servoy.j2db.dataprocessing.IRecord in project servoy-client by Servoy.

the class FoundsetTypeSabloValue method setDataAdapterListToSelectedRecord.

public void setDataAdapterListToSelectedRecord() {
    if (dataAdapterList != null) {
        if (foundset != null && foundset.getSize() > 0) {
            IRecord selectedRecord = foundset.getRecord(foundset.getSelectedIndex());
            dataAdapterList.setRecordQuietly(selectedRecord, true);
        } else {
            // make sure DAL is not listening to records that are no longer there in the foundset
            dataAdapterList.setRecordQuietly(null, true);
        }
    }
}
Also used : IRecord(com.servoy.j2db.dataprocessing.IRecord)

Example 9 with IRecord

use of com.servoy.j2db.dataprocessing.IRecord in project servoy-client by Servoy.

the class EventExecutor method executeEvent.

public Object executeEvent(WebComponent component, String eventType, int eventId, Object[] eventArgs) {
    Scriptable scope = null;
    Function f = null;
    Object[] newargs = eventArgs != null ? Arrays.copyOf(eventArgs, eventArgs.length) : null;
    if (eventId > 0) {
        ScriptMethod scriptMethod = formController.getApplication().getFlattenedSolution().getScriptMethod(eventId);
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof Form) {
                FormScope formScope = formController.getFormScope();
                f = formScope.getFunctionByName(scriptMethod.getName());
                if (f != null && f != Scriptable.NOT_FOUND) {
                    scope = formScope;
                }
            } else // is it a global method
            if (scriptMethod.getParent() instanceof Solution) {
                scope = formController.getApplication().getScriptEngine().getScopesScope().getGlobalScope(scriptMethod.getScopeName());
                if (scope != null) {
                    f = ((GlobalScope) scope).getFunctionByName(scriptMethod.getName());
                }
            } else // very like a foundset/entity method
            {
                Scriptable foundsetScope = null;
                if (component instanceof WebFormComponent) {
                    IRecord rec = ((WebFormComponent) component).getDataAdapterList().getRecord();
                    if (rec != null) {
                        foundsetScope = (Scriptable) rec.getParentFoundSet();
                    }
                }
                if (foundsetScope == null)
                    foundsetScope = (Scriptable) formController.getFormModel();
                if (foundsetScope != null) {
                    // TODO ViewFoundSets should be come a scriptable if they have foundset methods..
                    scope = foundsetScope;
                    Object scopeMethod = scope.getPrototype().get(scriptMethod.getName(), scope);
                    if (scopeMethod instanceof Function)
                        f = (Function) scopeMethod;
                }
            }
            if (f == null) {
                Debug.error(// $NON-NLS-1$ //$NON-NLS-2$
                "No function found for " + scriptMethod + " when trying to execute the event " + eventType + '(' + eventId + ") of component: " + component, // $NON-NLS-1$
                new RuntimeException());
                return null;
            }
        } else {
            Debug.warn("Couldn't find the ScriptMethod for event: " + eventType + " with event id: " + eventId + " to execute for component " + component);
        }
    }
    // $NON-NLS-1$
    if (formController.isInFindMode() && !Utils.getAsBoolean(f.get("_AllowToRunInFind_", f)))
        return null;
    if (newargs != null) {
        for (int i = 0; i < newargs.length; i++) {
            if (newargs[i] instanceof JSONObject && "event".equals(((JSONObject) newargs[i]).optString("type"))) {
                JSONObject json = (JSONObject) newargs[i];
                JSEvent event = new JSEvent();
                JSEventType.fillJSEvent(event, json, component, formController);
                event.setType(getEventType(eventType));
                event.setName(RepositoryHelper.getDisplayName(eventType, BaseComponent.class));
                newargs[i] = event;
            } else {
                // try to convert the received arguments
                WebObjectFunctionDefinition propertyDesc = component.getSpecification().getHandler(eventType);
                List<PropertyDescription> parameters = propertyDesc.getParameters();
                if (i < parameters.size()) {
                    PropertyDescription parameterPropertyDescription = parameters.get(i);
                    ValueReference<Boolean> returnValueAdjustedIncommingValueForIndex = new ValueReference<Boolean>(Boolean.FALSE);
                    newargs[i] = NGConversions.INSTANCE.convertSabloComponentToRhinoValue(JSONUtils.fromJSON(null, newargs[i], parameterPropertyDescription, new BrowserConverterContext(component, PushToServerEnum.allow), returnValueAdjustedIncommingValueForIndex), parameterPropertyDescription, component, scope);
                }
            // TODO? if in propertyDesc.getAsPropertyDescription().getConfig() we have  "type":"${dataproviderType}" and parameterPropertyDescription.getType() is Object
            // then get the type from the dataprovider and try to convert the json to that type instead of simply object
            }
        }
    }
    if (component instanceof WebFormComponent) {
        IPersist persist = ((WebFormComponent) component).getFormElement().getPersistIfAvailable();
        if (persist instanceof AbstractBase) {
            List<Object> instanceMethodArguments = ((AbstractBase) persist).getFlattenedMethodArguments(eventType);
            if (instanceMethodArguments != null && instanceMethodArguments.size() > 0) {
                // create entries for the instanceMethodArguments if they are more then callback arguments
                if (instanceMethodArguments.size() > newargs.length) {
                    newargs = Utils.arrayJoin(newargs, new Object[instanceMethodArguments.size() - newargs.length]);
                }
                // use instanceMethodArguments if not null, else just use the callback argument
                for (int i = 0; i < instanceMethodArguments.size(); i++) {
                    Object value = instanceMethodArguments.get(i);
                    if (value != null && value != JSONObject.NULL) {
                        newargs[i] = Utils.parseJSExpression(value);
                    }
                }
            }
        }
    }
    try {
        formController.getApplication().updateLastAccessed();
        return formController.getApplication().getScriptEngine().executeFunction(f, scope, scope, newargs, false, false);
    } catch (Exception ex) {
        formController.getApplication().reportJSError(ex.getMessage(), ex);
        return null;
    }
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) BaseComponent(com.servoy.j2db.persistence.BaseComponent) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) WebObjectFunctionDefinition(org.sablo.specification.WebObjectFunctionDefinition) FormScope(com.servoy.j2db.scripting.FormScope) Function(org.mozilla.javascript.Function) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) Solution(com.servoy.j2db.persistence.Solution) ValueReference(org.sablo.util.ValueReference) JSEvent(com.servoy.j2db.scripting.JSEvent) IJSEvent(com.servoy.base.scripting.api.IJSEvent) IRecord(com.servoy.j2db.dataprocessing.IRecord) AbstractBase(com.servoy.j2db.persistence.AbstractBase) Scriptable(org.mozilla.javascript.Scriptable) JSONException(org.json.JSONException) PropertyDescription(org.sablo.specification.PropertyDescription) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) JSONObject(org.json.JSONObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Aggregations

IRecord (com.servoy.j2db.dataprocessing.IRecord)9 FormScope (com.servoy.j2db.scripting.FormScope)3 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)2 Component (org.apache.wicket.Component)2 IJSEvent (com.servoy.base.scripting.api.IJSEvent)1 IFormController (com.servoy.j2db.IFormController)1 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)1 EditRecordList (com.servoy.j2db.dataprocessing.EditRecordList)1 FindState (com.servoy.j2db.dataprocessing.FindState)1 IFoundSet (com.servoy.j2db.dataprocessing.IFoundSet)1 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)1 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 Form (com.servoy.j2db.persistence.Form)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)1