9 Replies Latest reply: Nov 20, 2003 7:39 PM by 331500 RSS

    Multiple Table Selection and invoking Struts Action

    331500
      I have a multiple selection in a table. Once the records are selected I need to create a String Array of all the UserIDs and invoke a struts action. for example /deleteuser.do
       public static EventResult doMultiSelectEvent(BajaContext bc, Page page, PageEvent event){
          HttpSession session = bc.getServletRequest().getSession(false);
      
          ArrayList _table_data =(ArrayList) session.getAttribute(IConstants.USER_LIST_SUCCESS);
      
          PageEventFlattenedDataSet tableRows =  new PageEventFlattenedDataSet(event, "userListTable");
      
          int[] indices = SelectionUtils.getSelectedIndices(tableRows);
      
          String[] ID = new String[indices.length];
          //Creating a String Array of all the user ID
          for (int i=0; i<indices.length; i++){
            ID[i] =String.valueOf(((UsersDTO) _table_data.get(indices)).getUserID());
      }
      //NEED HELP FROM THIS POSITION
      EventResult result = new EventResult(page);
      result.setProperty("action", event.getName());
      System.out.print(event.getName());
      result.setProperty("userListTable", resultTableData);
      return result;
      }

      From this code segment how can I acheve that. This segment which I got from the Developer Guide returns to the same page but in my case I need to invoke a struts action.

      Below is the code segment I am using to call this method from my UIX page.
        <event name="delete">
            <method class="lk.informatics.infopro.provider.UIXProvider" method="doMultiSelectEvent"/>
          </event>
        • 1. Re: Multiple Table Selection and invoking Struts Action
          331500
          I forgot to delete this line from the code segment above. Please ignore that code
             result.setProperty("userListTable", resultTableData);
          • 2. Re: Multiple Table Selection and invoking Struts Action
            331500
            //NEED HELP FROM THIS POSITION
            EventResult result = new EventResult(page);
            result.setProperty("action", event.getName());
            System.out.print(event.getName());
            result.setProperty("userListTable",
            e", resultTableData);
            return result;
            }
            From this code segment how can I acheve that. This
            segment which I got from the Developer Guide returns
            to the same page but in my case I need to invoke a
            struts action.
            instead of above code segment I was tried the below code segment too
                session.setAttribute("ID",ID);
                Page nextPage = new Page("/deleteuser.do");
                return new EventResult(nextPage);
            I was trying to invoke the struts action like this. However the problem is it automatically adds .uix to the the name. How can I avoid this?
            • 3. Re: Multiple Table Selection and invoking Struts Action
              331500
              is there any solution to this issue? to Call Struts action within this event handler?
              • 4. Re: Multiple Table Selection and invoking Struts Action
                12214
                Senthoorkumaran,

                With all the trial and error I have done over the last few weeks, I may have a solution for you.

                You kind of have to flip the logic. FIRST call the struts action from your event handler in the UIX page:

                <event name="delete">
                <struts:action path="/deleteAction.do"/>
                </event>

                Now override the struts action handler by double clicking on the struts action in the struts Pageflow diagram. Here you create a skeleton class that allows you to perform operations during the processing of the struts action - specifically the execute() method. (Also see Tools -> Override Methods while in the JAVA editor in this context for other overrides).

                Now, using the JAVA APIs against the ActionMapping and the HttpRequest parameters you can get your page and event objects. Perform your logic (as posted) and finally allow the struts action to complete (by default the overriding java you have created returns "success").

                This is a nice approach actually because if your custom logic fails for some reason you can return a "failure" from the struts action and handle the error gracefully.

                One caveat. This execute() override will now execute ANY TIME this struts action is called so you must discriminate in the java to trap the specifics of the context you want your custom logic to execute for.

                Hope this helps...

                Tom
                • 5. Re: Multiple Table Selection and invoking Struts Action
                  331500
                  Thank you Tom,
                  Now override the struts action handler by double
                  clicking on the struts action in the struts Pageflow
                  diagram. Here you create a skeleton class that allows
                  you to perform operations during the processing of
                  the struts action - specifically the execute()
                  method. (Also see Tools -> Override Methods while in
                  the JAVA editor in this context for other overrides).
                  This seems to be how things are done in JDev 10g. However I am not using 10g and I am still on JDev 9.x.x
                  Now, using the JAVA APIs against the ActionMapping
                  and the HttpRequest parameters you can get your page
                  and event objects. Perform your logic (as posted) and
                  finally allow the struts action to complete (by
                  default the overriding java you have created returns
                  "success").
                  It would be great if you could post the code which you are using to process in the Struts action class. I was trying to do this but at the point of retriving the PageEvent from the HttpRequest I am stuck. Below I am posting my Strust Action Code too. I have commented most of the code to get the servlet.log() working
                    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws java.lang.Exception {
                      ActionForward forward = null;
                  
                      if (isCancelled(req)) return mapping.findForward("Cancel");
                  
                      RequestForm requestForm = (RequestForm)form;
                      RequestDBOperations service = new RequestDBOperations();
                      javax.sql.DataSource dataSource;
                      RequestTaskHolderDTO myReqTask = null;
                      java.sql.Connection myConnection = null;
                  
                  //--------------Processing of Table Rows and getting the Transaction ID------------
                      List requestList = (List)req.getSession(false).getAttribute(IConstants.REQUEST_LIST_SUCCESS);
                  
                  //HERE YOU CAN SEE THE DIFFERENT WAYS I TRIED TO GET THE PAGEEVET OBJECT FROM HttpRequest. viewtask is my event name
                      PageEvent event = (PageEvent)req.getSession(false).getAttribute("viewtask");
                  
                  //    PageEvent event = (PageEvent)req.getAttribute("viewtask");
                  //    PageEvent event = (PageEvent)req.getAttribute("event");
                  
                      servlet.log("List : " +  requestList);
                      servlet.log("Event : " + event);
                  
                  //    DataObject tableRows = new PageEventFlattenedDataSet(event, "reqListTable");
                  //    int index = SelectionUtils.getSelectedIndex(tableRows);
                  //    servlet.log("Index : " + index);
                  //    String name = "Nothing Selected";
                  //    // make sure that something was selected:
                  //    if (index>=0)
                  //    {
                  //      DataObject row = (DataObject)requestList.get(index);
                  //      servlet.log("Row : " + row);
                  //      name = row.selectValue(null, "txnID").toString();
                  //      servlet.log("name : " + name);
                  //    }
                  //    String txnID = "";
                  
                  //    try {
                  //      dataSource = getDataSource(req);
                  //      myConnection = dataSource.getConnection();
                  //      myReqTask = service.retriveTasks(myConnection, txnID);
                  //    } catch (SQLException sqle) {
                  //      getServlet().log("Connection.process", sqle);
                  //    } catch(ApplicationException e){
                  //      getServlet().log(e.toString());
                  //    } finally {
                  //      try {
                  //        myConnection.close();
                  //      } catch (SQLException e) {
                  //        getServlet().log("Connection.close", e);
                  //      }
                  //    }
                  //    getServlet().log("Req Task List Returned : " + myReqTask);
                  //    HttpSession currentSession = req.getSession(false);
                  //    currentSession.setAttribute("TaskDetailSuccess", myReqTask);
                  
                      forward = mapping.findForward("Success");
                      return forward;
                    }
                  Here is my event handler
                      <event name="viewtask">
                        <struts:action path="/detailrequestview.do"/>
                      </event>
                  By the way I am adopting your solution to a single selection at this point.
                  • 6. Re: Multiple Table Selection and invoking Struts Action
                    331500
                    Is there any other solution to post a table multiple selection to a struts action from UIX? Any code samples? Calling struts action in the event is not a problem but I am finiding it difficult to retrive PageEvent and other UIX objects inside a Struts Action.
                    • 7. Re: Multiple Table Selection and invoking Struts Action
                      331500
                      REPOST!!

                      (sorry about it though)
                      • 8. Re: Multiple Table Selection and invoking Struts Action
                        30485
                        Hi Senthoor -

                        I am not sure whether there is a way to get at the PageEvent from a Struts Action, but another solution might be to use the ServletRequestDataSet instead of the PageEventFlattenedDataSet to access your table data. That way, I don't think you'll need access to the PageEvent at all. By using the ServletRequestDataSet you can retrieve table data/selection info directly from the ServletRequest.

                        Andy
                        • 9. Re: Multiple Table Selection and invoking Struts Action
                          331500
                          Any examples or code samples available for this kind of access to table data in the Struts Action using UIX 2.1.7?

                          Senthoor