cancel
Showing results for 
Search instead for 
Did you mean: 

Automate check box group selections.

Former Member
0 Kudos

Hello there,

Is there a way to programmatically select checkbox group items and save them into the context.

Thanks

Srinivas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Check the below code

for(int i = 0; i < wdContext.nodeColor().size; i++)

{

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

}

this will give you all the checkboxes to true. You can make your own condition.

Former Member
0 Kudos

I still can't make the check box group selected at runtime based on a comparison from a string array.

Here is the code.


String[] officeList;
			officeList = wdContext.currentUser_Search_ResultsElement().getOffice_List().split(",");
	
		int adminOfficeIndex = -1;	
		while(finalCheckbox.hasNext()){			
			adminOfficeIndex++;
			String adminOffice = finalCheckbox.next().toString();		
			g_message_manager.reportSuccess("Admin Offices: "+adminOffice);		
				IPublicRepNetAdminComp.ICheckbox_GroupListElement officeNames =
						wdContext.createCheckbox_GroupListElement();
				wdContext.nodeCheckbox_GroupList().addElement(officeNames);	
				officeNames.setGroup_Names(adminOffice);
							//loop through user group to compare, if present make the selection
				for(int i =0; i < officeList.length ; i++){	
					g_message_manager.reportSuccess("User office looping: "+i);
					if(adminOffice.trim().equalsIgnoreCase(officeList<i>.trim())){
						g_message_manager.reportSuccess("Match found: "+officeList<i>+": "+ adminOfficeIndex);
						wdContext.nodeCheckbox_GroupList().setSelected(adminOfficeIndex, true);
						break;
					}								
				}
		}

Thanks

Srinivas

Former Member
0 Kudos

Hi,

Instead of the code wdContext.nodeCheckbox_GroupList().setSelected(adminOfficeIndex, true);

you can try to get the element first & then set the checked state

code would be like wdContext.nodeCheckbox_GroupList().getElement(officeNames).setSelected(true);

Kind Regards,

Nitin

Former Member
0 Kudos

I used this and it works:

wdContext.nodeCheckbox_GroupList().setSelected(Index, true);

Thanks all

Edited by: srinivas M on Feb 6, 2009 8:19 AM

sanyev
Active Participant
0 Kudos

Hi Srinivas,

You are doing the selection part completely wrong.

wdContext.nodeCheckbox_GroupList().setSelected(adminOfficeIndex, true);

.

The above code will not select a check box. This is used to select elements in a table.

First you have to check to which attributes the checkboxes are bound in the context. Let us know the context structure.

You should also know that Checkbox will take data only from the lead selected element of the context node. For instance you have a context node Checkbox_GroupList. The node should have a cardinality 1:1. If you have six checkboxes then you need to have six attributes of type boolean in that node. Each checkbox's checked property need to be bound to an attribute in the node Checkbox_GroupList node.

For selecting the checkbox the code should be some thing like this.

wdContext.nodeCheckbox_GroupList().currentCheckbox_GroupListElement().setCheckBox1(true);

Like wise all the six attribute values need to be checked.

In your case I guess you are comparing the attribute value with the contents of an array. If you know exactly what the names in officeList array is going to be then you can name the context attribute with the exact name then use your code like this,

String[] officeList;
			officeList = wdContext.currentUser_Search_ResultsElement().getOffice_List().split(",");	
		int adminOfficeIndex = -1;	
		while(finalCheckbox.hasNext()){			
			adminOfficeIndex++;
			String adminOffice = finalCheckbox.next().toString();		;		
				IPublicRepNetAdminComp.ICheckbox_GroupListElement officeNames =
						wdContext.createCheckbox_GroupListElement();
				wdContext.nodeCheckbox_GroupList().addElement(officeNames);	
				officeNames.setGroup_Names(adminOffice);
							//loop through user group to compare, if present make the selection
				for(int i =0; i < officeList.length ; i++){	
					if(adminOffice.trim().equalsIgnoreCase(officeList<i>.trim())){
						wdContext.nodeCheckbox_GroupList().currentCheckbox_GroupListElement().setAttributeValue(adminOffice.trim(), Boolean(true));
						break;
					}								
				}
		}

Make sure that you make the node Checkbox_GroupList cardinality 1:1 and name the attributes exactly the values in officeList.

Sanyev

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

u can write code like this

wdContext.currentContextElement().setCheck(true);

here check is the value attribute of type boolean. That attribute should be mapped to the checkbox property checked.

Regards,

H.V.Swathi

Former Member
0 Kudos

Thanks for your replies. Although, I didn't quite understand.

Here is my context

CheckBoxList (node)

|

>Value (attribute)

In the run time I have say 6 check boxes in this group. Now I have to make 3 of those check boxes checked. How should I write the code.

Regards

Srinivas

sanyev
Active Participant
0 Kudos

Hi Srinivas,

The IWDCheckBox has a mandatory property called checked which is bound to a boolean value. If you change the value of the boolean attribute to true programmatically at runtime then you can make the checkbox checked. So you have to set the boolean value to true to all the concerned checkboxes.

Regards,

Sanyev