Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Calling rest API on clicking a row of ojTable

1106277May 24 2016 — edited May 24 2016

I have a table in jobs.jsp where I show all jobs submitted by an user.

                                             <table id="tableJobs" summary="Jobs List" aria-label="Jobs Table"

                                                       data-bind="ojComponent: {component: 'ojTable',

                                                                                               data: jobsData,

                                                                                               selectionMode: {row: 'single'},

                                                                                               columnsDefault: {sortable: 'none'},

                                                            columns: [{headerText: 'Name',

                                                                       field: 'asdfa',

                                                                       style: 'width: 50%'},

                                                                      {headerText: 'Data',

                                                                       field: 'sdfasdff',

                                                                       style: 'width: 20%'},

                                                                      {headerText: 'Type',

                                                                       field: 'dfdfs',

                                                                       style: 'width: 20%'},

                                                                      {headerText: 'ID',

                                                                       field: 'jobId',

                                                                       style: 'width: 10%'}}],

                                                                   rootAttributes: {'style':'width: 100%; height:100%;'}}">

                                                </table>

So when I click on any row this method is called in my app.js and here in end I call my GET api through servlet call

                   function selectionListener(event, data)

                    {

                        if (data['option'] == 'selection')

                        {

                                   -------  sample code from cookbook for selection--------------------

                              // Call JobDetails servlet with key as jobId

                           $.get('jobDetails', { 'key': startKey.row });

                         }

                     }; 

This call my java doGet method to processRequest() of servlet  JobDetails.java

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)

            throws ServletException, IOException {

                Client client = Client.create();

               String jobId = request.getParameter("key");

                System.out.println("JobId is :"+jobId);

                String endPoint="https://abcd/"+jobId ;

                WebResource webResource = client.resource(endPoint);          

                 ClientResponse wsResponse = webResource.header("Authorization", "Basic dfdfdfsdf").accept("application/json") .get(ClientResponse.class);

                if (wsResponse.getStatus() != 200 && wsResponse.getStatus()!=302) {

                    throw new RuntimeException("Failed : HTTP error code : "

                            + wsResponse.getStatus());

                }

                String jobsDetailsOutput = wsResponse.getEntity(String.class);

                System.out.println(jobsDetailsOutput);  

               request.setAttribute("jobsDetailsJSON",jobsDetailsOutput);

                request.getRequestDispatcher("jobs.jsp").forward(request, response); 

    }

I am able to get my jobsDetailsOutput from my java sevlet. If I do System.out.println(), its giving me my api results.

But now how do I show these details in my jobs.jsp page ????  I am not able to figure out the same.

I tried this in my jobs.jsp, but my jobsDetailsJSON is coming empty, though I am setting it in above servlet like this request.setAttribute("jobsDetailsJSON",jobsDetailsOutput);


<p>This is Job Details</p>

<h1>${jobsDetailsJSON}</h1>

<c:choose>

    <c:when test="${not empty jobsDetailsJSON}">

        ${jobsDetailsJSON}

     </c:when>

</c:choose> -->

How do I show my results on my jsp page ??

If its returning me a list of details, how do I bind it to a ojPieChart component again ??

In pieChart I need to show details about a particular job which I fetch using above REST api.

Thanks !!

Note : I am not calling api's directly rom JS because our api's do not support CORS.

Comments
Post Details
Added on May 24 2016
1 comment
603 views