private UINode _createRangeNode()

in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/ui/laf/base/xhtml/NavigationBarRenderer.java [1269:1429]


  private UINode _createRangeNode(
    UIXRenderingContext context,
    UINode navBar,
    String destination,
    String name,
    String form,
    long   minValue,
    long   currentValue,
    int    blockSize,
    long    maxValue,
    String eventKey,
    String sourceKey,
    String sizeKey,
    String partialTargetsKey,
    String partialTargets
    )
  {
    UINode rangeNode = null;

    // if there is no blockSize to step by, or there are no items in the
    // table, then we don't render a choice
    if ((blockSize <= 0) ||
        ((maxValue < minValue) &&
         (maxValue != MAX_VALUE_UNKNOWN)))
    {
      rangeNode = _getEmptyRangeNode();
    }
    else if (/*(maxValue == MAX_VALUE_UNKNOWN) ||*/ !supportsScripting(context))
    {
      // we don't know the size, so use a label
      String rangeString = _getRangeString(context,
                                           navBar,
                                           currentValue,
                                           blockSize,
                                           maxValue,
                                           null);

      MarlinBean rangeLabel = new MarlinBean(STYLED_TEXT_NAME);
      
      rangeLabel.setAttributeValue(TEXT_ATTR, rangeString);
      rangeLabel.setAttributeValue(STYLE_CLASS_ATTR, NAV_BAR_VIEW_STYLE_CLASS);

      rangeNode = rangeLabel;
    }
    else
    {
      // we know the size, so use the choice control
      MarlinBean choice = new MarlinBean(CHOICE_NAME);

      choice.setAttributeValue(SHORT_DESC_ATTR,
                               getTranslatedValue(context, _CHOICE_TIP_KEY));

      String onChange = null;
      int selectedIndex;

      if (form == null)
      {
        // Bug #1765747: if we're trying to render a choice,
        // Netscape will get very unhappy if there isn't a form,
        // and render wacky output that pretty much trashes the
        // navbar.
        // If a client was _directly_ adding a choice, then this
        // would be their fault, and we wouldn't try to work around
        // it.  But the NavigationBar implicitly adds the choice
        // for them, and the Back/Next buttons are still useable
        // even without the choice.  So, the nice thing to do
        // is just make the choice read-only.
        if (requiresForm(context))
        {
          if (getParentFormName(context) == null)
          {
            // No form - turn on read-only
            choice.setAttributeValue(READ_ONLY_ATTR, Boolean.TRUE);
          }
        }

        // create each of the choice options for parameterized URLs
        selectedIndex = _addNavigationOptions(context, navBar, choice, false,
                                          minValue, maxValue, currentValue,
                                          blockSize, sizeKey);
        int count = choice.getIndexedChildCount(context);
        if (count > 1)
        {
          onChange = _getChoiceOnChange(context, 
                                        destination,
                                        sourceKey,
                                        eventKey,
                                        name,
                                        partialTargets,
                                        partialTargetsKey);
        }
        else
        {
          choice.setAttributeValue(READ_ONLY_ATTR, Boolean.TRUE);
        }
      }
      else
      {
        // create each of the choice options for form submit
        selectedIndex = _addNavigationOptions(context, navBar, choice, true,
                                          minValue, maxValue, currentValue,
                                          blockSize, sizeKey);
        int count = choice.getIndexedChildCount(context);
        if (count > 1)
        {
          onChange = _getChoiceOnChangeFormSubmitted(
                        context,
                        navBar,
                        form,
                        eventKey,
                        sourceKey,
                        name,
                        partialTargetsKey,
                        partialTargets);
        }
        else
        {
          choice.setAttributeValue(READ_ONLY_ATTR, Boolean.TRUE);
        }
      }

      if (onChange != null)
      {
        // set the onchange handler
        choice.setAttributeValue(ON_CHANGE_ATTR, onChange);

        // set the onfocus handler to save the initial value
        choice.setAttributeValue(ON_FOCUS_ATTR, _CHOICE_FORM_ON_FOCUS);
      }

      if (supportsID(context) &&
          (selectedIndex >= 0) &&
          !Boolean.TRUE.equals(choice.getAttributeValue(READ_ONLY_ATTR)))
      {
        String choiceId = XhtmlLafUtils.generateUniqueID(context);
        choice.setID(choiceId);

        StringBuffer text = new StringBuffer(26 + choiceId.length());
        text.append("_setSelectIndexById(\"");
        text.append(choiceId);
        text.append("\",");
        text.append(IntegerUtils.getString(selectedIndex));
        text.append(")");

        MarlinBean sb = new MarlinBean(SCRIPT_NAME);
        sb.setAttributeValue(TEXT_ATTR, text.toString());

        MarlinBean flb = new MarlinBean(FLOW_LAYOUT_NAME);
        flb.addIndexedChild(choice);
        flb.addIndexedChild(sb);

        rangeNode = flb;
      }
      else
      {
        rangeNode = choice;
      }
    }

    return rangeNode;
  }