Skip to Content

I have been trying my luck at WebDynpro and moving from ABAP to Java is definitely not a piece of cake. Things which were in-built in ABAP are much difficult to display in Java. Many of the users who do a paradigm shift from SAP R/3 Client to Web Client; usually seek a similar User Interface. Like all aspects in life, anything less is simply unacceptable.

I do have a big list to explore, and I started out with simple stuff. I am sure there are many guys out there who find this weblog a little too trivial, but it took me quite a few days to figure out.

Regular Expressions

From these links and the examples quoted, in case you are unaware of Regular Expressions, you will come to know how much more powerful it is than the regular approach we carry out in ABAP world.

Aim

To have filter functionality in table in WebDynpro

Pre-requisites

Basic Java knowledge, WebDynpro Terminology, able to setup JCo connection successfully, able to fetch data from R/3 and have gone through the tutorials at SDN

Approach

The brief steps to have a filter are:

  • First, we should be in a position to successfully extract data from R/3
  • Don’t do a context mapping of view context to component/custom controller used to fetch data i.e. for task a) you have created a component/custom controller and you have bound it with the model. In this case don’t do a context mapping of this component/custom controller to view context. We will instead source data from component/custom controller and put it in the view context.
  • Create a view context having a value node of cardinality 1…n and with relevant value attributes. In this example, they are Username, Firstname, Fullname, Lastname
  • In the filter process, the value node is completely refreshed and then based on the filter criteria, data is sourced from component/custom controller and put in the view context

Note

Only the filter functionality is explained below, it is assumed that table is already created.

Solution

Step 1

First a method has to be created in the view. The method is FILTER and it is associated with the event onFilter of the UI Element MyFilterTable

image

Step 2

Create a context value attribute FILTER_USERNAME. This value attribute will be associated (bound) with the filter value that you enter in the screen. image

Step 3

Bind the context value attribute FILTER_USERNAME to the relevant column of the table. In this case it is bound with Username. image

Step 4

Result

Input

Display all results which start with 200
image

Output

image

Other Results

Display results where usernames contain only letters. In this case the filter criteria is [A-Z,a-z].* image

To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

  1. Harsh Chawla
    Hi Subramanian,
       Nice Blog! Filtering is one of those nifty features that is not critical, but its availability makes life just a little bit simpler:). One little point, one doesn’t really need “to be able to extract data from R/3”, to try out filters as you’ve mentioned in the pre-requisites. A simple for loop in the doInit() of the component/custom controller will do the job of populating the context node. I’m just mentioning this, because people who havent yet figured out how to configure JCO connections and extract data from R/3 can still go ahead and try out this blog.
    Ciao,
    Harsh
    (0) 
      1. Former Member
        Hi,

        I applied the steps described by this blog, but I get always a runtime exception if I try to filter on the table.

        Can anyone help me?

        Thanks.
        Cemal Salman

        The exception is:

        com.sap.tc.webdynpro.services.exceptions.WDRuntimeException
             at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.handleUIElementEvent(HtmlClient.java:835)
             at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.updateEventQueue(HtmlClient.java:722)
             at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.initEvents(AbstractClient.java:131)
        ….

        Caused by: java.lang.reflect.InvocationTargetException
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:324)
             at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.handleUIElementEvent(HtmlClient.java:827)
             … 23 more
        Caused by: com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Cannot set pending user input ‘LE_SAPA*’ for invalid attribute path
             at com.sap.tc.webdynpro.clientserver.data.DataContainer.setPendingUserInput(DataContainer.java:1230)
             at com.sap.tc.webdynpro.clientserver.data.DataContainer.updateAttribute(DataContainer.java:458)
             at com.sap.tc.webdynpro.clientimpl.html.uielements.adaptbase.AbstractAdapter.updateAttribute(AbstractAdapter.java:503)
             at com.sap.tc.webdynpro.clientimpl.html.uielib.standard.uradapter.TableAdapter$FilterField.onINPUTFIELDCHANGE(TableAdapter.java:3175)
             at com.sap.tc.webdynpro.clientimpl.html.uielib.standard.uradapter.TableAdapter.onINPUTFIELDCHANGE(TableAdapter.java:8075)
             … 28 more

        (0) 
  2. Former Member
    Hi

    I have used the similar code as provided here for the filter functionality in my application, but i am not getting the desired result. Every time i give some filter parameter, the table doesn’t show the filter data. Besides it also clears the data displayed previously.
    I tried changing the cardinality and running, but that also hasn’t worked.
    If i comment the code for removal of the data elements, and then try running the application, nothing happens and previous data remains displayed in the table.
    Can you please help me in this regard, in deciphering the issue relating to it?

    Thanks & regards,
    Anupreet

    (0) 
  3. Former Member
    Hi Subramanian Venkateswaran,
      I am new to webdynpro.
      First of all, Thanks for the weblog.

    I have added about 8 nodeElements (custom) from wddoInit().

    I am getting an java.lang.IndexOutOfBoundsException:

    java.lang.IndexOutOfBoundsException: Index: 7, Size: 0
         at java.util.ArrayList.RangeCheck(ArrayList.java:507)
         at java.util.ArrayList.get(ArrayList.java:324)
         at com.sap.tc.webdynpro.progmodel.context.Node$ElementList.getElement(Node.java:2023)
         at com.sap.tc.webdynpro.progmodel.context.Node.getElementAtInternal(Node.java:624)
         at com.sap.tc.webdynpro.progmodel.context.Node.getElementAt(Node.java:631)
         at com.sap.tut.wd.flightlist.SearchView.onActionFilter(SearchView.java:218)
         at com.sap.tut.wd.flightlist.wdp.InternalSearchView.wdInvokeEventHandler(InternalSearchView.java:197)
         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:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

    Everything is fine until the 5th step.
    All the elements are removed and the CN_Userlist node’s size = 0.

    In 6th step,

    for (int i = n – 1; i >= 0; i–) {
    String value = (String) myValues.getElementAt(i).getAttributeValue(“Username”);
    ..

    ..

    }
       —> i am getting exception here… it’s not able get the value at ‘i’ (which is n-1 initially) as there are no nodeElements now.

    Can you please guide me on this?

    Regards,
    Kanth.

    (0) 
    1. Former Member Post author
      Good to know you liked the blog.

      Please create a message in Web Dynpro Forum with reference to this blog… Since I am already replying(please don’t reply to this post, instead just post a message in Web Dynpro Forum) find out what is the value of n! If the list is empty and n has a value greater than 1, there will be a problem and thus the error.

      Regards,
      Subramanian V.

      (0) 
  4. Hi Subramanian,
    Good work on the blog. I notice that you have decoupled the node in your view and component controller. This you do to remove/add entries into the view controller’s context without affecting the contect of the comp controller. Makes sense, but doesnt this mean that what you select on the screen (lead /multi select) is visible only in the view controller? So will methods in the component controller know the element being lead/multi selected?

    Regards,
    Atul

    (0) 
    1. Former Member Post author
      Hi Atul,

      To know whether it is lead/multi selected, the first controller that will come to know about this is the view controller because all actions in that view are handled by the respective methods of that view. If the component controller needs to know, it always can, but you need not always do a context mapping. [To continue this discussion, kindly open a post in Web Dynpro forum]

      Regards,
      Subramanian V.

      (0) 
  5. Former Member
    Hi,

    Somebody has a project example of table filter that works?

    I’m very beginner in Web Dynpro.

    I need your help!

    Thanks!

    Kleber

    (0) 

Leave a Reply