use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxOptions method _appendToBuffer.
/**
* Adds JSON formatted key-value pairs from options to end of response content. Does not adds the surrounding "{" and "}" signifying a dictionary / object.
*
* @param options dictionary of key-value pairs, intended to have come from AjaxOption
* @param appendable appendable to add JSON formatted key-value pairs to
* @param context WOContext to provide WOComponent to resolve binding values in
*/
public static void _appendToBuffer(NSDictionary options, Appendable appendable, WOContext context) {
if (options != null) {
WOComponent component = context.component();
boolean hasPreviousOptions = false;
Enumeration bindingsEnum = options.keyEnumerator();
while (bindingsEnum.hasMoreElements()) {
String bindingName = (String) bindingsEnum.nextElement();
if (!"options".equals(bindingName)) {
Object bindingValue = options.objectForKey(bindingName);
// This is needed for the double step to resolve the value for ^ notation
if (bindingValue instanceof WOAssociation) {
WOAssociation association = (WOAssociation) bindingValue;
bindingValue = association.valueInComponent(component);
}
if (bindingValue != null) {
try {
if (hasPreviousOptions) {
appendable.append(", ");
}
appendable.append(bindingName);
appendable.append(':');
appendable.append(bindingValue.toString());
hasPreviousOptions = true;
} catch (IOException e) {
// ignore
}
}
}
}
}
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxDraggable method appendToResponse.
@Override
@SuppressWarnings("unchecked")
public void appendToResponse(WOResponse res, WOContext ctx) {
if (canGetValueForBinding("draggableObject")) {
Object draggableObject = valueForBinding("draggableObject");
WOComponent page = context().page();
Map<WOComponent, Map<String, Object>> componentDraggablesMap = (Map<WOComponent, Map<String, Object>>) ctx.session().objectForKey(AjaxDraggable.COMPONENT_DRAGGABLES_MAP_KEY);
if (componentDraggablesMap == null) {
componentDraggablesMap = new WeakHashMap<WOComponent, Map<String, Object>>();
ctx.session().setObjectForKey(componentDraggablesMap, AjaxDraggable.COMPONENT_DRAGGABLES_MAP_KEY);
}
Map<String, Object> draggablesMap = componentDraggablesMap.get(page);
if (draggablesMap == null) {
draggablesMap = new HashMap<>();
componentDraggablesMap.put(page, draggablesMap);
}
String id = draggableID();
if (draggableObject == null) {
draggablesMap.remove(id);
} else {
draggablesMap.put(id, draggableObject);
}
}
super.appendToResponse(res, ctx);
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxDroppable method handleRequest.
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
AjaxUpdateContainer.setUpdateContainerID(request, (String) valueForBinding("updateContainerID"));
String droppedDraggableID = request.stringFormValueForKey(_draggableIDKeyName);
if (canSetValueForBinding("droppedDraggableID")) {
setValueForBinding(droppedDraggableID, "droppedDraggableID");
}
if (canSetValueForBinding("droppedObject")) {
WOComponent page = context.page();
Object droppedObject = AjaxDraggable.draggableObjectForPage(page, droppedDraggableID);
setValueForBinding(droppedObject, "droppedObject");
}
if (canGetValueForBinding("action")) {
WOActionResults results = (WOActionResults) valueForBinding("action");
if (results != null) {
System.out.println("AjaxDroppable.handleRequest: Not quite sure what to do with non-null results yet ...");
}
}
return null;
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxUpdateContainer method handleRequest.
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
WOComponent component = context.component();
String id = _containerID(context);
if (associations().objectForKey("action") != null) {
@SuppressWarnings("unused") WOActionResults results = (WOActionResults) valueForBinding("action", component);
// ignore results
}
WOResponse response = AjaxUtils.createResponse(request, context);
AjaxUtils.setPageReplacementCacheKey(context, id);
if (hasChildrenElements()) {
appendChildrenToResponse(response, context);
}
String onRefreshComplete = (String) valueForBinding("onRefreshComplete", component);
if (onRefreshComplete != null) {
AjaxUtils.appendScriptHeader(response);
response.appendContentString(onRefreshComplete);
AjaxUtils.appendScriptFooter(response);
}
if (AjaxModalDialog.isInDialog(context)) {
AjaxUtils.appendScriptHeader(response);
response.appendContentString("AMD.contentUpdated();");
AjaxUtils.appendScriptFooter(response);
}
return null;
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxUpdateLink method appendToResponse.
@Override
public void appendToResponse(WOResponse response, WOContext context) {
WOComponent component = context.component();
boolean disabled = booleanValueForBinding("disabled", false, component);
Object stringValue = valueForBinding("string", component);
String functionName = (String) valueForBinding("functionName", component);
if (functionName == null) {
String elementName;
boolean button = booleanValueForBinding("button", false, component);
if (button) {
elementName = "input";
} else {
elementName = (String) valueForBinding("elementName", "a", component);
}
boolean isATag = "a".equalsIgnoreCase(elementName);
boolean renderTags = (!disabled || !isATag);
if (renderTags) {
response.appendContentString("<");
response.appendContentString(elementName);
response.appendContentString(" ");
if (button) {
appendTagAttributeToResponse(response, "type", "button");
}
if (isATag) {
appendTagAttributeToResponse(response, "href", "javascript:void(0);");
}
if (!disabled) {
appendTagAttributeToResponse(response, "onclick", onClick(context, false));
}
appendTagAttributeToResponse(response, "title", valueForBinding("title", component));
appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
appendTagAttributeToResponse(response, "id", valueForBinding("id", component));
appendTagAttributeToResponse(response, "accesskey", valueForBinding("accesskey", component));
if (button) {
if (stringValue != null) {
appendTagAttributeToResponse(response, "value", stringValue);
}
if (disabled) {
response.appendContentString(" disabled");
}
}
// appendTagAttributeToResponse(response, "onclick",
// onClick(context));
response.appendContentString(">");
}
if (stringValue != null && !button) {
response.appendContentHTMLString(stringValue.toString());
}
appendChildrenToResponse(response, context);
if (renderTags) {
response.appendContentString("</");
response.appendContentString(elementName);
response.appendContentString(">");
}
} else {
AjaxUtils.appendScriptHeader(response);
response.appendContentString(functionName);
response.appendContentString(" = ");
response.appendContentString(onClick(context, true));
AjaxUtils.appendScriptFooter(response);
}
super.appendToResponse(response, context);
}
Aggregations