use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class WebAccordionPanel method getTagResolver.
private ITagResolver getTagResolver(IRecordInternal parentState) {
ITagResolver resolver;
WebForm webForm = findParent(WebForm.class);
if (webForm != null) {
resolver = webForm.getController().getTagResolver();
} else {
resolver = TagResolver.createResolver(parentState);
}
return resolver;
}
use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class WebAccordionPanel method setCurrentForm.
private void setCurrentForm(WebTabFormLookup fl, int previousIndex, List<Runnable> invokeLaterRunnables) {
if (fl != null && !fl.isFormReady())
return;
getStylePropertyChanges().setChanged();
currentForm = fl;
if (parentData != null) {
showFoundSet(currentForm, parentData, getDefaultSort());
}
// Test if current one is there
if (currentForm.isReady()) {
addCurrentFormComponent();
recomputeTabSequence();
boolean visible = true;
WebForm webform = findParent(WebForm.class);
if (webform != null) {
visible = webform.getController().isFormVisible();
}
currentForm.notifyVisible(visible, invokeLaterRunnables);
if (onTabChangeMethodCmd != null && previousIndex != -1) {
scriptExecutor.executeFunction(onTabChangeMethodCmd, Utils.arrayMerge((new Object[] { Integer.valueOf(previousIndex + 1) }), onTabChangeArgs), true, this, false, StaticContentSpecLoader.PROPERTY_ONCHANGEMETHODID.getPropertyName(), false);
}
}
}
use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class SortableCellViewHeaderGroup method sort.
protected final void sort(final String name, final WebCellBasedView view, int modifiers) {
direction = Utils.getAsBoolean(sorted.get(name));
direction = !direction;
FormController fc = null;
try {
Iterator<IPersist> it = cellview.getAllObjects();
while (it.hasNext()) {
IPersist element = it.next();
if (element instanceof ISupportName && element instanceof ISupportDataProviderID) {
if (name.equals(ComponentFactory.getWebID(form, element))) {
IFoundSetInternal fs = ((FoundSetListWrapper) listView.getList()).getFoundSet();
if (fs != null) {
WebForm wf = listView.findParent(WebForm.class);
if (wf != null)
fc = wf.getController();
GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
int labelForOnActionMethodId = 0;
if (gc != null) {
labelForOnActionMethodId = gc.getOnActionMethodID();
}
if (fc != null && labelForOnActionMethodId > 0) {
// execute on action
JSEvent event = new JSEvent();
event.setType(JSEvent.EventType.action);
event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
event.setFormName(view.getDataAdapterList().getFormController().getName());
event.setModifiers(modifiers);
event.setElementName(gc.getName());
fc.executeFunction(String.valueOf(labelForOnActionMethodId), // $NON-NLS-1$
Utils.arrayMerge((new Object[] { event }), Utils.parseJSExpressions(gc.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$
"onActionMethodID");
}
String id = ((ISupportDataProviderID) element).getDataProviderID();
if (id != null) {
if (cellview instanceof Portal && !ScopesUtils.isVariableScope(id)) {
int idx = id.lastIndexOf('.');
if (idx > 0) {
id = id.substring(idx + 1);
}
}
IDataProvider dataProvider = null;
if (fc != null) {
dataProvider = fs.getFoundSetManager().getApplication().getFlattenedSolution().getDataproviderLookup(fs.getFoundSetManager(), fc.getForm()).getDataProvider(id);
}
if (!(fc != null && labelForOnActionMethodId > 0)) {
// in case there is no onAction definned
if (cellview instanceof Portal || fc == null || fc.getForm().getOnSortCmdMethodID() == 0) {
List<String> sortingProviders = null;
try {
sortingProviders = DBValueList.getShowDataproviders(fs.getFoundSetManager().getApplication().getFlattenedSolution().getValueList(((ISupportDataProviderID) element).getValuelistID()), (Table) fs.getTable(), dataProvider == null ? id : dataProvider.getDataProviderID(), fs.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dataProvider == null ? id : dataProvider.getDataProviderID());
}
List<SortColumn> list = (modifiers & Event.SHIFT_MASK) != 0 ? fs.getSortColumns() : new ArrayList<SortColumn>();
for (String sortingProvider : sortingProviders) {
FoundSetManager fsm = (FoundSetManager) fs.getFoundSetManager();
SortColumn sc = fsm.getSortColumn(fs.getTable(), sortingProvider, false);
if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
for (SortColumn oldColumn : list) {
if (oldColumn.equalsIgnoreSortorder(sc)) {
sc = oldColumn;
break;
}
}
if (!list.contains(sc))
list.add(sc);
sc.setSortOrder(direction ? SortColumn.ASCENDING : SortColumn.DESCENDING);
}
fs.sort(list, false);
}
} else if (fc != null && fc.getForm().getOnSortCmdMethodID() != -1) {
JSEvent event = new JSEvent();
event.setType(JSEvent.EventType.none);
event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
event.setFormName(view.getDataAdapterList().getFormController().getName());
event.setModifiers(modifiers);
fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProvider == null ? id : dataProvider.getDataProviderID(), Boolean.valueOf(direction), event }), // $NON-NLS-1$
Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$
"onSortCmdMethodID");
}
}
if ((modifiers & Event.SHIFT_MASK) == 0) {
sorted.clear();
}
sorted.put(name, new Boolean(direction));
listView.setCurrentPage(0);
}
}
break;
}
}
}
listView.modelChanged();
} catch (Exception e) {
if (fc != null) {
if (e instanceof ServoyException) {
((ServoyException) e).setContext(fc.toString());
} else {
ServoyException se = new ServoyException();
se.initCause(e);
se.setContext(fc.toString());
e = se;
}
}
Debug.error("error sorting foundset: " + sorted, e);
}
}
use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class InlineScriptExecutorBehavior method respond.
@Override
protected void respond(AjaxRequestTarget target) {
Page page = component.getPage();
String scriptName = RequestCycle.get().getRequest().getParameter("snenc");
ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
scriptName = urlCrypt.decryptUrlSafe(scriptName).replace("\\\"", "\"");
String argValue;
for (String browserArgument : getBrowserArguments(scriptName)) {
argValue = RequestCycle.get().getRequest().getParameter(browserArgument);
if (argValue == null)
argValue = "";
boolean isString = true;
try {
Double.parseDouble(argValue);
isString = false;
} catch (NumberFormatException ex) {
}
if (isString && ("true".equals(argValue) || "false".equals(argValue)))
isString = false;
String browserParamWithArgument = BROWSER_PARAM + browserArgument;
// make sure we ignore user quoting if isString
if (isString) {
scriptName = scriptName.replace("\"" + browserParamWithArgument + "\"", browserParamWithArgument);
scriptName = scriptName.replace("'" + browserParamWithArgument + "'", browserParamWithArgument);
}
scriptName = scriptName.replace(browserParamWithArgument, isString ? "'" + argValue + "'" : argValue);
}
WebForm wf = component.findParent(WebForm.class);
if (wf != null) {
try {
wf.getController().eval(scriptName);
} catch (Exception e) {
if (!(e instanceof ExitScriptException)) {
// $NON-NLS-1$
Debug.error("Exception evaluating: " + scriptName, e);
}
}
WebEventExecutor.generateResponse(target, page);
}
// $NON-NLS-1$ //$NON-NLS-2$
target.appendJavascript("clearDoubleClickId('" + component.getMarkupId() + "')");
}
use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.
the class RecordItemModel method setValue.
/**
* @param obj
* @param dataProviderID
* @param prevValue
*/
public void setValue(Component component, String dataProviderID, Object value) {
Object obj = value;
String compDpid = getDataProviderID(component);
boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
Object prevValue = null;
if (ownComponentsValue && component instanceof IResolveObject) {
obj = ((IResolveObject) component).resolveRealValue(obj);
}
if (component instanceof IDisplayData) {
obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
}
WebForm webForm = component.findParent(WebForm.class);
IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
// use UI converter to convert from UI value to record value
if (!(record instanceof FindState)) {
obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
}
FormScope fs = webForm.getController().getFormScope();
try {
Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
if (scope.getLeft() != null) {
if (record == null) {
webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
} else {
// does an additional fire in foundset!
prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
}
} else if (fs.has(dataProviderID, fs)) {
prevValue = fs.get(dataProviderID);
fs.put(dataProviderID, obj);
} else {
if (record != null && record.startEditing()) {
try {
prevValue = record.getValue(dataProviderID);
record.setValue(dataProviderID, obj);
} catch (IllegalArgumentException e) {
Debug.trace(e);
((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
Object stateValue = record.getValue(dataProviderID);
if (!Utils.equalObjects(prevValue, stateValue)) {
// reset display to changed value in validator method
obj = stateValue;
}
if (ownComponentsValue) {
((IDisplayData) component).setValueValid(false, prevValue);
}
return;
}
if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
}
}
}
// then dont call notify
if (ownComponentsValue) {
((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
}
} finally {
// then touch the lastInvalidValue
if (ownComponentsValue) {
if (((IDisplayData) component).isValueValid()) {
lastInvalidValue = NONE;
} else {
lastInvalidValue = obj;
}
}
}
return;
}
Aggregations