Announcement Announcement Module
Collapse
No announcement yet.
get boolean to display as checkbox in view/show Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • get boolean to display as checkbox in view/show

    I have an object with Boolean fields, and in Create/Edit screens, the fields are a checkbox, which is exactly what I want. However, in List or view/show mode, the data displays with the text "true" or "false." How do you get booleans to display as (disabled) checkboxes in those gsp pages?

  • #2
    Does this cover what you're looking for?

    Comment


    • #3
      I recommend you run:

      grails install-templates

      and then edit the 'src/templates/scaffolding/show.gsp' and 'src/templates/scaffolding/list.gsp'. If you search for 'boolean', you will find the rendering code for boolean values. For example, in show.gsp it is:
      Code:
      <%  } else if (p.type == Boolean.class || p.type == boolean.class) { %>
      <td valign="top" class="value"><g:formatBoolean boolean="\${${propertyName}?.${p.name}}" /></td>
      Replace the <g:formatBoolean /> with a disabled <g:checkBox />.

      Comment


      • #4
        @pledbrook - that looks like just what I need for this application. I'll give it a shot, thank you!

        Comment


        • #5
          exact syntax

          Thnaks, I used following code snippet and worked like charm

          Code:
          if (p.type == Boolean.class || p.type == boolean.class) { %>
              <td><g:checkBox name="\${${p.name}}" disabled="true" value="\${${propertyName}.${p.name}}"> </g:checkBox></td>

          Comment

          Working...
          X