Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:50:49+00:00 2026-06-13T09:50:49+00:00

I want get parameters from json, so I have a code: @RenderMode(name = VIEW)

  • 0

I want get parameters from json, so I have a code:

    @RenderMode(name = "VIEW")
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, IOException {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            resourceRequest.setAttribute("resourceUrl", "http://localhost:8080/");

             jsonObject.put("rowsPerPage", 10);
             jsonObject.put("page", 1);
             jsonObject.put("total", 100);

             PrintWriter writer = resourceResponse.getWriter();
             writer.write(jsonObject.toString());
        }

What should be written in JavaScript method that displays the: rowsPerPage, page, total

I have a JavaScript code:

$.getJSON('http://localhost:8080/', function(jd) {
      alert(jd.rowsPerPage);
   });

JSP page:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

This is the <portlet:resourceURL var="testURL" id="view.jsp" escapeXml="false" />
<br/><br/>
<div id="myGrid" style="width:600px;height:500px;"></div>
<div id="pager" style="width:600px;height:20px;"></div>

But it is wrong, why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:50:50+00:00Added an answer on June 13, 2026 at 9:50 am

    Check your URL http://localhost:8080/ if it returns a JSON response (you can directly paste the URL in the address bar of the Browser). This would return the Welcome page of Liferay.

    For calling the serveResource method you would require a resourceURL to be passed in the jQuery function getJSON which can be generated using the <liferay-portlet:resourceURL> or <portlet:resourceURL> tags in JSP.

    Update:

    You should use the resourceURL in the javascript:

    <portlet:resourceURL var="testURL" id="view.jsp" escapeXml="false" />
    
    <script>
        $.getJSON('${testURL}', function(data) {
            alert(data.rowsPerPage);
        });
    </scrip>
    
    <!-- ${testURL}: This is EL i.e. expression language of JSP. Don't confuse it with jQuery -->
    <!-- <%=testURL.toString() %>: You can also use scriptlet instead of using EL. But normally scriptlets as you might know are not recommended -->
    

    Also I would like to suggest to make sure that the serveResource method is actually called with the script by included some log statements in the method.

    Here are some links for examples as to how to use Ajax in Liferay:

    1. A working example to use Ajax in Liferay.
    2. Blog explaining concept as to how ajax works in a portal with a simple example.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The thing is that I want to get parameters for my Capistrano recipe from
I want to make queries according to the parameters I get from my server
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it
I want to return a JSON array from a cakePHP controller. I effectively have
I want get as much as possible from Redis + Hiredis + libevent. I'm
I have the following C# helper class which retrieves a Json String from a
I have an AJAX call that I want to run against a WCF GET
I am using Asp.net MVC 3 and Json.net library. I have view model class
I want to grab some data from remote database and I have some networking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.