Search in sources :

Example 21 with WebForm

use of com.servoy.j2db.server.headlessclient.WebForm 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)

Aggregations

WebForm (com.servoy.j2db.server.headlessclient.WebForm)21 FormController (com.servoy.j2db.FormController)7 Point (java.awt.Point)6 Component (org.apache.wicket.Component)5 IComponent (com.servoy.j2db.ui.IComponent)4 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 ITagResolver (com.servoy.base.util.ITagResolver)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 FindState (com.servoy.j2db.dataprocessing.FindState)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 Form (com.servoy.j2db.persistence.Form)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 FormScope (com.servoy.j2db.scripting.FormScope)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 ArrayList (java.util.ArrayList)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1