cancel
Showing results for 
Search instead for 
Did you mean: 

How to bind a DropDown to something other than the lead selection?

Former Member
0 Kudos

Hi everybody,

I want to build a toolbar dynamically.

The context structure looks like this:


ToolbarButtons (non-singleton node)
  |
  +Items (non-singleton node)
  |  |
  |  +Text (string)
  |  +Value (string)
  |
  +Text (string)
  +Tooltip (string)
  +Type (int)

Each ToolbarButtonsElement with Type=1 represents a ToolbarButton, each ToolbarButtonsElement with Type=2 should be a ToolbarDropDownByIndex. If so, the Items in the DropDown are stored in Items node.

I create the UI Elements with the following code:


for (int i = 0; i < tbNode.size(); i++)
{
	IToolbarButtonsElement tbe = 
		(IToolbarButtonsElement)tbNode.getElementAt(i);

	IWDToolBarItem tbItem = null;
	if (tbe.getType() == TOOLBAR_TYPE_BUTTON){ (...) }
	else if (tbe.getType() == TOOLBAR_TYPE_DROPDOWN)
	{
		wdContext.nodeHeaderData()
			.nodeToolbarContents()
			.nodeToolbarButtons()
			.setLeadSelection(i);
		IWDToolBarDropDownByIndex tbDD = 
			(IWDToolBarDropDownByIndex)view.createElement(
				IWDToolBarDropDownByIndex.class, null);
				
		tbDD.setLabelText(tbe.getText());
		tbDD.setTooltip(tbe.getTooltip());
				
		IWDAttributeInfo ai = wdContext.nodeHeaderData()
			.nodeToolbarContents()
			.nodeToolbarButtons()
			.nodeItems()
			.getNodeInfo()
			.getAttribute("Text");

		tbDD.bindTexts(ai);
		tbItem = tbDD;
	}
	if (tbItem != null) tb.addToolBarItem(tbItem);
}

This works fine if I only have one dropdown. But if there is more than one, all the items of ALL dropdowns display the (same) Items of the last element of ToolbarButtons.

If I change the lead selection of ToolbarButtons, all the dropdown items change as well.

How can I bind the DropDown Texts to something other than the lead selection?

best regards,

Markus

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

First, why is the "ToolBarButtons" node a non-singleton?

Second, bind the ToolBarDropDownByIndex.texts property to the "Items" node in the i-th element of the ToolBarButtons node:


IWDToolBar toolBar = ...;
for (int i = 0, n = wdContext.nodeToolbarButtons().size(); i < n; ++i)
{
  IToolbarButtonsElement e = (IToolbarButtonsElement)
    wdContext.nodeToolbarButtons().getElementAt(i);
  IWDToolBarDropDownByIndex tbDD = (IWDToolBarDropDownByIndex)
    view.createElement(IWDToolBarDropDownByIndex.class, null);
  tbDD.setLabelText(e.getText());
  tbDD.setTooltip(e.getTooltip());
  tbDD.bindTexts(e.nodeItems().getNodeInfo().getAttribute("Text"));
  toolBar.addItem(tbDD);
}

Armin

Former Member
0 Kudos

Hi Armin,

this doesn't work either because

e.nodeItems().getNodeInfo().getAttribute("Text");

always gets me the absolutely same object which is connected to the lead selection of node ToolbarButtons. I've inserted some log outputs in the for loop which show the hash codes of the created objects. They show up like this:

com.sap.tc.webdynpro.clientserver.uielib.standard.impl.ToolBarDropDownByIndex@1170465 hash: 18285669

NodeElement(SiemensAppFrameCompView.HeaderData.ToolbarContents.ToolbarButtons.3) hash: 2203691

AttributeInfo(SiemensAppFrameCompView.HeaderData.ToolbarContents.ToolbarButtons.Items.Text) hash: <b>16540974</b>

-next loop-

com.sap.tc.webdynpro.clientserver.uielib.standard.impl.ToolBarDropDownByIndex@19a7266 hash: 26899046

NodeElement(SiemensAppFrameCompView.HeaderData.ToolbarContents.ToolbarButtons.5) hash: 13419753

