| Method from com.sun.faces.renderkit.html_basic.HtmlBasicRenderer Detail: |
protected String augmentIdReference(String forValue,
UIComponent fromComponent) {
int forSuffix = forValue.lastIndexOf(UIViewRoot.UNIQUE_ID_PREFIX);
if (forSuffix < = 0) {
// if the for-value doesn't already have a suffix present
String id = fromComponent.getId();
int idSuffix = id.lastIndexOf(UIViewRoot.UNIQUE_ID_PREFIX);
if (idSuffix > 0) {
// but the component's own id does have a suffix
if (logger.isLoggable(Level.FINE)) {
logger.fine("Augmenting for attribute with " +
id.substring(idSuffix) +
" suffix from Id attribute");
}
forValue += id.substring(idSuffix);
}
}
return forValue;
}
Conditionally augment an id-reference value.
If the forValue doesn't already include a generated
suffix, but the id of the fromComponent does include a
generated suffix, then append the suffix from the
fromComponent to the forValue.
Otherwise just return the forValue as is.
|
public String convertClientId(FacesContext context,
String clientId) {
return clientId;
}
|
public void decode(FacesContext context,
UIComponent component) {
rendererParamsNotNull(context, component);
if (!(component instanceof UIInput)) {
// decode needs to be invoked only for components that are
// instances or subclasses of UIInput.
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"No decoding necessary since the component {0} is not an instance or a sub class of UIInput",
component.getId());
}
return;
}
if (!shouldDecode(component)) {
return;
}
String clientId = component.getClientId(context);
assert(clientId != null);
Map< String, String > requestMap =
context.getExternalContext().getRequestParameterMap();
// Don't overwrite the value unless you have to!
String newValue = requestMap.get(clientId);
if (newValue != null) {
setSubmittedValue(component, newValue);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"new value after decoding {0}",
newValue);
}
}
}
|
public void encodeEnd(FacesContext context,
UIComponent component) throws IOException {
rendererParamsNotNull(context, component);
if (!shouldEncode(component)) {
return;
}
ResponseWriter writer = context.getResponseWriter();
assert(writer != null);
String currentValue = getCurrentValue(context, component);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"Value to be rendered {0}",
currentValue);
}
getEndTextToRender(context, component, currentValue);
}
|
protected void encodeRecursive(FacesContext context,
UIComponent component) throws IOException {
// suppress rendering if "rendered" property on the component is
// false.
if (!component.isRendered()) {
return;
}
// Render this component and its children recursively
component.encodeBegin(context);
if (component.getRendersChildren()) {
component.encodeChildren(context);
} else {
Iterator< UIComponent > kids = getChildren(component);
while (kids.hasNext()) {
UIComponent kid = kids.next();
encodeRecursive(context, kid);
}
}
component.encodeEnd(context);
}
Render nested child components by invoking the encode methods
on those components, but only when the rendered
property is true.
|
protected Iterator getChildren(UIComponent component) {
int childCount = component.getChildCount();
if (childCount > 0) {
return component.getChildren().iterator();
} else {
return Collections.< UIComponent >emptyList().iterator();
}
}
|
protected String getCurrentValue(FacesContext context,
UIComponent component) {
if (component instanceof UIInput) {
Object submittedValue = ((UIInput) component).getSubmittedValue();
if (submittedValue != null) {
return (String) submittedValue;
}
}
String currentValue = null;
Object currentObj = getValue(component);
if (currentObj != null) {
currentValue = getFormattedValue(context, component, currentObj);
}
return currentValue;
}
|
protected void getEndTextToRender(FacesContext context,
UIComponent component,
String currentValue) throws IOException {
// no-op unless overridden
}
Renderers override this method to write appropriate HTML content into
the buffer. |
protected UIComponent getFacet(UIComponent component,
String name) {
UIComponent facet = null;
if (component.getFacetCount() > 0) {
facet = component.getFacet(name);
if ((facet != null) && !facet.isRendered()) {
facet = null;
}
}
return (facet);
}
|
protected UIComponent getForComponent(FacesContext context,
String forComponent,
UIComponent component) {
if (null == forComponent || forComponent.length() == 0) {
return null;
}
UIComponent result = null;
UIComponent currentParent = component;
try {
// Check the naming container of the current
// component for component identified by
// 'forComponent'
while (currentParent != null) {
// If the current component is a NamingContainer,
// see if it contains what we're looking for.
result = currentParent.findComponent(forComponent);
if (result != null) {
break;
}
// if not, start checking further up in the view
currentParent = currentParent.getParent();
}
// no hit from above, scan for a NamingContainer
// that contains the component we're looking for from the root.
if (result == null) {
result =
findUIComponentBelow(context.getViewRoot(), forComponent);
}
} catch (Exception e) {
// ignore - log the warning
}
// log a message if we were unable to find the specified
// component (probably a misconfigured 'for' attribute
if (result == null) {
if (logger.isLoggable(Level.WARNING)) {
logger.warning(MessageUtils.getExceptionMessageString(
MessageUtils.COMPONENT_NOT_FOUND_IN_VIEW_WARNING_ID,
forComponent));
}
}
return result;
}
Locates the component identified by forComponent |
protected String getFormattedValue(FacesContext context,
UIComponent component,
Object currentValue) throws ConverterException {
return getFormattedValue(context, component, currentValue, null);
}
|
protected String getFormattedValue(FacesContext context,
UIComponent component,
Object currentValue,
Converter converter) throws ConverterException {
// formatting is supported only for components that support
// converting value attributes.
if (!(component instanceof ValueHolder)) {
if (currentValue != null) {
return currentValue.toString();
}
return null;
}
if (converter == null) {
// If there is a converter attribute, use it to to ask application
// instance for a converter with this identifer.
converter = ((ValueHolder) component).getConverter();
}
if (converter == null) {
// if value is null and no converter attribute is specified, then
// return a zero length String.
if(currentValue == null) {
return "";
}
// Do not look for "by-type" converters for Strings
if (currentValue instanceof String) {
return (String) currentValue;
}
// if converter attribute set, try to acquire a converter
// using its class type.
Class converterType = currentValue.getClass();
converter = Util.getConverterForClass(converterType, context);
// if there is no default converter available for this identifier,
// assume the model type to be String.
if (converter == null) {
return currentValue.toString();
}
}
return converter.getAsString(context, component, currentValue);
}
Overloads getFormattedValue to take a advantage of a previously
obtained converter. |
protected Iterator getMessageIter(FacesContext context,
String forComponent,
UIComponent component) {
Iterator messageIter;
// Attempt to use the "for" attribute to locate
// messages. Three possible scenarios here:
// 1. valid "for" attribute - messages returned
// for valid component identified by "for" expression.
// 2. zero length "for" expression - global errors
// not associated with any component returned
// 3. no "for" expression - all messages returned.
if (null != forComponent) {
if (forComponent.length() == 0) {
messageIter = context.getMessages(null);
} else {
UIComponent result = getForComponent(context, forComponent,
component);
if (result == null) {
messageIter = Collections.EMPTY_LIST.iterator();
} else {
messageIter =
context.getMessages(result.getClientId(context));
}
}
} else {
messageIter = context.getMessages();
}
return messageIter;
}
|
protected HtmlBasicRenderer.Param[] getParamList(UIComponent command) {
if (command.getChildCount() > 0) {
ArrayList< Param > parameterList = new ArrayList< Param >();
for (UIComponent kid : command.getChildren()) {
if (kid instanceof UIParameter) {
UIParameter uiParam = (UIParameter) kid;
Object value = uiParam.getValue();
Param param = new Param(uiParam.getName(),
(value == null ? null :
value.toString()));
parameterList.add(param);
}
}
return parameterList.toArray(new Param[parameterList.size()]);
} else {
return EMPTY_PARAMS;
}
}
|
public boolean getRendersChildren() {
return true;
}
|
protected Object getValue(UIComponent component) {
// Make sure this method isn't being called except
// from subclasses that override getValue()!
throw new UnsupportedOperationException();
}
|
protected void rendererParamsNotNull(FacesContext context,
UIComponent component) {
Util.notNull("context", context);
Util.notNull("component", component);
}
|
protected void setSubmittedValue(UIComponent component,
Object value) {
// no-op unless overridden
}
Renderers override this method to store the previous value
of the associated component. |
protected boolean shouldDecode(UIComponent component) {
if (Util.componentIsDisabledOrReadonly(component)) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"No decoding necessary since the component {0} is disabled or read-only",
component.getId());
}
return false;
}
return true;
}
|
protected boolean shouldEncode(UIComponent component) {
// suppress rendering if "rendered" property on the component is
// false.
if (!component.isRendered()) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"End encoding component {0} since rendered attribute is set to false",
component.getId());
}
return false;
}
return true;
}
|
protected boolean shouldEncodeChildren(UIComponent component) {
// suppress rendering if "rendered" property on the component is
// false.
if (!component.isRendered()) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"Children of component {0} will not be encoded since this component's rendered attribute is false",
component.getId());
}
return false;
}
return true;
}
|
protected boolean shouldWriteIdAttribute(UIComponent component) {
String id;
return (null != (id = component.getId()) &&
!id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX));
}
|
protected String writeIdAttributeIfNecessary(FacesContext context,
ResponseWriter writer,
UIComponent component) {
String id = null;
if (shouldWriteIdAttribute(component)) {
try {
writer.writeAttribute("id", id = component.getClientId(context),
"id");
} catch (IOException e) {
if (logger.isLoggable(Level.WARNING)) {
String message = MessageUtils.getExceptionMessageString
(MessageUtils.CANT_WRITE_ID_ATTRIBUTE_ERROR_MESSAGE_ID,
e.getMessage());
logger.warning(message);
}
}
}
return id;
}
|