cancel
Showing results for 
Search instead for 
Did you mean: 

How to preselect IWDCheckBoxGroup items programatically?

Former Member
0 Kudos

I am having trouble in preselecting IWDCheckBoxGroup items programatically..

I am using a IWDCheckBoxGroup to display following structure in context:

struct SSCRejectReason {

boolean itemSelected;

String reasonCode;

String reasonText;

}

There are 0..n number of records in that structure. The reasonText is bound to the "texts" property of my IWDCheckBoxGroup control. I am able to pass the information back and forth between my Web Dynpro -application and ERP (with normal parameter mapping in detecting which item the user checked in UI etc) just fine.

I need both get the input from the user and display it in the next phase. So far I haven't found a way to pre-select the IWDCheckBoxGroup values after I have populated my context with RFC/BAPI-execution.

After the RFC/BAPI-execution the display texts get populated beatufully as I assumed and if I loop my whole context structure through after the query I am able to see that the correct rows have itemSelected=True.

Since detecting which CheckBox was selected by user needed parameter mapping and two lines of code, how do I make the correct CheckBoxes pre-selected in doModifyView?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

maybe I have made wrong assumptions, don't know as I am bit puzzled at the moment.

The part of functionality I am dealing at the moment is for rejecting or accepting certain requests. The requester must know why the request got rejected etc.

So, I have this structure in my context:

struct RejectReason {

boolean itemSelected;

String reasonCode;

String reasonText;

}

The reasonCode is the actual value that get stored to ERP system. The reasonText is just the display text I want to display with CheckBoxes, the display texts come also from ERP system and are maintained there. There can be 0..n reasons for rejection in the business logic. Because of dynamic nature of the reason classification I chose to use IWDCheckBoxGroup.

By reading help.sap.com and SDN, I also found out that I need to map the parameters which are passed on the IWDCheckBoxGroup's Toggle-event, based on the "index" I know what CheckBox was ticked and based on "checked" I know whether it is on or off. I added the itemSelected property to my structure so that I know in my context which item should be selected. At this time I didn't know about the isMultiSelected method you mentioned.

Mapping in doModifyView:

wdContext.currentNavigationalHelperElement().setRejectReasonCheckBoxVisibility(WDVisibility.NONE);

IWDCheckBoxGroup checkBoxGroup = (IWDCheckBoxGroup)view.getElement("CheckBoxGroup");

checkBoxGroup.mappingOfOnToggle().addSourceMapping("checked", "checked");

checkBoxGroup.mappingOfOnToggle().addSourceMapping("index", "index");

Handling the user interaction:

public void onActionToggleRejectReason(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,

boolean checked, int index ){

//@@begin onActionToggleRejectReason(ServerEvent)

wdContext.nodeRejectReasons().setLeadSelection(index);

wdContext.currentRejectReasonsElement().setITEM_SELECTED(checked);

//@@end

}

When storing the user input to ERP system I just loop the whole context node and create/populate corresponding element in BAPI table structure if the boolean itemSelected is set to true.

So now the real question: After I have stored the selections to ERP, I am reading them back to another part of the application, the context gets populated nicely I get lines like:

itemSelected reasonCode reasonText

false 01 reason A

true 02 reason B

Also the CheckBoxGroup displays "reason A" and "reason B" but no checkmark for "reason B".

But I have no idea how to get the correct CheckBoxes selected..

Edited by: tero virta on Jan 8, 2008 3:05 PM

Former Member
0 Kudos

Remove the "itemSelected" attribute and use the multi-selection of the context node instead.

Armin

Answers (3)

Answers (3)

Former Member
0 Kudos

here you go,

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

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

hope this will be help.

Rahul

Former Member
0 Kudos

The selection of an IWDCheckBoxGroup element is completely determined by the multi-selection of the context node X containing the attribute to which you have bound the "texts" property.

When you check some boxes in the group, you can just use X.isMultiSelected(i) to find out if the check box #i is checked. Parameter mapping etc. is not needed.

In the opposite direction, if you call X.setSelected(i, true), the check box #i will be selected.

I don't understand the code below, where you change the lead selection. If you want to update the attribute "ITEM_SELECTED" in all node elements according to the multi-selection of the node, you have to do something like


for (int i = 0; i < wdContext.nodeSSCRejectReasons().size(); ++i)
{
  ISSCRejectReasonsElement e = wdContext.nodeSSCRejectReasons().getRejectReasonsElementAt(i);
  e.setITEM_SELECTED( wdContext.nodeSSCRejectReasons().isMultiSelected(i) );
}

Armin

Former Member
0 Kudos

You just have to set the multi-selection of this node after populating it. No need to do anything inside wdDoModifyView().

Armin