简体   繁体   中英

how to select first value in select tag empty(not null) in GSP?

Here is my domain class Incident

 class Incident {
      String status
     Usergroup assignmentGroup
     static hasMany={usergroups:Usergroup}
  }

I want to find all incidents by assignmentGroup.I am using GORM criteria for this

this is searchIncident.gsp

 <tr class="prop">
       <td valign="top" class="name">
          <label for="assignmentGroup"><g:message code="incident.assignmentGroup.label" default="Assignment Group" /></label>
       </td>
       <td valign="top" class="value ${hasErrors(bean: incidentInstance, field: 'assignmentGroup', 'errors')}">
           <g:select  id="groupSelect" name="assignmentGroup.id" from="${app.Usergroup.list()}" optionKey="id"  value=""  />
       </td>
  </tr>
   <tr class="prop" >
     <td valign="top" class="name">
        <label for="status"><g:message code="incident.status.label" default="Status" /></label>
     </td>
     <td valign='top' class='value'>
       <g:select name='status'  from='${[""] + new Incident().constraints.status.inList}'>
       </g:select>
     </td> 
    </tr>

In my option tag i must select the first value empty(not null).

If I've understood, you need to include the noSelection attribute, as in:

// use a no selection with a nullable Object property (use 'null' as key)
<g:select id="type" name='type.id' value="${person?.type?.id}"
    noSelection="${['null':'Select One...']}"
    from='${PersonType.list()}'
   optionKey="id" optionValue="name"></g:select>

See the grails docs here for more: http://grails.org/doc/latest/ref/Tags/select.html

Jim

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM