| Method from org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer Detail: |
static int __getIndex(Object submittedValue,
List selectItems) {
if ("".equals(submittedValue))
return -1;
try
{
int index = Integer.parseInt(submittedValue.toString());
if (( -1 < index) && (countSelectItems(selectItems) > index))
{
return index;
}
else
{
// TODO Don't throw exception: message!
throw new IndexOutOfBoundsException(_LOG.getMessage(
"SELECTONE_SUBMITTEDVALUE_INDEX_OUTSIDE_BOUNDS", new Object[]{index, (selectItems.size() - 1)}));
}
}
catch (NumberFormatException ne)
{
// TODO Don't throw exception: message!
throw new NumberFormatException(_LOG.getMessage(
"SELECTONE_CANNOT_CONVERT_SUBMITTEDVALUE_INDEX_INTO_INTEGER", new Object[]{submittedValue.toString(), ne}));
}
}
Convert a stringified index into an index, with range-checking. |
protected void encodeAllAsElement(FacesContext context,
RenderingContext arc,
UIComponent component,
FacesBean bean) throws IOException {
Converter converter = getConverter(bean);
if ( converter == null)
converter = getDefaultConverter(context, bean);
boolean valuePassThru = getValuePassThru(bean);
if (isAutoSubmit(bean))
AutoSubmitUtils.writeDependencies(context, arc);
// Only add in validators and converters when we're in valuePassThru
// mode; otherwise, there's not enough on the client to even consider
FormData fData = arc.getFormData();
if (fData != null)
{
((CoreFormData) fData).addOnSubmitConverterValidators(component,
valuePassThru ? converter : null,
valuePassThru ? getValidators(bean) : null,
getClientId(context, component),
isImmediate(bean),
getRequired(bean),
getRequiredMessageKey());
}
List< SelectItem > selectItems = getSelectItems(component, converter, false);
int selectedIndex = _getSelectedIndex(context,
component,
bean,
selectItems,
converter,
valuePassThru);
ResponseWriter writer = context.getResponseWriter();
boolean simple = getSimple(bean);
if (simple)
{
writer.startElement("span", component);
// put the outer style class here, like af_selectOneRadio, styleClass,
// inlineStyle, 'state' styles like p_AFDisabled, etc.
renderRootDomElementStyles(context, arc, component, bean);
}
encodeElementContent(context,
arc,
component,
bean,
selectItems,
selectedIndex,
converter,
valuePassThru);
if (isHiddenLabelRequired(arc))
renderShortDescAsHiddenLabel(context, arc, component, bean);
if (simple)
{
writer.endElement("span");
}
}
|
abstract protected void encodeElementContent(FacesContext context,
RenderingContext arc,
UIComponent component,
FacesBean bean,
List selectItems,
int selectedIndex,
Converter converter,
boolean valuePassThru) throws IOException
|
public static boolean encodeOption(FacesContext context,
RenderingContext arc,
UIComponent component,
SelectItem item,
Converter converter,
boolean valuePassThru,
int index,
boolean isSelected) throws IOException {
if (item == null)
return false;
if (item.isDisabled())
{
if (!Boolean.TRUE.equals(arc.getAgent().getCapabilities().get(
TrinidadAgent.CAP_SUPPORTS_DISABLED_OPTIONS)))
return false;
}
Object itemValue = getItemValue(context,
component,
item,
converter,
valuePassThru,
index);
ResponseWriter writer = context.getResponseWriter();
writer.startElement("option", null);
if (item.isDisabled())
writer.writeAttribute("disabled", Boolean.TRUE, null);
// Never write out null, because that will result in the label
// getting submitted, instead of null.
if (itemValue == null)
itemValue="";
writer.writeAttribute("value", itemValue, null);
if (isSelected)
writer.writeAttribute("selected", Boolean.TRUE, null);
// For reasons that aren't especially clear to me, we're getting
// passed the empty string for our title.
String description = item.getDescription();
if ((description != null) && !"".equals(description))
writer.writeAttribute("title", description, null);
writer.writeText(item.getLabel(), null);
writer.endElement("option");
return true;
}
|
protected void findTypeConstants(FacesBean.Type type) {
super.findTypeConstants(type);
_valuePassThruKey = type.findKey("valuePassThru");
}
|
protected String getAutoSubmitScript(RenderingContext arc,
FacesBean bean) {
String source = LabelAndMessageRenderer.__getCachedClientId(arc);
boolean immediate = isImmediate(bean);
return AutoSubmitUtils.getSubmitScript(arc, source, XhtmlConstants.AUTOSUBMIT_EVENT, immediate);
}
|
public Object getConvertedValue(FacesContext context,
UIComponent component,
Object submittedValue) throws ConverterException {
boolean valuePassThru = getValuePassThru(getFacesBean(component));
if (!valuePassThru)
{
return _convertIndexedSubmittedValue(context, component, submittedValue);
}
else
{
return super.getConvertedValue(context, component, submittedValue);
}
}
|
public static Object getItemValue(FacesContext context,
UIComponent component,
SelectItem item,
Converter converter,
boolean valuePassThru,
int index) {
if (!valuePassThru)
{
return IntegerUtils.getString(index);
}
else
{
Object itemValue = item.getValue();
if ((itemValue != null) && (converter != null))
{
itemValue = converter.getAsString(context,
component,
itemValue);
}
return itemValue;
}
}
Return the value to output for an item. |
protected String getRequiredMessageKey() {
return UIXSelectOne.REQUIRED_MESSAGE_ID;
}
|
protected List getSelectItems(UIComponent component,
Converter converter) {
return getSelectItems(component, converter, false);
}
|
protected List getSelectItems(UIComponent component,
Converter converter,
boolean filteredItems) {
return SelectItemSupport.getSelectItems(component, converter, filteredItems);
}
|
protected Object getSubmittedValue(FacesContext context,
UIComponent component,
String clientId) {
Object submittedValue = super.getSubmittedValue(context,
component,
clientId);
if (submittedValue == null)
submittedValue = "";
return submittedValue;
}
|
protected String getUnselectedLabel(FacesBean bean) {
return null;
}
|
protected boolean getValuePassThru(FacesBean bean) {
Object o = bean.getProperty(_valuePassThruKey);
if (o == null)
o = _valuePassThruKey.getDefault();
assert(o != null);
return Boolean.TRUE.equals(o);
}
|
protected void renderNonElementContent(FacesContext context,
RenderingContext arc,
UIComponent component,
FacesBean bean) throws IOException {
// http://issues.apache.org/jira/browse/ADFFACES-151
// Getting default converter for null value leads to exception but
// if value of component is null than there is no need to perform
// this method
if (getValue(bean) == null)
return;
Converter converter = getConverter(bean);
if ( converter == null)
converter = getDefaultConverter(context, bean);
boolean valuePassThru = getValuePassThru(bean);
// =-=AEW If needed, this could be made more efficient
// by iterating through the list instead of getting
// all the items
List< SelectItem > selectItems = getSelectItems(component, converter, false);
int selectedIndex = _getSelectedIndex(context,
component,
bean,
selectItems,
converter,
valuePassThru);
// If an item is selected, get its label.
String text;
if (selectedIndex >= 0)
{
SelectItem item = selectItems.get(selectedIndex);
text = item.getLabel();
}
else
{
text = getUnselectedLabel(bean);
}
context.getResponseWriter().writeText(text, null);
}
|