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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:39:41+00:00 2026-05-22T22:39:41+00:00

Is it possible to dynamically access properties by using #evaluate? I apologize in advance

  • 0

Is it possible to dynamically access properties by using #evaluate? I apologize in advance for the length, but most of this is just example code to fully illustrate my issue.

I have a preferences class which looks like this:

public class DefaultUserPreferences implements Preferences {
    //Getters and setters left off for "brevity…"
    private Panel defaultPanel;
    private OrderByColumn mostActiveSortOrder;
    private OrderByColumn recentlyModifiedAccountsSortColumn;
}

Each of these types are simply a custom enum.

public enum OrderByColumn {
    NAME,
    LAST_ACTIVITY,
    GROUP
}

public enum Panel {
    MOST_ACTIVE,
    RECENTLY_MODIFIED;

    public String getCamelCase() {
        String[] words = StringUtils.split(this.name(), "_");
        String rval = StringUtils.EMPTY;
        if (words != null && words.length >= 1) {
            rval = StringUtils.lowerCase(words[0]);
            for(int i = 1; I < words.length; i++) {
               rval += StringUtils.capitalize(words[i].toLowerCase());
            }
        }
        return rval;
    }
}

Below is a snippet of how I’d like to display the preferences to the users, but I can’t seem to get the getter to be called (I get the following if I evaluate it to get text: test.core.model.entities.DefaultUserPreferences@596fde80.mostActiveSortOrder)

#for ($panel in $Panels)
    ## The names here are correct
    #set($selectName = ${panel.CamelCase}SortColumn) 
    #set($dynamicProperty = $preferences.$selectName)
    <tr>
        <td>$panel</td>
        <td>
            <select name="$selectName">
                #for($option in $OrderByColumn)
                    <option value="$option" #if($option == #evaluate($dynamicProperty) selected="selected" #end>$option</option>
                #end
       </td>
    </tr>
#end

However my getter never seems to be called on the preferences. I’ve added each of the pieces to the Context, and am not having any issues iterating over the Panels, I just can’t seem to get the syntax down to dynamically call the getters on properties. Is this possible in 1.7?

  • 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-22T22:39:42+00:00Added an answer on May 22, 2026 at 10:39 pm

    Received this from the mailing list. Basically evaluate only returns a string for display instead of returning a value. Thus the set directive is required inside of the evaluated string.

    #set($selectName = "${panel.CamelCase}SortColumn")
    #set($dynamicProp = '#set( $selectedPreference = ' + '$preferences.' + $selectName)  + ' )')
    #evaluate($dynamicProp)
    

    With these lines run, I may then check the value of selectedPreference against the values I am iterating over.

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

Sidebar

Related Questions

Possible Duplicate: obj-c access property dynamically I'm attempting to access an object’s properties dynamically
Possible Duplicate: How can I access local scope dynamically in javascript? Hi all. We
Just wondering if it is possible to dynamically create a list of strings in
Is it possible to subclass dynamically? I know there's ____bases____ but I don't want
Is it possible to allow methods and properties of the 'this' pointer to be
Is it possible to access a sub-property of an object dynamically? I managed it
Is it possible to access Facebox settings? For example, I'd like to do set
I'm wondering if it is possible to access a property of a class dynamically
Is it possible to dynamically create and modify images on a per pixel level
Does someone knows if it's possible to dynamically create a call chain and invoke

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.