cancel
Showing results for 
Search instead for 
Did you mean: 

I want to limit the selection of checkboxes to 5 in a table in webdynpro java 7.3.I need a error message if the selection of checkboxes exceeds 5. Can you suggest any solution for this?

Former Member
0 Kudos

I want to limit the selection of checkboxes to 5 in a table in webdynpro java 7.3.I need a error message if the selection of checkboxes exceeds 5. Can you suggest any solution for this?

Accepted Solutions (1)

Accepted Solutions (1)

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

how about this one?

Create a context node this way:

where checkbox is boolean, text is a string.

Create a table UI element based on this context.

Initialize the content in wdDoInit():

public void wdDoInit()

  {

    //@@begin wdDoInit()

IPrivateCBoxCompView.ITabElement tab;

    

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

    tab = wdContext.nodeTab().createTabElement();

    tab.setCheckbox(false);

    tab.setText("text"+i);

    wdContext.nodeTab().addElement(tab);

   }

    //@@end

  }

Then write the following event for the checkbox's onToggle event:

public void onActionCheckitems(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

  {

    //@@begin onActionCheckitems(ServerEvent)

   boolean morethan5 = false;

   int j = 0;

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

    wdContext.nodeTab().setLeadSelection(i);

    if (wdContext.currentTabElement().getCheckbox()) j++;

    if (j>5) morethan5 = true;   

   }

  

   if (morethan5) {

   IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

   msgMgr.reportException("error, more than 5 items selected!");

   }

    //@@end

  }

It looks as follows in runtime:

you can select the elements:

but once you check the the 6th checkbox it reports the error:

Is it what you wanted to achieve? I hope this helps.

Best Regards,

Ervin

Sharathmg
Active Contributor
0 Kudos

To add a slight modification to the solution by Ervin,

the code could be modified to node.isMultiselected(<for loop index> );

Just to avoid setting the lead selection.

Regards,

Sharath

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sharath,

yes, I also had the problematic of setting the lead selection. Could you please elaborate your solution?

Perhaps not everyone is clear on how you meant it and so it could come in handy for future search for other customers.

Cheers, 😉

Ervin

Sharathmg
Active Contributor
0 Kudos

Lead selection on an element in a table leads to a server round trip.

A definite impact on the performance.

Keeping this in mind, in WDJ, it is recommended to use the table mode as nw04s instead of auto. With mode as auto, if a user clicks on any row, the framework performs a server round trip to set the row as lead-selected. To avoid this, it is recommended to use nw04s mode and handle the user's selection by code.

In this scenario, as the user will select the check box, there would not be any need to perform a lead-selection. Instead loop through the contents of the node and check if the element is selected(using the method isMultiselected(index) ). This avoid additional steps of setting lead-selection and the resulting server round trip.

Thanks Ervin.

Its open for your feedback.

Regards,

Sharath

Former Member
0 Kudos

Thank you Ervin,

I got resolved for this issue.

It was very helpful

Former Member
0 Kudos

Hi Sharath,

thank you so much

Your information added in the context gave a needful help.

Thank for your support

Former Member
0 Kudos

@Sharath

Can you explain in detail what performance benefits of your approach vs Ervin code? Where server round trips will occur in Ervin code?

Sharathmg
Active Contributor
0 Kudos

Ervin's code:

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

    wdContext.nodeTab().setLeadSelection(i); - At this point a server round trip.

    if (wdContext.currentTabElement().getCheckbox()) j++;

    if (j>5) morethan5 = true;   

   }

If the loop if for N number of check boxes, the round trip is done N number of times. This can be avoided.

Only check the element is selected using one line in the for loop. If yes, increment the counter.

Regards,

Sharath

Former Member
0 Kudos

If I'm not mistaken action handler is executed on server side. Can you explain what server round trips do you mean?

Sharathmg
Active Contributor
0 Kudos

Yes. When u click on action handler, following happens:

1. a request is sent to server

2. Execution of the code on the server

3. Response from the server

When lead selection is changed, following happens:

1. a request is sent to server

2. web dynpro framework sets the selection of the element as row in table

3. returns the response to user.

This is server round trip .

Regards,

Sharath

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sharath,

yes, but as of 710 there is no way to set the mode to nw04s, or is it? Which table UI parameter do you mean? Can you please also provide a small code snippet how you would modify the above code?

Thank you so much!

Best Regards,

Ervin

Former Member
0 Kudos

With user action to change lead selection it is true - the server round trip occur. But when you change lead selection from action handler no server round trip occur (in my opinion) - the code already on server side. Your comments about this?

Sharathmg
Active Contributor
0 Kudos

Well, that is a possibility. Need to check to confirm.

Regards,

Sharath

Sharathmg
Active Contributor
0 Kudos

Hello Ervin,

Unfortunately, I am currently working on NW 7.02. Need to check the settings in NW7.2

In 7.0, the property is : compatibility mode

ErvinSzolke
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sharath,

I know this property on 70X but on >= 710 such a feature is not available.

Regards,

Ervin

Answers (0)