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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:12:08+00:00 2026-05-18T08:12:08+00:00

I have controller: package plugin class TestController { def simply = {[name:new Date()]} }

  • 0

I have controller:

package plugin

class TestController {

def simply = {[name:new Date()]}
}

as you see i pass param name

my view page:

<html>
<head>
<!-- <script type="text/javascript" src="${resource(dir:'resource/js',file:'simply.js')}?color=FA8DFF">-->

<g:javascript>
    alert("${name}")
</g:javascript>
</head>
<body>
</body>
</html>

this page run correct – afrer load i see alert window with current date 🙂

but, when

view page:

<html>
<head>
<script type="text/javascript" src="${resource(dir:'resource/js',file:'simply.js')}?color=FA8DF">
</script>
</head>
<body>
</body>
</html>

and external simply.js file:

alert("${name}")

i see empty alert window. So, my question: how i can pass params to external.js file?

  • 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-18T08:12:09+00:00Added an answer on May 18, 2026 at 8:12 am

    There are two stages in parsing the view when it is displayed to the user. State one is the server executing any code contained in the view page. In your case

    ${name}
    

    Is turned into the current date since that’s the value from the controller. This means that the text sent to the users browser contains 3/2/2010 instead of ${name}

    The second stage that takes place when the user accesses a view is the browser parsing the HTML. The HTML that is sent to the browser depends on what took place on the server. Since in your example the JavaScript is contained in the view ${name} is replaced with the current date on the server. Then JavaScript containing 3/3/2010 is sent to the browser since ${name} was replaced by 3/3/2010 on the server. This means the popup box will contain 3/3/2010. If you include external JavaScript files they never get run through the first step since the browser directly downloads them and does not make a request to the server. This means that the first step never takes place so $[name} does not get replaced with the value from your controller. This behavior is the same weather you use the

    <script>
    

    or

    <g:javascript>
    

    tag.
    In order to pass values from a view into JavaScript located in an external file you should define your JavaScript as functions in external files if you wish to pass parameters. For example in external.js

    Function dispDate(theParam)
    {
    Alert(theParam);
    }
    

    Then from your view

    <g:javascript src="external.js" />
    <script type="text/JavaScript">
    dispDate(“${name}”);
     </script>
    

    Where external.js is stored in the web-app/js directory.

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

Sidebar

Related Questions

I have controller with action new , and I want it to create ActiveRecord::Base
When submitting one form from view, how can i also read or have controller
I have a controller with an action method as follows: public class InventoryController :
I have a controller with that I want to pass off some data to
HI I have the following routing table routes.MapRoute(null, Save, // Route name new {
We have created the following simple Mojolicious controller: package SampleApp::Pages; # $Id$ use strict;
I have an Apex class (controller) originally developed under Developer Edition and need to
I have following file upload code: package net.viralpatel.contact.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller;
I have this DomainClass: package cm class XXX{ String city String website static constraints
I have this model: public class Package { public string CustomerName { get; set;

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.