AttributeInfo(SiemensAppFrameCompView.HeaderData.ToolbarContents.ToolbarButtons.Items.Text) hash: <b>16540974</b>

-next loop-

com.sap.tc.webdynpro.clientserver.uielib.standard.impl.ToolBarDropDownByIndex@193a289 hash: 26452617

NodeElement(SiemensAppFrameCompView.HeaderData.ToolbarContents.ToolbarButtons.7) hash: 26465608

AttributeInfo(SiemensAppFrameCompView.HeaderData.ToolbarContents.ToolbarButtons.Items.Text) hash: <b>16540974</b>

-next loop-

There you can see that the AttributeInfo object is always the same object and so all the dropdowns show the same entries. If I change the lead selection of ToolbarButtons at runtime (eg. by a table UIElement) the entries of all dropdowns change as well. That's not what I want!

Markus

Former Member
0 Kudos

You are right, my proposal was only wishful thinking

But nevertheless there is a solution to your problem:

Use separate root level nodes "DropdownItems#i" to provide the drop-down list items.

If you know the number of drop-down lists at design time (which you probably don't),

you can create these nodes at design time.

If not, you have to create them at runtime using the context API. (In the code shown below, I simply created two

nodes "DropdownItems0" and "DropdownItems1" at design time.)

When creating drop-down list #i, bind its "texts" property

to the "text" attribute of node "DropdownItems#i".

Sample code:

public static void wdDoModifyView(IPrivateDynamicToolbarView wdThis, IPrivateDynamicToolbarView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    if (firstTime)
    {
      IWDToolBar toolBar = (IWDToolBar) view.getElement("Toolbar");
      for (int i = 0, n = wdContext.nodeToolbarButtons().size(); i < n; ++i)
      {
        IToolbarButtonsElement e = (IToolbarButtonsElement)
          wdContext.nodeToolbarButtons().getElementAt(i);
        IWDToolBarDropDownByIndex tbDD = (IWDToolBarDropDownByIndex)
          view.createElement(IWDToolBarDropDownByIndex.class, null);
        tbDD.setLabelText(e.getText());
        tbDD.setTooltip(e.getTooltip());
        IWDAttributeInfo textAttribute = wdContext.getChildNode(
          "DropdownItems" + i, IWDNode.LEAD_SELECTION).getNodeInfo().getAttribute("Text");
        tbDD.bindTexts(textAttribute);
        tbDD.setOnSelect(wdThis.wdGetItemSelectAction());
        tbDD.mappingOfOnSelect().addParameter("dropdownIndex", i);
        toolBar.addToolBarItem(tbDD);
      }
    }
    //@@end
  }

  public void onActionItemSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int dropdownIndex )
  {
    //@@begin onActionItemSelect(ServerEvent)
    int itemIndex = wdContext.getChildNode("DropdownItems" + dropdownIndex, IWDNode.LEAD_SELECTION).getLeadSelection();
    wdComponentAPI.getMessageManager().reportSuccess(
      "Item selected, drop-down index=" + dropdownIndex + ", itemIndex=" + itemIndex
    );
    //@@end
  }


  public void wdDoInit()
  {
    //@@begin wdDoInit()
    {
      IToolbarButtonsElement e = wdContext.nodeToolbarButtons().createToolbarButtonsElement();
      wdContext.nodeToolbarButtons().addElement(e);
      e.setText("A");
      for (int i = 0; i < 3; ++i)
      {
        IDropdownItems0Element item = wdContext.nodeDropdownItems0().createDropdownItems0Element();
        wdContext.nodeDropdownItems0().addElement(item);
        item.setText(e.getText() + i);
      }
    }
    {
      IToolbarButtonsElement e = wdContext.nodeToolbarButtons().createToolbarButtonsElement();
      e.setText("B");
      wdContext.nodeToolbarButtons().addElement(e);
      for (int i = 0; i < 3; ++i)
      {
        IDropdownItems1Element item = wdContext.nodeDropdownItems1().createDropdownItems1Element();
        wdContext.nodeDropdownItems1().addElement(item);
        item.setText(e.getText() + i);
      }
    }
    //@@end
  }

Former Member
0 Kudos

Thank you Armin,

this works.

Answers (0)