on 10-15-2008 10:45 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.