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 1054391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:23:59+00:00 2026-05-16T17:23:59+00:00

I have been using Grails for last 3 weeks (learning and working). I have

  • 0

I have been using Grails for last 3 weeks (learning and working). I have been working on porting a JSP/Servlet application to Grails and it has been absolute “fun” porting the application.

I have facing an issue and have been searching, reading but could not solve it yet.

In the GSP page I have a textfield and search button where user enters ProductID. I have a controller which is called from jQuery Ajax method when a search button is clicked.

 // ----- Part of jQuery Ajax call ---
$.ajax({
        type : "post",
        url : '/${grailsApplication.metadata['app.name']}/product/checkProductAjax',
        data : "pid="+proID,

// ----- Contoller code-----
class ProductController {
      def scaffold = true    
          def checkProductAjax = {
                 def product= Product.findByProductId(params.pid)
                if(product) {
                     [product: product] // model to get data in GSP page.                  
                      render(product.toString() + ":" + product.id)
                } else {
                    render("none")
                }
          }
}

Ajax call and everything works fine. The problem I am facing is how to get the model (i.e. the Product data back to the GSP page i.e. [product: product] and display in GSP as for e.g. Product Name: ${product}

How can I get it working? I have read examples where it is mentioned that just setting the model [product: product] will help to get the data in GSP.

Product Name: ${product} always shows blank in the GSP page Product Name:

Please tell me what I am doing wrong.

Cheers!
Jay Chandran

  • 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-05-16T17:24:00+00:00Added an answer on May 16, 2026 at 5:24 pm

    [product: product] and render(product.toString() + ":" + product.id) are incompatible. When you see a controller action whose last line is a map like [product: product] this is the implicit return value since it’s the last statement of the action closure – it’s the equivalent of return [product: product]. But if you have a map in the middle of a method it’s just created and discarded. It’s pretty much equivalent to

    def ignoreThisMap = [product: product]
    // other code
    

    Since you’re making an Ajax call though, putting the product in the model doesn’t make sense since you aren’t going to re-render the GSP. You’re going to render text, JSON, XML, or some other content that the client-side JavaScript will use to update some subset of the html. So you probably want something closer to

    if (product) {
       render product as JSON
    }
    else {
       render "none"
    }
    

    and then you can use jQuery or Prototype to evaluate the JSON and extract the data in your JavaScript.

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

Sidebar

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.