return ( obj == null ? "" : obj.toString() );
}
public void writeScript(FacesContext context, UIComponent component) throws IOException {
UIComponentControl componentControl = (UIComponentControl) component;
ResponseWriter writer = context.getResponseWriter();
Map<String, Object> attributes = component.getAttributes();
String name = convertToString(attributes.get("name"));
String attachTo = convertToString(attributes.get("attachTo"));
String forAttr = convertToString(attributes.get("for"));
forAttr = replaceClientIds(context, component, forAttr);
String operation = convertToString(attributes.get("operation"));
String attachTiming = componentControl.getAttachTiming();
checkValidity(componentControl.getClientId(context), name, attachTiming, forAttr, operation);
String event = convertToString(attributes.get("event"));
JSFunctionDefinition namedFunction = null;
JSFunction eventFunction = null;
if (name.trim().length() != 0) {
JSFunction subFunction = new JSFunction("Richfaces.componentControl.performOperation");
subFunction.addParameter(new JSReference("event"));
componentControl.addOptions(subFunction, event, forAttr, operation);
namedFunction = new JSFunctionDefinition("event");
namedFunction.setName(name);
namedFunction.addToBody(subFunction);
}
if (attachTo != null && attachTo.trim().length() != 0 && !"#".equals(attachTo)) {
boolean isImmediate = attachTiming.equals(IMMEDIATE);
boolean isOnLoad = attachTiming.equals(ON_LOAD);
boolean isOnAvailable = attachTiming.equals(ON_AVAILABLE);
if (isOnLoad) {
eventFunction = new JSFunction("Richfaces.componentControl.attachReady");
} else if (isOnAvailable) {
eventFunction = new JSFunction("Richfaces.componentControl.attachAvailable");
} else if (isImmediate) {
eventFunction = new JSFunction("Richfaces.componentControl.attachEvent");
} else {
// unknown value of property "attachTiming"
return;
}
// "attachTo" attribute may contain several ids splitted by ","
String selector = replaceClientIds(context, component, attachTo);
eventFunction.addParameter(selector);
componentControl.addOptions(eventFunction, event, forAttr, operation);
}
if (eventFunction != null || namedFunction != null) {
writer.startElement(HTML.SCRIPT_ELEM, componentControl);
getUtils().writeAttribute(writer, HTML.TYPE_ATTR, "text/javascript");