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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:15:46+00:00 2026-06-18T04:15:46+00:00

I created a taglib to shorten input field code. It presets ‘name’, ‘value’ and

  • 0

I created a taglib to shorten input field code. It presets ‘name’, ‘value’ and others. Now I need to get a bean value, but the field holding that value is dynamic.
See some code (shortened to better work out my problem):

gsp:

<g:validatedInputField bean="${command}" field="surname" />
<g:validatedInputField bean="${command}" field="name" />

taglib

def validatedInputField = { attrs, body ->

    def field = attrs.field
    def bean = attrs.bean

    if (field && bean) {

        def val = bean.field
        out << "<input type=\"text\" name=\"$field\" bean=\"$bean\" value=\"$val\">"
    }
}

So the problem is the following line. It does obviously not work because there is no field ‘field’ in the bean. I want it to be dynamically replaced by ‘name’ or ‘surname’ or whatever the value of the param ‘field’ is.

def val = bean.field

I tried exprimenting with various GString/interpolation variations, but nothing worked.
Of course I could just add another param to pass the value, but I feel like it shouldn’t be required as I already have everything I need to get it in the taglib…

Can you please give me some directions?
Thanks

  • 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-06-18T04:15:47+00:00Added an answer on June 18, 2026 at 4:15 am

    In groovy, you can refer to a member of an object dynamically by using GStrings. For example:

    def val = bean."${field}"
    

    You could even perform some logic inside the GString. Let’s say you have a default field and you want to use the name inside the ‘field’ variable only if it is not null:

    def val = bean."${field ? field : "default"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just created a custom taglib which runs fine with Jetty. When using TomCat
I created a WCF service that uses TagLib# ( http://developer.novell.com/wiki/index.php/TagLib_Sharp ) which relies on
I created cookie with server side code (c#) and it was shown in chrome
Background: I created my own TagLib for application. One of the tags must depend
I've created a layout with Maqetta. Now I want to add the logic to
I'm running following code: TagLib.File f = TagLib.File.Create(path); f.Tag.AlbumArtists = f.Tag.Artists = new string[]
I'm using Visual Basic 9 (VS2008) and TagLib. The following code extracts the album
I have created Spring 3.0 application where after Login user get displayed jsp page
I have created facelet template: left-right.xhtml <ui:composition> <ui:include name=left /> <hr /> <ui:include name=right
I'm trying to run a javascript menthod on an input=image in html. My code

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.