cancel
Showing results for 
Search instead for 
Did you mean: 

Binding Checkbox Group to Context with Dictionary Enum (WD for Java)

Former Member
0 Kudos

Hello,

I see no examples in the documentation of binding a Checkbox Group to a context attribute that references a dictionary type with an enumeration. When I do so in NDS, it shows the checkboxes in the layout together with the values defined in the type's enumeration. However, when running the application, nothing comes up.

Any ideas or examples would be most welcome.

Thanks,

Martin

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Surya,

Create a button and in its onAction write the following code:

wdThis.wdFirePlugGotoSecond();

String val="";

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

{

IPrivateWDSampleView.ICheckBoxElement ele=wdContext.nodeCheckBox().getCheckBoxElementAt(i);

IPrivateWDSampleView.ICheckBoxNode node=wdContext.nodeCheckBox();

if(node.isMultiSelected(i)==true)

{

val = ele.getCheckBoxVals();

wdComponentAPI.getMessageManager().reportSuccess("These are the selected value"+val);

}

}

wdContext.currentCheckBoxElement().setCheckBoxVals(val);

Where CheckBox is my node name and CheckBoxVals is my attribute in it .

In the second view write the following code in the wdDoInit() method:

String a="";

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

{

a = wdContext.currentCheckBoxElement().getCheckBoxVals();

}

In your view layout bind your textview value to this attribute CheckboxVals.

Former Member
0 Kudos

Really?

How do you bind a <b>CheckBoxGroup </b>to a DDIC type with enumeration?

And in which version of NWDS do you see the enumeration values as individual checkboxes?

Armin

Former Member
0 Kudos

Thanks Sergei and Armin.

Sergei, the type is in fact a String, but I will look into your recommendation.

Armin, if I could post/send you some screenshots, you will see exactly what I mean. It actually makes most sense to me that you should be able to do this. The selected values should map back to individual elements under the node, surely?

Thanks.

Former Member
0 Kudos

The Javadoc for CheckBoxGroup says:

/**
 * Web Dynpro CheckBoxGroup API.
 *
 * <p>
 * The <code>CheckBoxGroup</code> UI element represents a multiple selection
 * visualized
 * as a group of checkboxes.
 * </p>
 * <p>
 * <strong>Data binding:</strong>
 * <br>
 * The property <code>texts</code> must be bound to an attribute
 * <code>Text</code> living in a context node <code>Values</code> of cardinality
 * <code>0..n</code> and selection <code>0..n</code>. The attribute
 * <code>Text</code> must have a simple type like <code>String</code>.
 * <br>
 * The number of checkboxes is the size of node <code>Values</code>. The
 * displayed texts are the values of  attribute <code>Text</code> and the
 * selection is the (multiple) selection of node
 * <code>Values</code>.
 * The check boxes are arranged into rows, the size of each row is limited by
 * property <code>colCount</code>.
 * </p>
 * <p>
 * <strong>Events:</strong>
 * <br>
 * If a checkbox is toggled, the event <code>onToggle</code> is triggered.
 * Event parameter
 * <code>checked</code> contains the new state of the checkbox, property
 * <code>index</code> contains the
 * index of the toggled checkbox.
 * </p>
 * </p>
 * <p>
 * This type can be called by applications using Web Dynpro, but DO NOT EXTEND OR IMPLEMENT IT!
 * </p>
 *
 * @author SAP
 * @SAPWebDynproPart 2
 */

From this you can see that the data binding model for CheckBoxGroup has nothing to do with DDIC types.

Armin

Former Member
0 Kudos

Hi Armin,

This technique works for other elements, such as the RadiobuttonGroupByKey. As a matter of fact, you can bind the value of an InputField to a context attribute that references a dictionary type with enumerations, and it will give you a dropdown where you can select one of the enumeration values. At least this works on SPS16. Maybe you are on a lower release.

What I mean to say with that is: The javadoc for WDRadiobuttonGroupByKey also does not mention DDIC, yet it works. (It is actually described elsewhere in the documentation).

Thanks anyway,

Martin

Former Member
0 Kudos

