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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:28:31+00:00 2026-05-30T08:28:31+00:00

I’ve got an app using the Play! framework. I’m binding variables to templates and

  • 0

I’ve got an app using the Play! framework. I’m binding variables to templates and building on what could be a life-saver trait for Play!: https://github.com/asinghal/Play-ScalaGen/blob/master/misc_utils/EmailNotifier.scala

var templateHtmlBinding = new java.util.HashMap[String, Object]()
    var templateTextBinding = new java.util.HashMap[String, Object]()

    for (o <- args) {
      val names = LocalVariablesNamesTracer.getAllLocalVariableNames(o).toList
      for (name <- names) {
        templateHtmlBinding += (name -> o)
        templateTextBinding += (name -> o)
      }
    }

The issue is that when you do a getAllLocalVariableNames on line 155 the entire list returns empty. I can confirm that the objects passed into the function are not null as verified by printing them out inside the function. I’m wondering if there’s something wrong using this in Scala or if anyone knows of a reflection method that could do the job?

Edit

I’m trying a little reflection but my reflection knowledge is somewhat limited. A sample:

val names = o.getClass.getMethods.toList.map(_.toString)

Output from a sample object passed in:

List(public java.lang.String models.Account.name(), public static final scala.Op
tion models.Account.get(long), public boolean models.Account.equals(java.lang.Ob...

Any idea how to filter this further?

Second Edit

I’ve gotten this far which successfully produces a list of each object and its properties, but unfortunately it still triggers the same error with a populated list:

val oname = o.getClass.getName.replaceAll("models.","").toLowerCase
val names = o.getClass.getDeclaredFields.toList.map(_.getName.toString).map(oname+"."+_)

gives:

List(account.id, account.name, account.address,...

Any insight on where something is going wrong in the Play! templating?

  • 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-30T08:28:33+00:00Added an answer on May 30, 2026 at 8:28 am

    As in Edit 2 I was able to get the property names of every object passed in. However, the problem I had was actually caused by the class itself, so I modified a couple things to fix it. I created this:

    for ((name:String, o:Object) <- args) {
      templateHtmlBinding += (name -> o)
      templateTextBinding += (name -> o)
    }
    

    and replaced lines 153-159:

    for (o <- args) {
          var names = LocalVariablesNamesTracer.getAllLocalVariableNames(o).toList
          for (name <- names) {
            templateHtmlBinding += (name -> o)
            templateTextBinding += (name -> o)
          }
        }
    

    It looks like you just can’t get variable names if you want to expand outside of Play! controllers and get messy. So a fix is to simply pass in the template variable names like this:

    mail.send("app/views/Mails/invite", "account"->account, "user"->user )
    

    and reference in your template like:

    ${account.name}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.