cancel
Showing results for 
Search instead for 
Did you mean: 

displaying the checkbox created at runtime

Former Member
0 Kudos

hai all,

i have created the checkboxes at runtime but they are getting displayed in the same line.

i need to display them one after the other in next lines.please help me its urgent.

Thanks n Regards

Sharanya.R

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

create a container and set the layout as rowlayout.

Regards

Ayyapparaj

Former Member
0 Kudos

hai,

Thanks ayyaparaj.please help me in dynamic context creation which could be binded to the dynamically created checkbox.Its urgent.

Thanks n Regards

Sharanya.R

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

To solve the problem, I have created one Java class

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);

}

}

}

Now, to create context node in component controller, use following code,

List list = new ArrayList();

list.add("Label of check box");

............... .........................

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

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

To create check box, use following code in wdModifyView,

if(firstTime) {

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

IWDNodeInfo nodeInfo = node.getNodeInfo();

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

}

And to access the values of the check boxes in different view, put the following code in wdInit()

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

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

And in wdModifyView

if(firstTime) {

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

IWDNodeInfo nodeInfo = node.getNodeInfo();

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

}

Thanks,

Puspendu

Former Member
0 Kudos

hai puspendu,

thanks for the response.

iam using checkbox group and iam adding the elements at runtime.so user ll select the the checkboxes based on requirement and that selected values need to be passed to next view.

Thanks n Regards

Sharanya.R

Former Member
0 Kudos

Hi,

Refer this thread and try to close this.

Regards

Ayyapparaj

Former Member
0 Kudos

Any reason why you don't use a CheckBoxGroup?

Armin

Former Member
0 Kudos

hai,

no specific reasons for that.I have not used checkbox group til now so i dont have idea of using it.If you can help me in dynamically creating a context and binding the dynamically created checkbox group to that context it will be very helpful.its urgent.

Thanks n Regards

Sharanya.R

Former Member
0 Kudos

That was my guess. Using a CheckBoxGroup is much simpler here because you don't need to create the context structure programmatically but only the context data.

Example: Create a context node "Items" (cardinality=0:n, selection=0:n) with an attribute "text" (string) at designtime. Bind the CheckBoxGroup.texts property to the attribute "text".

At runtime, add elements to the "Items" node:


for (int i = 0; i < 3; ++i)
{
  IItemsElement e = wdContext.nodeItems().createItemsElement();
  wdContext.nodeItems().addElement(e);
  e.setText("Item #" + i);
}

This will give you a check box group with all boxes unchecked. To check the box at index i, you need to set the selection of the node at index i:


wdContext.nodeItems().setSelected(i, true);

To have each check box in a new line, set "colCount" = 1 for the check box group.

That's it.

Armin

Former Member
0 Kudos

hai armin,

In checkbox group by default there are 3 checkboxes.In my case it may vary from 1 to 25.whats the solution for that.

Thanks n regards

Sharanya.R

Edited by: Sharanya R on Feb 25, 2008 9:43 AM

Former Member
0 Kudos

Hi,

If you are using the above code , it contains only three elements.

Change the loop to match your requirement.( 1..25 elements as you mentioned)

Regards

Ayyapparaj

Former Member
0 Kudos

hai,

thanks .now in the displayed check boxes user may choose one to 3 options based on which next list of options needs to be provided . In that case how can i take the values of the selected checkboxes.

Thanks n Regards

Sharanya.R

Former Member
0 Kudos

Hi Sharanya,

For displaying 25 items in a check box Grp; first create a simple type and in its Enumeration tab give all the 25 values that you want. Assign this to the Context element and bind it with the CheckBox Grp.

This will work;

For your layout; use the Grid layout that positions UI elements( Check Boxes) one by one. (One more Option; use property "Column count" that also will help you in time)

Regards

- Vinod

*Reward me, if it helps you.

Former Member
0 Kudos

You aren't serious, are you?

Armin

Former Member
0 Kudos

need more info

Former Member
0 Kudos

Hi,

where you are adding the checkboxes.Under RootUIElement?

Then change the layout of the RootUIElement to GridLayout.

Regards,

Sudhir

Former Member
0 Kudos

Hi,

Change the layout of the group(or what ever container) to which you are adding to Gridlayout.

Regards,

Sudhir