Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2007-2018 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://oss.oracle.com/licenses/CDDL+GPL-1.1
* or LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* $Id: ListRendererBase.java,v 1.1.4.1.2.1 2009-12-29 04:52:45 jyeary Exp $
*/
package com.sun.webui.jsf.renderkit.html;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
import com.sun.webui.jsf.component.ListManager;
import com.sun.webui.jsf.component.ListSelector;
import com.sun.webui.jsf.model.Separator;
import com.sun.webui.jsf.model.OptionTitle;
import com.sun.webui.jsf.model.list.ListItem;
import com.sun.webui.jsf.model.list.StartGroup;
import com.sun.webui.jsf.model.list.EndGroup;
import com.sun.webui.jsf.util.ConversionUtilities;
import com.sun.webui.jsf.util.RenderingUtilities;
/**
* The ListRendererBase is the base class for the listbox renderers
* (Drop-down Menu and Selectable List). These are both rendered using
* the same HTML tag (select) so a lot of the renderering functionality
* is shared.
*/
public abstract class ListRendererBase extends Renderer {
/**
*
*/
private final static boolean DEBUG = false;
/**
The list of attribute names in the HTML 4.01 Specification that
* correspond to the entity type %events;.
This method determines whether the component should be
* rendered as a standalone list, or laid out together with a
* label that was defined as part of the component.
*
*
A label will be rendered if either of the following is
* true:
*
*
The page author defined a label facet; or
*
The page author specified text in the label attribute.
*
*
If there is a label, the component will be laid out using a
* HTML table. If not, the component will be rendered as a
* standalone HTML select element.
* @param component The component associated with the
* renderer. Must be a subclass of ListSelector.
* @param context The FacesContext of the request
* @param styles A String array of styles used to render the
* component. The first item of the array is the name of the
* JavaScript method that handles change event. The second item is
* the style used when the list is enabled. The third style is the
* one to use when the list is disabled. The fourth item is the
* style to use for an item that is enabled, the fifth to use for
* an item that is disabled, and the sixth to use when the item is
* selected.
* @throws java.io.IOException if the renderer fails to write to
* the response
*/
void renderListComponent(ListSelector component, FacesContext context,
String[] styles)
throws IOException {
if (DEBUG) {
log("renderListComponent()");
}
boolean readonly = component.isReadOnly();
if (readonly) {
if (DEBUG) {
log("\t component is readonly");
}
// We don't want to accidentally mark any label as
// required in this case...
component.setRequired(false);
}
UIComponent label = component.getLabelComponent();
ResponseWriter writer = context.getResponseWriter();
String id = component.getClientId(context);
boolean spanRendered = false;
if (label != null) {
renderOpenEncloser(component, context, "span", styles[8]); //NOI18N
spanRendered = true;
writer.writeText("\n", null);
if (!component.isLabelOnTop() && component.getRows() > 1) {
Map attributes = label.getAttributes();
Object styleClass = attributes.get("styleClass");
if (styleClass == null) {
attributes.put("styleClass", styles[9]);
} else if (styleClass.toString().indexOf(styles[9]) == -1) {
attributes.put("styleClass", styleClass + " " + styles[9]);
}
}
RenderingUtilities.renderComponent(label, context);
writer.writeText("\n", null);
if (component.isLabelOnTop()) {
writer.startElement("br", component); //NOI18N
writer.endElement("br"); //NOI18N
writer.writeText("\n", null);
}
writer.writeText("\n", null);
id = id.concat(ListSelector.LIST_ID);
}
if (readonly) {
UIComponent value = component.getReadOnlyValueComponent();
if (label == null) {
value.getAttributes().put("style", component.getStyle());
value.getAttributes().put("styleClass", component.getStyleClass());
}
RenderingUtilities.renderComponent(value, context);
} else {
//renderHiddenValue(component, context, writer, styles[8]);
//writer.writeText("\n", null);
// Because renderHiddenValue is commented out this needs
// to be called for supporting DB NULL values.
// If it becomes uncommented remove this call.
//
recordRenderedValue(component);
renderList(component, id, context, styles, label == null);
}
if (label != null) {
context.getResponseWriter().endElement("span"); //NOI18N
}
}
/**
* Overrides encodeChildren of Renderer to do nothing. This
* renderer renders its own children, but not through this
* method.
* @param context The FacesContext of the request
* @param component The component associated with the
* renderer. Must be a subclass of ListSelector.
*/
@Override
public void encodeChildren(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component)
throws java.io.IOException {
return;
}
/**
*
Renders the opening div tag.
* @param component The component associated with the
* renderer. Must implement ListManager
* @param context The FacesContext of the request
* @param element One of "span" or "div"
* @throws java.io.IOException if the renderer fails to write to
* the response
*/
protected void renderOpenEncloser(ListManager component,
FacesContext context,
String element,
String hiddenStyle)
throws IOException {
String id = component.getClientId(context);
ResponseWriter writer = context.getResponseWriter();
writer.writeText("\n", null);
writer.startElement(element, (UIComponent) component);
writer.writeAttribute("id", id, "id"); //NOI18N
String style = component.getStyle();
if (style != null && style.length() > 0) {
writer.writeAttribute("style", style, "style"); //NOI18N
}
style = component.getStyleClass();
if (component.isVisible()) {
if (style != null && style.length() > 0) {
writer.writeAttribute("class", style, "class"); //NOI18N
}
} else {
if (style == null) {
style = hiddenStyle;
} else {
style = style + " " + hiddenStyle; //NOI18N
}
writer.writeAttribute("class", style, "class"); //NOI18N
}
writer.writeText("\n", null); //NOI18N
}
protected void renderHiddenValue(UIComponent component, FacesContext context,
ResponseWriter writer, String hiddenStyle)
throws IOException {
ListManager listManager = (ListManager) component;
recordRenderedValue(component);
String hiddenID = component.getClientId(context).concat(ListSelector.VALUE_ID);
String hiddenLabelID = component.getClientId(context).concat(ListSelector.VALUE_LABEL_ID);
String[] values = listManager.getValueAsStringArray(context);
if (DEBUG) {
log("Values are: ");
for (int i = 0; i < values.length; ++i) {
log(String.valueOf(values[i]));
}
}
// Write a hidden label to pacify a11y checkers.
writer.startElement("label", component); //NOI18N
writer.writeAttribute("id", hiddenLabelID, null); //NOI18N
writer.writeAttribute("for", hiddenID, "for"); //NOI19N
writer.writeAttribute("class", hiddenStyle, null); //NOI18N
writer.endElement("label"); //NOI18N
// Write the hidden