use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class UIDialogButtons method encodeEnd.
@Override
public void encodeEnd(FacesContext context) throws IOException {
if (!isRendered())
return;
ResponseWriter out = context.getResponseWriter();
out.write("</table>");
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class BaseAjaxItemPicker method encodeBegin.
/**
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
*/
public void encodeBegin(FacesContext fc) throws IOException {
if (isRendered() == false) {
return;
}
ResponseWriter out = fc.getResponseWriter();
String formClientId = Utils.getParentForm(fc, this).getClientId(fc);
Map attrs = this.getAttributes();
ResourceBundle msg = Application.getBundle(fc);
// get values from submitted value or none selected
String selectedValues = null;
String selectedNames = null;
String selectedItems = null;
List<NodeRef> submitted = null;
if (getSingleSelect() == true) {
NodeRef ref = (NodeRef) getSubmittedValue();
if (ref == null) {
Object objRef = getValue();
if (objRef instanceof String) {
ref = new NodeRef((String) objRef);
} else if (objRef instanceof NodeRef) {
ref = (NodeRef) objRef;
}
}
if (ref != null) {
submitted = new ArrayList<NodeRef>(1);
submitted.add(ref);
}
} else {
Object value = getSubmittedValue();
if (value == null) {
value = getValue();
}
if (value instanceof List) {
submitted = (List<NodeRef>) value;
} else if (value instanceof String) {
// special case for "empty" submitted value
if (!value.equals(EMPTY)) {
submitted = new ArrayList<NodeRef>(1);
submitted.add(new NodeRef(value.toString()));
}
}
}
if (submitted != null) {
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(fc, true);
tx.begin();
StringBuilder nameBuf = new StringBuilder(128);
StringBuilder valueBuf = new StringBuilder(128);
StringBuilder itemBuf = new StringBuilder(256);
NodeService nodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("nodeService");
for (NodeRef value : submitted) {
String name = (String) nodeService.getProperty(value, ContentModel.PROP_NAME);
String icon = (String) nodeService.getProperty(value, ApplicationModel.PROP_ICON);
if (nameBuf.length() != 0) {
nameBuf.append(", ");
valueBuf.append(",");
itemBuf.append(",");
}
nameBuf.append(name);
valueBuf.append(value.toString());
itemBuf.append(getItemJson(value.toString(), name, icon));
}
selectedNames = nameBuf.toString();
selectedValues = valueBuf.toString();
selectedItems = "[" + itemBuf.toString() + "]";
// commit the transaction
tx.commit();
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
// generate the Ids for our script object and containing DIV element
String divId = getId();
String objId = divId + "Obj";
// generate the script to create and init our script object
String contextPath = fc.getExternalContext().getRequestContextPath();
out.write("<script type='text/javascript'>");
out.write("function init" + divId + "() {");
out.write(" window." + objId + " = new AlfPicker('" + divId + "','" + objId + "','" + getServiceCall() + "','" + formClientId + "'," + getSingleSelect() + ");");
if (getInitialSelection() != null) {
out.write(" window." + objId + ".setStartId('" + getInitialSelection() + "');");
}
if (getDefaultIcon() != null) {
out.write(" window." + objId + ".setDefaultIcon('" + getDefaultIcon() + "');");
}
if ((!getSingleSelect()) && (selectedItems != null)) {
out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
}
// write any addition custom request attributes required by specific picker implementations
String requestProps = getRequestAttributes();
if (requestProps != null) {
out.write(" window." + objId + ".setRequestAttributes('" + requestProps + "');");
}
out.write("}");
out.write("window.addEvent('domready', init" + divId + ");");
out.write("</script>");
// generate the DIV structure for our component as expected by the script object
out.write("<div id='" + divId + "' class='picker'>");
out.write(" <input id='" + getHiddenFieldName() + "' name='" + getHiddenFieldName() + "' type='hidden' value='");
if (selectedValues != null) {
out.write(selectedValues);
}
out.write("'>");
// current selection displayed as link and message to launch the selector
out.write(" <div id='" + divId + "-noitems'");
if (attrs.get("style") != null) {
out.write(" style=\"");
out.write((String) attrs.get("style"));
out.write('"');
}
if (attrs.get("styleClass") != null) {
out.write(" class=");
out.write((String) attrs.get("styleClass"));
}
out.write(">");
out.write(" <span class='pickerActionButton'><a href='javascript:" + objId + ".showSelector();'>");
if (selectedNames == null) {
out.write(getLabel());
} else {
out.write(selectedNames);
}
out.write("</a></span>");
out.write(" </div>");
// container for item navigation
out.write(" <div id='" + divId + "-selector' class='pickerSelector'>");
out.write(" <div class='pickerResults'>");
out.write(" <div class='pickerResultsHeader'>");
out.write(" <div class='pickerNavControls'>");
out.write(" <span class='pickerNavUp'>");
out.write(" <a id='" + divId + "-nav-up' href='#'><img src='");
out.write(contextPath);
out.write("/images/icons/arrow_up.gif' border='0' alt='");
out.write(msg.getString(MSG_GO_UP));
out.write("' title='");
out.write(msg.getString(MSG_GO_UP));
out.write("'></a>");
out.write(" </span>");
out.write(" <span class='pickerNavBreadcrumb'>");
out.write(" <div id='" + divId + "-nav-bread' class='pickerNavBreadcrumbPanel'></div>");
out.write(" <a href='javascript:" + objId + ".breadcrumbToggle();'><span id='" + divId + "-nav-txt'></span><img border='0' src='");
out.write(contextPath);
out.write("/images/icons/arrow_open.gif'></a>");
out.write(" </span>");
out.write(" <span id='" + divId + "-nav-add'></span>");
out.write(" </div>");
out.write(" </div>");
// container for item selection
out.write(" <div>");
out.write(" <div id='" + divId + "-ajax-wait' class='pickerAjaxWait'");
String height = getHeight();
if (height != null) {
out.write(" style='height:" + height + "'");
}
out.write("></div>");
out.write(" <div id='" + divId + "-results-list' class='pickerResultsList'");
if (height != null) {
out.write(" style='height:" + height + "'");
}
out.write("></div>");
out.write(" </div>");
out.write(" </div>");
// controls (OK & Cancel buttons etc.)
out.write(" <div class='pickerFinishControls'>");
out.write(" <div id='" + divId + "-finish' style='float:left' class='pickerButtons'><a href='javascript:" + objId + ".doneClicked();'>");
out.write(msg.getString(MSG_OK));
out.write("</a></div>");
out.write(" <div style='float:right' class='pickerButtons'><a href='javascript:" + objId + ".cancelClicked();'>");
out.write(msg.getString(MSG_CANCEL));
out.write("</a></div>");
out.write(" </div>");
out.write(" </div>");
// container for the selected items
out.write(" <div id='" + divId + "-selected' class='pickerSelectedItems'></div>");
out.write("</div>");
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class ErrorsRenderer method encodeBegin.
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
if (component.isRendered() == false) {
return;
}
Iterator messages = context.getMessages();
if (messages.hasNext()) {
ResponseWriter out = context.getResponseWriter();
String contextPath = context.getExternalContext().getRequestContextPath();
String styleClass = (String) component.getAttributes().get("styleClass");
String errorClass = (String) component.getAttributes().get("errorClass");
if (errorClass == null) {
errorClass = DEFAULT_CSS_ERROR;
}
String infoClass = (String) component.getAttributes().get("infoClass");
if (infoClass == null) {
infoClass = DEFAULT_CSS_INFO;
}
String message = (String) component.getAttributes().get("message");
String errorHint = Application.getMessage(context, ERROR_HINT);
if (message == null) {
// because we are using the standard messages component value binding
// would not be handled for the message attribute so do it here
ValueBinding vb = component.getValueBinding("message");
if (vb != null) {
message = (String) vb.getValue(context);
}
if (message == null) {
message = Application.getMessage(context, DEFAULT_MESSAGE);
}
}
PanelGenerator.generatePanelStart(out, contextPath, "yellowInner", "#ffffcc");
out.write("\n<div");
if (styleClass != null) {
outputAttribute(out, styleClass, "class");
}
out.write(">");
// if we have a message to display show it next to the info icon
if (message.length() > 0 && context.getMaximumSeverity().compareTo(FacesMessage.SEVERITY_WARN) > 0) {
out.write("<img src='");
out.write(contextPath);
out.write("/images/icons/info_icon.gif' alt='");
out.write(Utils.encode(errorHint));
out.write("' align='absmiddle'/> ");
out.write(Utils.encode(message));
out.write("\n<ul style='margin:2px;'>");
while (messages.hasNext()) {
FacesMessage fm = (FacesMessage) messages.next();
out.write("<li");
renderMessageAttrs(fm, out, errorClass, infoClass);
out.write(">");
out.write(Utils.encode(fm.getDetail()));
out.write("</li>\n");
}
out.write("</ul>");
} else {
// if there is no title message to display use a table to place
// the info icon on the left and the list of messages on the right
out.write("<table border='0' cellpadding='3' cellspacing='0'><tr><td valign='top'><img src='");
out.write(contextPath);
out.write("/images/icons/info_icon.gif' alt='");
out.write(Utils.encode(errorHint));
out.write("'/>");
out.write("</td><td>");
while (messages.hasNext()) {
FacesMessage fm = (FacesMessage) messages.next();
out.write("<div style='margin-bottom: 3px;'");
renderMessageAttrs(fm, out, errorClass, infoClass);
out.write(">");
out.write(Utils.encode(fm.getDetail()));
out.write("</div>\n");
}
out.write("</td></tr></table>");
}
out.write("</div>\n");
PanelGenerator.generatePanelEnd(out, contextPath, "yellowInner");
// TODO: Expose this as a configurable attribute i.e. padding at bottom
out.write("<div style='padding:2px;'></div>");
}
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class ImagePickerRadioRenderer method encodeEnd.
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
if (component.isRendered() == false) {
return;
}
ResponseWriter out = context.getResponseWriter();
out.write("</table>");
// if we didn't select any image, default to the first one
if (this.imageSelected == false) {
out.write("\n<script type='text/javascript'>document.getElementById('");
out.write(component.getClientId(context));
out.write("').checked = true;</script>\n");
}
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class ModeListRenderer method encodeEnd.
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
if (!component.isRendered()) {
return;
}
ResponseWriter out = context.getResponseWriter();
// end outer table
UIModeList list = (UIModeList) component;
if (list.isHorizontal()) {
out.write("</tr>");
}
out.write("</table>");
if (list.isMenu()) {
// close menu hidden div section
out.write("</div>");
}
}
Aggregations