in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/NavigationBarRenderer.java [180:567]
private void _renderSingleItemNavigator(
UIXRenderingContext context,
UINode navBar,
String eventKey,
String sourceKey,
String valueKey,
String sizeKey,
String partialTargetsKey,
String partialTargets
)
throws IOException
{
Number result;
// get current value
result = (Number)navBar.getAttributeValue(context, VALUE_ATTR);
long currentValue = (result != null)
? result.longValue()
: 1;
// get max value
long totalItems;
int childCount = navBar.getIndexedChildCount(context);
if (childCount > 0)
{
totalItems = childCount;
}
else
{
result = (Number)navBar.getAttributeValue(context, MAX_VALUE_ATTR);
totalItems = (result != null)
? result.longValue()
: MAX_VALUE_UNKNOWN;
}
boolean showBackButton = (currentValue > 1);
boolean showNextButton = ((totalItems == MAX_VALUE_UNKNOWN) ||
(currentValue < totalItems));
// bail if no buttons shown or values are bogus
if ((!showBackButton && !showNextButton) ||
((currentValue > totalItems) && (totalItems != MAX_VALUE_UNKNOWN)) ||
(currentValue < MAX_VALUE_UNKNOWN))
return;
// get form name (#1308799)
String formName = XhtmlLafUtils.getParentFormName(context);
// If we don't support navigation (e.g., printable pages),
// lie and claim we support scripting (even though we probably don't).
// This will give us the highest fidelity output - that is,
// we avoid creating submit buttons.
boolean supportsScripting = (supportsScripting(context) ||
!supportsNavigation(context));
if ((formName != null) && supportsScripting)
{
// render hidden fields to hold the form data
renderHiddenFields( context,
formName,
false,
eventKey,
sourceKey,
valueKey,
sizeKey,
partialTargetsKey,
partialTargets);
}
// get name
String nameString = _getNameString(context, navBar);
UINode backButton = null;
UINode nextButton = null;
// set up the back button
if (showBackButton)
{
BoundValue buttonTextandAccessKeyBV =
new SkinTranslatedBoundValue( _SINGLE_BACK_TEXT_KEY);
Object buttonTextBV = new AccessKeyBoundValue(buttonTextandAccessKeyBV,
false);
Object buttonAccessKeyBV = new AccessKeyBoundValue(
buttonTextandAccessKeyBV,
true);
// set the destination.
if (formName == null)
{
backButton = createSingleItemURLButton(
context,
true,
buttonTextBV,
buttonAccessKeyBV,
getSingleDestinationURL(context,
navBar,
eventKey,
sourceKey,
nameString,
valueKey,
currentValue-1));
}
else
{
if (supportsScripting)
{
backButton = createSingleItemSubmitButton(
context,
true,
buttonTextBV,
buttonAccessKeyBV,
getSingleDestinationSubmit( context,
navBar,
formName,
eventKey,
sourceKey,
nameString,
valueKey,
currentValue - 1,
false));
}
else
{
backButton = createSubmitButton(context,
buttonTextBV,
buttonAccessKeyBV,
null,
formName,
false,
eventKey,
sourceKey,
nameString,
valueKey,
currentValue - 1,
null,
-1);
}
}
}
// set up the next button
if (showNextButton)
{
String buttonTextKey = ((totalItems == 2)
? _SINGLE_CONTINUE_TEXT_KEY
: _SINGLE_NEXT_TEXT_KEY);
BoundValue buttonTextandAccessKeyBV =
new SkinTranslatedBoundValue(buttonTextKey);
Object buttonTextBV = new AccessKeyBoundValue( buttonTextandAccessKeyBV,
false);
Object buttonAccessKeyBV = new AccessKeyBoundValue(
buttonTextandAccessKeyBV,
true);
// The navBar needs its initial focus to be on the Next button,
// according to the BLAF. Render a special id on the Next button
// if this navBar is to have the initial focus. (unless it needs
// initial focus, the Next button does not have an id on it)
String buttonID = _getIDForFocus(context, navBar);
if (formName == null)
{
MutableUINode mutableNextButton =
createSingleItemURLButton(
context,
false,
buttonTextBV,
buttonAccessKeyBV,
getSingleDestinationURL(context,
navBar,
eventKey,
sourceKey,
nameString,
valueKey,
currentValue+1));
if (buttonID != null)
{
mutableNextButton.setID(buttonID);
}
nextButton = mutableNextButton;
}
else
{
// set the destination
if (supportsScripting)
{
MutableUINode mutableNextButton =
createSingleItemSubmitButton(
context,
false,
buttonTextBV,
buttonAccessKeyBV,
getSingleDestinationSubmit(
context,
navBar,
formName,
nameString,
currentValue + 1,
true));
if (buttonID != null)
{
mutableNextButton.setID(buttonID);
}
nextButton = mutableNextButton;
}
else
{
nextButton = createSubmitButton(context,
buttonTextBV,
buttonAccessKeyBV,
buttonID,
formName,
false,
eventKey,
sourceKey,
nameString,
valueKey,
currentValue + 1,
null,
-1);
}
}
}
// start the rendering
ResponseWriter writer = context.getResponseWriter();
boolean renderAsTable = _renderAsTable(context, navBar);
if (renderAsTable)
{
writer.startElement("table", navBar.getUIComponent());
renderLayoutTableAttributes(context, "0", null);
renderID(context, navBar);
writer.startElement("tr", null);
}
// we only want to render the ID in the "td" if renderAsTable is false.
// render the base ID the first time only, then we render the subIDs.
_renderStartTableCell(context, navBar, writer, renderAsTable, true);
// don't render back button on first step
if (showBackButton)
{
backButton.render(context);
writer.endElement("td");
_renderSpacerCell(context);
// we only want to render the ID in the "td" if renderAsTable is false.
// render the subID.
_renderStartTableCell(context, navBar, writer, renderAsTable, false);
}
//
// create the label and render it
//
writer.writeAttribute(NOWRAP_ATTRIBUTE, Boolean.TRUE, null);
// Now, we create one of two things. Normally, we'll create
// a simple range string. But, when there are link children,
// we create a ChoiceBean
if ((childCount == 0) ||
// No form when we require one means no choice
((formName == null) && requiresForm(context)) ||
// No scripting also means no choice
!supportsScripting(context))
{
// No "Step 1 of X" when there's 1 or two steps
if (totalItems > 2)
{
// the string to be displayed between buttons
String rangeString = _getRangeString(context,
navBar,
currentValue,
SINGLE_STEP,
totalItems,
null);
MarlinBean stepLabel = new MarlinBean(STYLED_TEXT_NAME);
stepLabel.setAttributeValue(TEXT_ATTR, rangeString);
stepLabel.setStyleClass(NAV_BAR_VIEW_STYLE_CLASS);
stepLabel.render(context);
}
}
else
{
// Gather the children
DataObjectList links = LinkDataObject.getLinkDataList(context,
navBar);
MarlinBean choice = new MarlinBean(CHOICE_NAME);
int maxVisited = (int) currentValue;
Object maxVisitedObj = navBar.getAttributeValue(context,
MAX_VISITED_ATTR);
if (maxVisitedObj instanceof Number)
maxVisited = ((Number) maxVisitedObj).intValue();
// Sanity check the "maxVisited" attribute
maxVisited = Math.min(maxVisited,
links == null ? 0 : links.getLength());
// Add one option per link, but only go up to the "maxVisited"
// value. (BTW, since maxVisited is 1-indexed, but i is 0-indexed,
// this is an _inclusive_ range here)
for (int i = 0; i < maxVisited; i++)
{
DataObject link = links.getItem(i);
MarlinBean option = new MarlinBean(OPTION_NAME);
option.setAttributeValue(TEXT_ATTR,
link.selectValue(context, TEXT_ATTR));
option.setAttributeValue(VALUE_ATTR, IntegerUtils.getString(i + 1));
if (currentValue == i + 1)
option.setAttributeValue(SELECTED_ATTR, Boolean.TRUE);
choice.addIndexedChild(option);
}
if (choice.getIndexedChildCount(context) > 0)
{
String onChange;
// get name
String name = _getNameString(context, navBar);
// Two options: formSubmitted mode and non-formSubmitted mode.
// First, non-formSubmitted mode.
if (formName == null)
{
onChange = _getChoiceOnChange(context,
_getDestinationString(context, navBar),
sourceKey,
eventKey,
name,
null,
null);
}
else
{
onChange = _getChoiceOnChangeFormSubmitted(context,
navBar,
formName,
eventKey,
sourceKey,
name,
partialTargetsKey,
null);
}
choice.setAttributeValue(ON_CHANGE_ATTR, onChange);
}
else
{
choice.setAttributeValue(READ_ONLY_ATTR, Boolean.TRUE);
}
choice.render(context);
}
// don't render the next button on last step
if (showNextButton)
{
writer.endElement("td");
_renderSpacerCell(context);
_renderStartTableCell(context, navBar, writer, renderAsTable, false);
nextButton.render(context);
}
writer.endElement("td");
if (renderAsTable)
{
writer.endElement("tr");
writer.endElement("table");
}
}