use of com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor in project servoy-client by Servoy.
the class MainPage method respond.
/**
* Respond to focus/blur events.
*/
@SuppressWarnings("nls")
public void respond(AjaxRequestTarget target, final String event, final String markupId) {
Component component = (Component) visitChildren(IComponent.class, new IVisitor<Component>() {
public Object component(Component c) {
Component targetComponent = c;
if (c instanceof WebBaseSelectBox && ("blur".equals(event) || "focus".equals(event))) {
Component[] cs = ((WebBaseSelectBox) c).getFocusChildren();
if (cs != null && cs.length == 1)
targetComponent = cs[0];
}
if (targetComponent.getMarkupId().equals(markupId)) {
return c;
}
return IVisitor.CONTINUE_TRAVERSAL;
}
});
if (component == null) {
// $NON-NLS-1$
Debug.log("Component not found markupId " + markupId);
return;
}
IFormUIInternal<?> formui = component.findParent(IFormUIInternal.class);
if (formui != null && formui.isDesignMode()) {
// $NON-NLS-1$
Debug.log("Event ignored because of design mode");
return;
}
if (component instanceof IFieldComponent) {
WebEventExecutor eventExecutor = (WebEventExecutor) ((IFieldComponent) component).getEventExecutor();
if (eventExecutor != null) {
if ("focus".equals(event)) {
int webModifier = Utils.getAsInteger(RequestCycle.get().getRequest().getParameter(IEventExecutor.MODIFIERS_PARAMETER));
StartEditOnFocusGainedEventBehavior.startEditing(component, WebEventExecutor.convertModifiers(webModifier), target);
eventExecutor.onEvent(JSEvent.EventType.focusGained, target, component, webModifier);
} else if ("blur".equals(event)) {
// test if the data is really posted by looking up the key.
if (component instanceof FormComponent<?> && RequestCycle.get().getRequest().getParameter("nopostdata") == null) {
// changed data is posted
((FormComponent<?>) component).processInput();
}
eventExecutor.onEvent(JSEvent.EventType.focusLost, target, component, IEventExecutor.MODIFIERS_UNSPECIFIED);
} else {
Debug.trace("Ignored event " + event);
}
} else {
Debug.trace("Ignored event, no eventExecutor");
}
} else {
// other non-field components like WebLabel
ServoyForm form = component.findParent(ServoyForm.class);
if (form != null) {
// JS might change the page this form belongs to... so remember it now
Page page = form.getPage();
int webModifier = Utils.getAsInteger(RequestCycle.get().getRequest().getParameter(IEventExecutor.MODIFIERS_PARAMETER));
WebEventExecutor.setSelectedIndex(component, target, WebEventExecutor.convertModifiers(webModifier), true);
WebEventExecutor.generateResponse(target, page);
}
}
}
Aggregations