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

  • Home
  • SEARCH
  • 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 1027041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:10:45+00:00 2026-05-16T12:10:45+00:00

I’m trying to access elements in a HashMap. The keys of this HashMap are

  • 0

I’m trying to access elements in a HashMap.
The keys of this HashMap are defined by an Enum.

After going through the documentation, I figured that in order to be able to access the Enum, I have to send it to Freemarker like so:

BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
TemplateHashModel enumModels = wrapper.getEnumModels();
TemplateHashModel fieldTypeModel = (TemplateHashModel)enumModels.get("com.example.MinisiteFieldType");
root.put("fieldtypes", fieldTypeModel);

In my .ftl I tried the following:

${myelement.mymap[fieldtypes.SEOTEXT]}

However I get:
Expression myelement.mymap[fieldtypes.SEOTEXT] is undefined on line X…

I wanted to make sure I mapped the enum correctly, so I tried:

${fieldtypes.SEOTEXT}

This didn’t print anything, leaving me wondering wether it got through, or simply couldn’t be printed.

In Java debug, just before inserting the TemplateHashModel in my root Map, ‘fieldTypeModel’ is filled with the correct data…

Any help would be appreciated!

Bart

  • 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-16T12:10:45+00:00Added an answer on May 16, 2026 at 12:10 pm

    I suspect your problem is that by using the [] syntax to access your map, you’re implicitly telling Freemarker to treat it as a hash. That may not work as you’d expect — the hash will probably represent the Map object, mapping ‘size’ and ‘containsKey’ and so forth to Java methods. Instead, try:

    ${myelement.mymap.get(fieldtypes.SEOTEXT)}
    

    As a side note, I’ve never tried accessing enums by the method you describe, but there’s another way to access Java constants from a template that doesn’t require Java code, so the following should also work:

    ${myelement.mymap.get(stack.findValue("@com.example.MinisiteFieldType@SEOTEXT"))}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
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

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.