cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Tray creation at runtime

Former Member
0 Kudos

hi experts,

we have a requirement where we are showing employee details in the tray UI element.

we have 1 tray at design time showing employee details obtained from a Bapi.

Now we need to display spouse details(if available) and children details(their number can be any~known at runtime) in seperate trays. eg each tray for 1 person..so if there are 6 children, there are 8 trays including one for employee and spouse...

Now what I need is the source code or method to dynamically generate tray at runtime along with the labels and textviews they contain..

thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

here is the code to create tray and textview element in it dynamically.

place this code in wdDoModifyView()

if(firstTime){

IWDTransparentContainer container =(IWDTransparentContainer)view.getElement("RootUIElementContainer");

IWDTray inputTray = (IWDTray)view.createElement(IWDTray.class, "tray");

IWDTextView test =(IWDTextView)view.createElement(IWDTextView.class, "test");

test.setText("Tray Created");

inputTray.addChild(test);

container.addChild(inputTray);

}

Regards,

ramesh

Edited by: Ramesh Babu V on Oct 15, 2008 5:45 PM

Answers (5)

Answers (5)

Former Member
0 Kudos

HI,

solved the problem....

i was doing some search here and there and finally got the code to do it. when i came back to the thread i found Ramesh suggested the same stuff which i had used.

thanks gurus.

I am writing my code here for other people looking for the same thing:

IWDTransparentContainer container =(IWDTransparentContainer)view.getElement("RootUIElementContainer");

wdContext.currentContextElement().setIpvalue("Demo Name"); //this is my context attribute.

for(int i=1;i<3;i++)

{

IWDTray tray=(IWDTray)view.createElement(IWDTray.class,null);

tray.setExpanded(false);

tray.setWidth("700px");

IWDLabel label=(IWDLabel)view.createElement(IWDLabel.class,null);

label.setText("your name is");

IWDTextView textview1=(IWDTextView)view.createElement(IWDTextView.class,null);

textview1.setText(wdContext.currentContextElement().getIpvalue());

IWDLabel label1=(IWDLabel)view.createElement(IWDLabel.class,null);

label1.setText("Employee age");

IWDCaption caption =(IWDCaption)view.createElement(IWDCaption.class,null);

caption.setText("WElcome to employee information");

tray.setHeader(caption);

IWDLayout layout=(IWDLayout)tray.createLayout(IWDMatrixLayout.class); //setting tray layout to matrix

IWDLayoutData layout1=(IWDLayoutData)label1.createLayoutData(IWDMatrixHeadData.class);

tray.addChild(label);

tray.addChild(textview1);

tray.addChild(label1);

container.addChild(tray);

P.S. Awarding points to Ramesh.

Former Member
0 Kudos

There are several things to do:

- Reserve some container "DynamicArea" inside your view for the dynamic area

- Add some boolean attribute "DynamicAreaNeedsUpdate" to the context to signal if the dynamic area needs update

- In method wdDoModifyView(), check the flag, update the dynamic area if needed, reset the flag

- In the method that loads new data, set the flag

Say your data are stored in a context structure like


Persons (node, c=0:n)
-- firstName (string)
-- lastName (string)
-- etc

Then the code to write will be something like


void wdDoModifyView(...)
{
  if ( wdContext.currentContextElement().getDynamicAreaNeedsUpdate() )
  {
    updateDynamicArea(/* same parameters as wdDoModifyView() */);
    wdContext.currentContextElement().setDynamicAreaNeedsUpdate(false);
  }
}

//@@begin others

private static void updateDynamicArea(...)
{
   IWDTransparentContainer dynamicArea = (IWDTransparentContainer ) view.getElement("DynamicArea");
   dynamicArea.destroyAllChildren();
   dynamicArea.createLayout(IWDRowLayout.class);
   for (int i = 0; i < wdContext.nodePersons().size(); ++i)
   {
     IPersonsElement p = wdContext.nodePersons().getPersonsElementAt(i);
     IWDTray tray = createTrayForPerson(p, /* other arguments */);
     tray.createLayoutData(IWDRowHeadData.class); /* put tray in new row */
     dynamicArea.addChild(tray);
   }
}

private static IWDTray createTrayForPerson(IPersonsElement p, /* other arguments */)
{
  IWDTray tray = view.createElement(IWDTray.class, null);
  IWDMatrixLayout layout = tray.createLayout(IWDMatrixLayout.class);
  layout.setStretchedHorizontally(false);
  {
    IWDLabel label = (IWDLabel) view.createElement(IWDLabel.class, null); 
    IWDTextView text = (IWDtextView) view.createElement(IWDTextView.class, null);
    label.setLabelFor(text.getId());
    label.createLayoutData(IWDMatrixHeadData.class); /* start new row */
    label.setText("Firstname");
    text.setText(p.getFirstName());
    tray.addChild(label);
    tray.addChild(text);
  }
  {
    IWDLabel label = (IWDLabel) view.createElement(IWDLabel.class, null); 
    IWDTextView text = (IWDtextView) view.createElement(IWDTextView.class, null);
    label.setLabelFor(text.getId());
    label.createLayoutData(IWDMatrixHeadData.class); /* start new row */
    label.setText("Lastname");
    text.setText(p.getLastName());
    tray.addChild(label);
    tray.addChild(text);
  }
  /* etc */
  return tray;
}

//@@end

Armin

Former Member
0 Kudos

Hi,

I am not sure, but try to work in wddomodifyview to create dynamic UI like

IWDTray tr= (IWDTray)view.createElement(abc,"ab");

Regards

Raghu

DeeptiChavare
Active Participant
0 Kudos

Hi Ankur,

The link [http://help.sap.com/saphelp_nw70/helpdata/EN/95/93fe1e71a2e44691b1f041e67f71aa/frameset.htm|http://help.sap.com/saphelp_nw70/helpdata/EN/95/93fe1e71a2e44691b1f041e67f71aa/frameset.htm] describes how to create UI elements at runtime.

You can use IWDTray interface to create a tray dynamically.

Former Member
0 Kudos

Hi Ankur,

I could not find out the code for dynamic tray creation but found out a work around. You can create a tray in Layout tab and bind its enabled property to boolean type attribute and than manipulate this attribute to show or hide the tray.