public void encodeEnd(FacesContext context,
UIComponent component) throws IOException {
// ---------------------------------------------------------- Public Methods
rendererParamsNotNull(context, component);
if (!shouldEncode(component)) {
return;
}
ResponseWriter writer = context.getResponseWriter();
assert(writer != null);
String alignStr;
Object borderObj;
boolean alignVertical = false;
int border = 0;
if (null !=
(alignStr = (String) component.getAttributes().get("layout"))) {
alignVertical = alignStr.equalsIgnoreCase("pageDirection");
}
if (null != (borderObj = component.getAttributes().get("border"))) {
border = (Integer) borderObj;
}
Converter converter = null;
if(component instanceof ValueHolder) {
converter = ((ValueHolder)component).getConverter();
}
renderBeginText(component, border, alignVertical, context, true);
List< SelectItem > items = RenderKitUtils.getSelectItems(context, component);
if (!items.isEmpty()) {
Object currentSelections = getCurrentSelectedValues(component);
Object[] submittedValues = getSubmittedSelectedValues(component);
int idx = -1;
for (SelectItem curItem : items) {
idx++;
// If we come across a group of options, render them as a nested
// table.
if (curItem instanceof SelectItemGroup) {
// write out the label for the group.
if (curItem.getLabel() != null) {
if (alignVertical) {
writer.startElement("tr", component);
}
writer.startElement("td", component);
writer.writeText(curItem.getLabel(), component, "label");
writer.endElement("td");
if (alignVertical) {
writer.endElement("tr");
}
}
if (alignVertical) {
writer.startElement("tr", component);
}
writer.startElement("td", component);
writer.writeText("\n", component, null);
renderBeginText(component, 0, alignVertical,
context, false);
// render options of this group.
SelectItem[] itemsArray =
((SelectItemGroup) curItem).getSelectItems();
for (int i = 0; i < itemsArray.length; ++i) {
renderOption(context,
component,
converter,
itemsArray[i],
currentSelections,
submittedValues,
alignVertical,
i);
}
renderEndText(component, alignVertical, context);
writer.endElement("td");
if (alignVertical) {
writer.endElement("tr");
writer.writeText("\n", component, null);
}
} else {
renderOption(context,
component,
converter,
curItem,
currentSelections,
submittedValues,
alignVertical,
idx);
}
}
}
renderEndText(component, alignVertical, context);
}
|
protected void renderBeginText(UIComponent component,
int border,
boolean alignVertical,
FacesContext context,
boolean outerTable) throws IOException {
ResponseWriter writer = context.getResponseWriter();
assert(writer != null);
writer.startElement("table", component);
if (border != Integer.MIN_VALUE) {
writer.writeAttribute("border", border, "border");
}
// render style and styleclass attribute on the outer table instead of
// rendering it as pass through attribute on every option in the list.
if (outerTable) {
// render "id" only for outerTable.
if (shouldWriteIdAttribute(component)) {
writeIdAttributeIfNecessary(context, writer, component);
}
String styleClass = (String) component.getAttributes().get(
"styleClass");
String style = (String) component.getAttributes().get("style");
if (styleClass != null) {
writer.writeAttribute("class", styleClass, "class");
}
if (style != null) {
writer.writeAttribute("style", style, "style");
}
}
writer.writeText("\n", component, null);
if (!alignVertical) {
writer.writeText("\t", component, null);
writer.startElement("tr", component);
writer.writeText("\n", component, null);
}
}
|
protected void renderOption(FacesContext context,
UIComponent component,
Converter converter,
SelectItem curItem,
boolean alignVertical,
int itemNumber) throws IOException {
renderOption(context,
component,
converter,
curItem,
getCurrentSelectedValues(component),
getSubmittedSelectedValues(component),
alignVertical,
itemNumber);
}
|
protected void renderOption(FacesContext context,
UIComponent component,
Converter converter,
SelectItem curItem,
Object currentSelections,
Object[] submittedValues,
boolean alignVertical,
int itemNumber) throws IOException {
ResponseWriter writer = context.getResponseWriter();
assert (writer != null);
// disable the check box if the attribute is set.
boolean componentDisabled = Util.componentIsDisabled(component);
String labelClass;
if (componentDisabled || curItem.isDisabled()) {
labelClass = (String) component.
getAttributes().get("disabledClass");
} else {
labelClass = (String) component.
getAttributes().get("enabledClass");
}
if (alignVertical) {
writer.writeText("\t", component, null);
writer.startElement("tr", component);
writer.writeText("\n", component, null);
}
writer.startElement("td", component);
writer.writeText("\n", component, null);
writer.startElement("input", component);
writer.writeAttribute("name", component.getClientId(context),
"clientId");
String idString =
component.getClientId(context) + NamingContainer.SEPARATOR_CHAR +
Integer.toString(itemNumber);
writer.writeAttribute("id", idString, "id");
String valueString = getFormattedValue(context, component,
curItem.getValue(), converter);
writer.writeAttribute("value", valueString, "value");
writer.writeAttribute("type", "checkbox", null);
Object valuesArray;
Object itemValue;
if (submittedValues != null) {
valuesArray = submittedValues;
itemValue = valueString;
} else {
valuesArray = currentSelections;
itemValue = curItem.getValue();
}
RequestStateManager.set(context,
RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
component);
if (isSelected(context, itemValue, valuesArray)) {
writer.writeAttribute(getSelectedTextString(), Boolean.TRUE, null);
}
// Don't render the disabled attribute twice if the 'parent'
// component is already marked disabled.
if (!Util.componentIsDisabled(component)) {
if (curItem.isDisabled()) {
writer.writeAttribute("disabled", true, "disabled");
}
}
// Apply HTML 4.x attributes specified on UISelectMany component to all
// items in the list except styleClass and style which are rendered as
// attributes of outer most table.
RenderKitUtils.renderPassThruAttributes(writer,
component,
ATTRIBUTES);
RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);
writer.endElement("input");
writer.startElement("label", component);
writer.writeAttribute("for", idString, "for");
// if enabledClass or disabledClass attributes are specified, apply
// it on the label.
if (labelClass != null) {
writer.writeAttribute("class", labelClass, "labelClass");
}
String itemLabel = curItem.getLabel();
if (itemLabel != null) {
writer.writeText(" ", component, null);
if (!curItem.isEscape()) {
// It seems the ResponseWriter API should
// have a writeText() with a boolean property
// to determine if it content written should
// be escaped or not.
writer.write(itemLabel);
} else {
writer.writeText(itemLabel, component, "label");
}
}
writer.endElement("label");
writer.endElement("td");
writer.writeText("\n", component, null);
if (alignVertical) {
writer.writeText("\t", component, null);
writer.endElement("tr");
writer.writeText("\n", component, null);
}
}
|