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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:23:05+00:00 2026-06-18T17:23:05+00:00

Say I have a Domain object Teacher with two fields String name, TeacherType teacherType,

  • 0

Say I have a Domain object Teacher with two fields String name, TeacherType teacherType, where TeacherType is an enum containing AssitantProfessor, AssociateProfessor, Professor.

After I generate the views using grails run-target generate-all Teacher, it produces an _form.gsp that is used for both create and edit of Teacher. In the edit view I want only the name to be editable but the TeacherType to be unmodifiable once created (this is just an example, it is a requirement that certain fields can’t be updated after creation). In the create view, both TeacherType and name should be editable.

Since both create.gsp and edit.gsp render the _form template, what is the preferred approach here?

  1. Create two separate templates i.e. _formCreate.gsp , _formEdit.gsp; Or
  2. Pass in a model map within create.gsp and edit.gsp and use them in _form.gsp to conditionally render the view?
    e.g.

In create.gsp:

    <fieldset class="form">
        <g:render template="form" model="[teacherInstance: teacherInstance, 'mode':'create']"/>
    </fieldset>

In edit.gsp

    <fieldset class="form">
        <g:render template="form" model="[teacherInstance: teacherInstance, 'mode':'edit']"/>
    </fieldset>

In _form.gsp

    <g:if test="${mode == 'edit'}">
        <g:select name="teacherType" from="${TeacherType?.values()}" keys="${TeacherType.values()*.name()}" required="" value="${teacherInstance?.teacherType?.name()}" disabled="disabled"/>
    </g:if>
    <g:else>
        <g:select name="teacherType" from="${TeacherType?.values()}" keys="${TeacherType.values()*.name()}" required="" value="${teacherInstance?.teacherType?.name()}" disabled="false"/>
    </g:else>

Approach 2 works but I suppose if the number of conditional statements increase it may just be better to follow approach 1 and split the forms.

Is there another approach that I’m not aware of?

  • 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-18T17:23:06+00:00Added an answer on June 18, 2026 at 5:23 pm

    The disabled attribute of <g:select> (and many other <g:...> form field tags) can be a boolean-valued expression:

    <g:select name="teacherType" from="${TeacherType?.values()}"
      keys="${TeacherType.values()*.name()}" required=""
      value="${teacherInstance?.teacherType?.name()}"
      disabled="${mode == 'edit'}"/>
    

    This will render as disabled="disabled" if the expression evaluates to true, and as the absence of a disabled attribute (i.e. the field will not be disabled) if the expression is false. You could even use a boolean entry in the model, e.g. render the template with

    model="[teacherInstance: teacherInstance, editing:true]"
    

    (or editing:false respectively) and then say disabled="${editing}" on the <g:select>.

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

Sidebar

Related Questions

I have this huge domain object(say parent) which contains other domain objects. It takes
I have a domain object called User . Properties of user include ssoId, name,
I have a domain object annotated like this for hibernate support. @Entity @Table(name =
Let's say I have a Domain Object like this: public class Product { public
As part of my domain model, lets say I have a WorkItem object. The
I have two machines, say in the company domain CorpotateDomain . First machine: first.CorpotateDomain.com
Say I have a user domain class with fields username and password . For
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let's say I have a domain object that looks like this: @Entity @Indexed public
Say I have this XML: <domain type='qemu' xmlns:qemu='http://libirt.org/schemas/domain/qemu/1.0'> <name>QEmu-fedora-i686</name> <memory>219200</memory> <os> <type arch='i686' machine='pc'>hvm</type>

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.