on 09-23-2013 8:21 AM
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?
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);
}
}
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!");
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.