on 02-27-2006 3:04 PM
HI,
I have a Webdynpro table with two columns, the first colum displays Company Names and the Second one Company Nodes.
I would like to sort the fist column by Company Name and the second one by Company codes,
i have gone through the following tutorial
but its bit difficult to understand..
is there any simple steps and code..
Murali
Define actions "SortByName" and "SortByCode" that sort the node element collection of the table. Use method IWDNode.sortElements(Comparator).
Assign these actions to the "onAction" event of the table columns which is triggered whenever the column header is clicked.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you tell me the steps
currently i called company code bapi, and company Name and code are displayed in two colums,
as per your suggestion i created two actions
sortByCompanyName,and sortByCompanyCode.
where do i have to attach these actions..
if i see the context,
1)Bapi_Companycode_Getlist_Input
- Output |
-CompanyCode_List
|
- Company_Name
- Company_Code
2) Do i need to create a node sort of thing, i am not getting how to proceed further..
I can see event for table UI element
OnFilter and OnLeadSelect
Murali
Message was edited by: Murali Manohar
All that i did is excuted company code Bapi.
public static void wdDoModifyView(IPrivateTableCompatibilityModeView wdThis, IPrivateTableCompatibilityModeView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
if (firstTime) {
IWDTable tablec = (IWDTable) view.getElement("CompanyTable");
wdContext.currentContextElement().setTableSorter(
new TableSorter(tablec, wdThis.wdGetSortByCompanyNameAction(), null));
}
//@@end
}
========================
public void onActionsortByCompanyName(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionsortByCompanyName(ServerEvent)
wdContext.currentContextElement().getCCodeSorter().sort(
wdEvent,
wdContext
.nodeBapi_Companycode_Getlist_Input()
.nodeOutput()
.nodeCompanycode_List());
//@@end
}
after clicking on the header of the table following is the error stack
=======================
java.lang.NullPointerException
at com.sap.tut.wd.tutwd_table.tablecomp.TableCompatibilityModeView.onActionsortByCompanyName(TableCompatibilityModeView.java:329)
at com.sap.tut.wd.tutwd_table.tablecomp.wdp.InternalTableCompatibilityModeView.wdInvokeEventHandler(InternalTableCompatibilityModeView.java:318)
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)
at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)
at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:248)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:160)
=================
Message was edited by: Murali Manohar
You did not mention that you want to use the TableSorter utility class from the table tutorial. Perhaps you first try to implement sorting without this class.
Assign the SortBy{Name, Code} actions to the "onAction" event of the corresponding table column, in the action handler, sort the context node using the IWDNode.sortElements() method with a suitable comparator. In the first run, the comparator might be an instance of an anonymous inner class.
Armin
Hi
Armin,
with Table sorter class, sorting is working fine.
can you tell me the steps and code to sort with comapartor
1) i already assigned an action to corresponding Colums
how can sort with comparator
a) I have to sort company Names (Sort by Name)
b) Sort company code
your inputs are highly aprreciated
Hi Murali,
In the //@@others section of your code, insert this code:
private class CustomComparator implements Comparator
{
String attribute;
int sortOrder;
CustomComparator(String attrib,int sort)
{
this.attribute = attrib;
if(sort == 0) sort = 1;
this.sortOrder = sort;
}
public int compare(Object o1, Object o2)
{
IWDNodeElement element1 = (IWDNodeElement) o1;
IWDNodeElement element2 = (IWDNodeElement) o2;
return element1.getAttributeAsText(attribute).compareToIgnoreCase(
element2.getAttributeAsText(attribute))* sortOrder;
}
public boolean equals(Object o1, Object o2) {
IWDNodeElement element1 = (IWDNodeElement) o1;
IWDNodeElement element2 = (IWDNodeElement) o2;
if (element1.getAttributeAsText(attribute)
.equalsIgnoreCase(element2.getAttributeAsText(attribute)))
return true;
else
return false;
}
}
Once this is done, you have to call this comparator member method in the action that you have defined. Like this:
CustomComparator comp = null;
try
{
sortDirection = <some integer variable, whether 1 or -1>;
if(sortDirection == WDTableColumnSortDirection.UPcomp = new CustomComparator(<name of the value attribute, in your case Company name or Company code>,1);
}
else if(sortDirection == WDTableColumnSortDirection.DOWN){
comp = new CustomComparator(sortAttribute,-1);
}
wdContext.node<your node name>().sortElements(comp);
}
catch(RuntimeException rEx)
{
rEx.printStackTrace();
}
Regards,
Satyajit.
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.