开发者

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 c开发者_开发知识库ode="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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