asdtiang的博客 感谢blogjava提供的博客交流平台

gsp学习笔记each select set

Posted on 2010-02-24 10:37 asdtiang 阅读(529) 评论(0)  编辑  收藏 所属分类: grails study
gsp中的select标签使用:
<g:select name="category.id" from="${org.asdtiang.study.grails.Category.list()}"
                                              optionKey
="id" optionValue="categoryName"
 value
="${goodsInstance?.category?.categoryName}"  />
from指定数据来源。
optionKey="id"表示依次用数据源中每个Category的id作为每个选项的值(即<option value=""/>中的value对应的值)
optionValue="categoryName"表示用每个Category的categoryName作为每个选项的显示结果(如:<option>test</option> 中test对应内容)
value指定当前列表中与value等值的选项。

1 <html>
2   <body>
3     Hello ${params.name}
4   </body>
5 </html>
6 
GSP also supports logical and iterative tags out of the box. For logic there are if, else and elseif which support your typical branching scenarios:
1 <g:if test="${session.role == 'admin'}">
2    <%-- show administrative functions --%>
3 </g:if>
4 <g:else>
5    <%-- show basic functions --%>
6 </g:else>
7 
8 

For iteration GSP has the each and while tags:

 1 <g:each in="${[1,2,3]}" var="num">
 2    <p>Number ${num}</p>
 3 </g:each>
<g:each in="${goodsInstanceList}" status="i" var="goodsInstance">
<%-- in指定遍历的集合,status指定索引,var指定每次取出元素的名称,默认为it --%>
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        
                            
<td><g:link action="show" id="${goodsInstance.id}">${fieldValue(bean: goodsInstance, field: "id")}</g:link></td>
                        
                            
<td>${fieldValue(bean: goodsInstance, field: "title")}</td>                       
<%--fieldValue方法的作用是取出指定bean的指定属性,能自动执行encodeAsHtml()操作,以防止跨站脚本攻击--%>
                            <td><img alt="不能显示" src="${fieldValue(bean: goodsInstance, field: "photoUrl")}" style="width:300px; height:300px" ></td>
                        
                            
<td>${goodsInstance.category?.categoryName}</td>

                        
                        
</tr>
  
</g:each>

 4 
 5 <g:set var="num" value="${1}" />
 6 <g:while test="${num < 5 }">
 7 <p>Number ${num++}</p>
 8 </g:while>
 9 
10 





天苍苍,野茫茫,风吹草底见牛羊

只有注册用户登录后才能发表评论。


网站导航:
 

posts - 80, comments - 24, trackbacks - 0, articles - 32

Copyright © asdtiang

asdtiang的博客 PaidMailz
点击广告网赚A(每天4个广告,每个0.0025美元,一个搜索广告0.03美元)