cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic context creation

Former Member
0 Kudos

hai all,

when i create a context in runtime ll the attributes created at runtime be available in the context of my view after i run the application?

as i need to get the values of the dynamically created attributes and provide the next view based on that i need to know how the values can be set to the dynamically created attributes and how they can be used.please provide me with complete solution and solve the problem.

Thanks n regards

Sharanya.R

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

To solve your problem, create a class as follows,

public class UIHandler {

/*

  • Call this method to create node in Component controller as the data should be shared among

  • multiple views

  • @param rootInfo is NodeInfo for wdContext in Component Controller

  • @param name of Value node to be created

  • @param Collection represents the list of attributes to be created for check boxes

*/

public static IWDNodeInfo createChildNode(

IWDNodeInfo rootInfo,

String name,

Collection collection) {

IWDNodeInfo node =

rootInfo.addChild(

name,

null,

true,

true,

false,

true,

false,

true,

null,

null,

null);

for (Iterator iter = collection.iterator(); iter.hasNext();) {

String str = (String) iter.next();

node.addAttribute(str, "com.sap.dictionary.boolean");

}

return node;

}

/*

  • Call this method to create node in view to create list of check boxes

*/

public static IWDNodeInfo createMappedChildNode(

IWDNodeInfo nodeInfoOrigin,

IWDNodeInfo rootInfo,

String name) {

IWDNodeInfo nodeInfoView =

rootInfo.addMappedChild(

name,

null,

nodeInfoOrigin.isSingleton(),

nodeInfoOrigin.isMandatorySelection(),

nodeInfoOrigin.isMultiple(),

nodeInfoOrigin.getPathDescription(),

false,

true);

for (Iterator iter = nodeInfoOrigin.iterateAttributes();

iter.hasNext();

) {

IWDAttributeInfo attrInfo = (IWDAttributeInfo) iter.next();

nodeInfoView.addMappedAttribute(

attrInfo.getName(),

attrInfo.getName());

}

return nodeInfoView;

}

/*

  • Create list of check boxes

*/

public static void createCheckBoxes(

IWDView view,

String rootContainerName,

IWDNodeInfo nodeInfo) {

IWDTransparentContainer rootCont =

(IWDTransparentContainer) view.getElement(rootContainerName);

IWDTransparentContainer cont =

(IWDTransparentContainer) view.createElement(

IWDTransparentContainer.class,

"Container");

IWDGridLayout layout =

(IWDGridLayout) cont.createLayout(IWDGridLayout.class);

layout.setColCount(2);

rootCont.addChild(cont);

for (Iterator iter = nodeInfo.iterateAttributes(); iter.hasNext();) {

IWDAttributeInfo attrInfo = (IWDAttributeInfo) iter.next();

IWDLabel label =

(IWDLabel) view.createElement(

IWDLabel.class,

attrInfo.getName());

label.setText(attrInfo.getName());

IWDCheckBox cbx =

(IWDCheckBox) view.createElement(

IWDCheckBox.class,

attrInfo.getName() + "cbx");

cbx.bindChecked(attrInfo);

label.setLabelFor(cbx.getId());

cont.addChild(label);

cont.addChild(cbx);

}

}

}

Then create component controller context as follows,

IWDNodeInfo nodeInfo = UIHandler.createChildNode(wdThis.wdGetTestController().wdGetContext().getNodeInfo(), "Data", list);

Here list is a collection of String values to represent the labels.

And then create context for view

UIHandler.createMappedChildNode(nodeInfo, wdContext.getNodeInfo(), "Data");

Now Create Check boxes,

if(firstTime) {

IWDNode node = wdContext.getChildNode("Data", 0);

IWDNodeInfo nodeInfo = node.getNodeInfo();

UIHandler.createCheckBoxes(view, "RootUIElementContainer", nodeInfo);

}

Thus you are ready with creation of check boxes. If you want to access values of the check boxes in another view, use following code,

In wdInit() {

IWDNodeInfo nodeInfo = wdThis.wdGetTestController().wdGetContext().getChildNode("Data", 0).getNodeInfo();

UIHandler.createMappedChildNode(nodeInfo, wdContext.getNodeInfo(), "Data");

}

And in view

if(firstTime) {

IWDNode node = wdContext.getChildNode("Data", 0);

IWDNodeInfo nodeInfo = node.getNodeInfo();

UIHandler.createCheckBoxes(view, "RootUIElementContainer", nodeInfo);

}

Former Member
0 Kudos

Are you sure that you really need to create the context structure programmatically? This is "normally" not needed.

Armin

Former Member
0 Kudos

hai armein,

I need to create the chekboxes based on user selection .also based on user selection in checkbox the sub levels should be displayed.if i go for static it ll take 1000 views to do that.so iam going for dynamic ones.

Thanks n regards

Sharanya.R

Former Member
0 Kudos

Hi,

Just a suggestion for your problem. Why dont you add everything statically and on user selection make sublevel visibility to none and visible.

thanks & regards,

Manoj

Former Member
0 Kudos

hai manoj,

i need to display checkboxes for user selection dynamically and they user may select more than one value in the checkboxes based on which i need to display another set of checkbox which needs context values .but the levels are 25 and for each level 25 sublevels are there.so statical creation of context is tedious.suggest me a way wch helps me to do this.

Thanks n Regards'

Sharanya.R