Yes, I know (I changed the author tag above

But what are we talking about, CheckBoxGroup or RadioButtonGroupByKey?

Armin

Former Member
0 Kudos

Thanks Armin.

I'm trying to get this working with a CheckBoxGroup. Is binding a CheckBoxGroup to a context attribute referencing a ddic type with enum is unsupported? If so, I find it strange that in the layout designer in NDS, when doing this binding, it actually shows the checkboxes, one for each value in the enumeration. (But when running the app, it shows nothing). What is the fundamental difference between the value binding of CheckBoxGroup and RadioButtonGroupByKey? (And why does this type of binding work for other elements like InputField?)

Thanks,

Martin

Former Member
0 Kudos

That's why I asked which version of the IDE you are using where the view designer allows this, because it makes no sense.

There are two completely different binding types: *ByIndex and *ByKey. CheckBoxGroup uses *ByIndex type only, other UI elements like DropDown allow both types which is indicated by the UI element names: DropDownByIndex, DropDownByKey.

The *ByKey binding uses a DDIC type with value set to get the individual items.

The *ByIndex binding uses the elements in a context node (and the node selection ) to get items and selection.

Armin

Former Member
0 Kudos

I see.

So are you saying, in effect, that this feature is not supported in WebDynpro for Java due to this restriction? Why is there no CheckBoxGroupByIndex and CheckBoxGroupByKey as with the other elements?

My NDS and WebDynpro installation are both on SPS16. My IDE has given me false hope

Former Member
0 Kudos

CheckBoxGroup is in fact CheckBoxGroupByIndex.

The *ByKey binding makes no sense for multiple selection elements.

Armin

Former Member
0 Kudos

However, the concept of multiple selection in the context is extended to a Table; you can have multiple selection in a table if in the context node your selection property is 0..n or 1..n. Could not a checkboxgroup conceptually be implemented in the same way? Perhaps this functionality is something to consider for a future release?

I think it would make life a lot easier

Thanks,

Martin

Former Member
0 Kudos

But that's exactly as the CheckBoxGroup works!?

This is *ByIndex binding.

Armin

Former Member
0 Kudos

OK, aside from the underlying workings of the components, here is what would be nice: Being able to put a checkbox group into your layout, and bind the Texts to a context attribute which maps to a ddic type with enumeration, such that you can read a list of all selected values from the context, the same way you would from a table where multiple selection has been enabled (assuming the attribute is in a node with 0..n cardinality etc. etc.).

Surely this would be possible to implement?

Martin

Former Member
0 Kudos

This makes no sense to me.

For a CheckBoxGroup(ByIndex),

- checkbox #i gets its text from an attribute A of node element #i of a node X with cardinality *:N

- checkbox #i is selected <=> element #i of node X is (multi-)selected

I don't see where a value set of an attribute's type fits in this model.

Armin

Former Member
0 Kudos

Hi Armin,

Thanks for the reply. I see now that I based my question on an incorrect assumption: I thought at runtime that the WebDynpro runtime populates the node with attribute nodes representing the values in an enumeration, if the attribute references a dictionary enumeration I see now that this is not the case.

(My theory was that if these elements are there, a selection of checkboxes should be obtainable by querying the relevant node in the context).

However, I still think there is a need for a checkbox group UI element that you can map to an attribute which in turn references a dictionary element with an enumeration, on the one hand to be consistent with the design of the other UI elements in WebDynpro, and also to make it easier for developers to produce such components, so that checkbox options don't have to be coded in a checkbox group.

What I'm proposing is that a UI element is needed representing a checkbox group, in which you can reference a dictionary type with enumeration, such that either:

1. The runtime populates attribute nodes in a node in the context with all the available values in the enumeration, and the selected values can be queried at runtime.

OR

2. Depending on the selection, attribute nodes are created inside the node in the context, one for each selected value.

Just to clear up any confusion: I'm not trying to make the existing CheckBoxGroup element do this. I understand this is not possible. That is why I'm saying a new element is needed that can provide this functionality.

Does this make sense?

Thanks and Regards,

Martin<b></b>

Former Member
0 Kudos

Hi Martin,

You can get the selected values at runtime.

IPrivate<ViewName>.I<Name>node node=wdContext.node<Name>();

int size=node.size();

for(int i=0;i<size;i++){

IPrivate<ViewName>.I<Name>Element element=node.get<Name>ElementAt(i);

if(node.isSelected(i)){

String selected=element.get<name>();

}

}

Check the Cardinality as 0..n and selected as 0..n

Kind Regards

Mukesh

Former Member
0 Kudos

Hi Mukesh,

Thank you code,i tried with ur code working fine displayed 3 check boxes with 3 texts at run time but small problem here i.e. whenever i select one two check boxes in that group i want to send selected check boxes texts to display text view of another view .

Please respond asap.

Thanks and regards,

surya.

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Martin

There is a bug in NW IDE regarding to non-string enumerations. If your enumeration has a numeric basic type IDE can save wrong .property file packed in .ear archive of the WD application. If so check enumeration texts contained in the .property file related to your simple type and recreate the simple type again to avoid the problem if the texts are missed in the file.

BR

Sergei