use of javax.faces.component.UICommand in project acs-community-packaging by Alfresco.
the class UIDialogButtons method generateButtons.
/**
* Generates the buttons for the dialog currently being shown.
*
* @param context Faces context
*/
@SuppressWarnings("unchecked")
protected void generateButtons(FacesContext context) {
// generate the OK button, if necessary
if (Application.getDialogManager().isOKButtonVisible()) {
UICommand okButton = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
okButton.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
FacesHelper.setupComponentId(context, okButton, "finish-button");
// create the binding for the finish button label
ValueBinding valueBinding = context.getApplication().createValueBinding("#{DialogManager.finishButtonLabel}");
okButton.setValueBinding("value", valueBinding);
// create the action binding
MethodBinding methodBinding = context.getApplication().createMethodBinding("#{DialogManager.finish}", null);
okButton.setAction(methodBinding);
// create the binding for whether the button is disabled
valueBinding = context.getApplication().createValueBinding("#{DialogManager.finishButtonDisabled}");
okButton.setValueBinding("disabled", valueBinding);
// setup CSS class for button
String styleClass = (String) this.getAttributes().get("styleClass");
if (styleClass != null) {
okButton.getAttributes().put("styleClass", styleClass);
}
// add the OK button
this.getChildren().add(okButton);
}
// generate the additional buttons
generateAdditionalButtons(context);
// generate the OK button
UICommand cancelButton = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
cancelButton.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
FacesHelper.setupComponentId(context, cancelButton, "cancel-button");
// create the binding for the cancel button label
ValueBinding valueBinding = context.getApplication().createValueBinding("#{DialogManager.cancelButtonLabel}");
cancelButton.setValueBinding("value", valueBinding);
// create the action binding
MethodBinding methodBinding = context.getApplication().createMethodBinding("#{DialogManager.cancel}", null);
cancelButton.setAction(methodBinding);
// setup CSS class for button
String styleClass = (String) this.getAttributes().get("styleClass");
if (styleClass != null) {
cancelButton.getAttributes().put("styleClass", styleClass);
}
// set the immediate flag to true
cancelButton.getAttributes().put("immediate", Boolean.TRUE);
// add the Cancel button
this.getChildren().add(cancelButton);
}
use of javax.faces.component.UICommand in project acs-community-packaging by Alfresco.
the class UIDialogButtons method generateAdditionalButtons.
/**
* If there are any additional buttons to add as defined by the dialog
* configuration and the dialog at runtime they are generated in this
* method.
*
* @param context Faces context
*/
@SuppressWarnings("unchecked")
protected void generateAdditionalButtons(FacesContext context) {
// get potential list of additional buttons
List<DialogButtonConfig> buttons = Application.getDialogManager().getAdditionalButtons();
if (buttons != null && buttons.size() > 0) {
if (logger.isDebugEnabled())
logger.debug("Adding " + buttons.size() + " additional buttons: " + buttons);
// add a spacing row to separate the additional buttons from the OK button
addSpacingRow(context);
for (DialogButtonConfig buttonCfg : buttons) {
UICommand button = (UICommand) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
button.setRendererType(ComponentConstants.JAVAX_FACES_BUTTON);
FacesHelper.setupComponentId(context, button, buttonCfg.getId());
// setup the value of the button (the label)
String label = buttonCfg.getLabel();
if (label != null) {
// see if the label represents a value binding
if (label.startsWith(BINDING_EXPRESSION_START)) {
ValueBinding binding = context.getApplication().createValueBinding(label);
button.setValueBinding("value", binding);
} else {
button.setValue(label);
}
} else {
// NOTE: the config checks that a label or a label id
// is present so we can assume there is an id
// if there isn't a label
String labelId = buttonCfg.getLabelId();
label = Application.getMessage(context, labelId);
button.setValue(label);
}
// setup the action binding, the config checks that an action
// is present so no need to check for NullPointer. It also checks
// it represents a method binding expression.
String action = buttonCfg.getAction();
MethodBinding methodBinding = context.getApplication().createMethodBinding(action, null);
button.setAction(methodBinding);
// setup the disabled attribute, check for null and
// binding expressions
String disabled = buttonCfg.getDisabled();
if (disabled != null && disabled.length() > 0) {
if (disabled.startsWith(BINDING_EXPRESSION_START)) {
ValueBinding binding = context.getApplication().createValueBinding(disabled);
button.setValueBinding("disabled", binding);
} else {
button.getAttributes().put("disabled", Boolean.parseBoolean(disabled));
}
}
// setup CSS class for the button
String styleClass = (String) this.getAttributes().get("styleClass");
if (styleClass != null) {
button.getAttributes().put("styleClass", styleClass);
}
// setup the onclick handler for the button
String onclick = buttonCfg.getOnclick();
if (onclick != null && onclick.length() > 0) {
button.getAttributes().put("onclick", onclick);
}
// add the button
this.getChildren().add(button);
if (logger.isDebugEnabled())
logger.debug("Added button with id of: " + button.getId());
}
// add a spacing row to separate the additional buttons from the Cancel button
addSpacingRow(context);
}
}
use of javax.faces.component.UICommand in project acs-community-packaging by Alfresco.
the class UISelectList method renderItem.
/**
* Render a list item in the appropriate selection mode
*
* @param context FacesContext
* @param out ResponseWriter
* @param item UIListItem representing the item to render
*/
private void renderItem(FacesContext context, ResponseWriter out, UIListItem item) throws IOException {
boolean activeSelect = isActiveSelect();
boolean escapeLabel = getEscapeItemLabel();
boolean escapeDescription = getEscapeItemDescription();
// begin the row, add tooltip if present
String tooltip = item.getTooltip();
out.write("<tr title=\"");
out.write(tooltip != null ? tooltip : "");
out.write("\">");
if (activeSelect == false) {
// we are rendering passive select list, so either multi or single selection using
// checkboxes or radio button control respectively
boolean multiSelect = isMultiSelect();
String id = getClientId(context);
String itemValue = item.getValue().toString();
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write(" width=16><input type='");
out.write(multiSelect ? "checkbox" : "radio");
out.write("' name='");
out.write(id);
out.write("' id='");
out.write(id);
out.write("' value='");
out.write(Utils.encode(itemValue));
out.write("'");
if (this.onchange != null) {
out.write(" onchange='" + this.onchange + "'");
}
String[] value = (String[]) getValue();
if (multiSelect) {
if (value != null) {
for (int i = 0; i < value.length; i++) {
if (value[i].equals(itemValue)) {
out.write(" CHECKED");
break;
}
}
}
} else {
if (value != null && value.length == 1 && value[0].equals(itemValue)) {
out.write(" CHECKED");
}
}
out.write("></td>");
}
// optional 32x32 pixel icon
String icon = item.getImage();
if (icon != null) {
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
// give pixel space around edges
out.write(" width=34>");
out.write(Utils.buildImageTag(context, icon, 32, 32, ""));
out.write("</td>");
}
// label and description text
String label = item.getLabel();
String description = item.getDescription();
out.write("<td width=100%");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write("><div style='padding:2px'>");
if (escapeLabel) {
out.write(Utils.encode(label));
} else {
out.write(label);
}
out.write("</div>");
if (description != null) {
out.write("<div style='padding:2px'>");
if (escapeDescription) {
out.write(Utils.encode(description));
} else {
out.write(description);
}
out.write("</div>");
}
out.write("</td>");
if (activeSelect) {
// we are rendering an active select list with child components next to each item
// get the child components and look for compatible Command objects
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write('>');
for (Iterator i = getChildren().iterator(); i.hasNext(); ) /**/
{
UIComponent child = (UIComponent) i.next();
if (child instanceof UICommand) {
out.write("<span style='padding:1px'>");
Utils.encodeRecursive(context, child);
out.write("</span>");
}
}
out.write("</td>");
}
}
Aggregations