Posted on 2010-02-24 10:37
asdtiang 閱讀(546)
評論(0) 編輯 收藏 所屬分類:
grails study
gsp中的select標(biāo)簽使用:
<g:select?name="category.id"?from="${org.asdtiang.study.grails.Category.list()}"
??????????????????????????????????????????????optionKey="id"?optionValue="categoryName"
?value="${goodsInstance?.category?.categoryName}"??/>
from指定數(shù)據(jù)來源。
optionKey="id"表示依次用數(shù)據(jù)源中每個(gè)Category的id作為每個(gè)選項(xiàng)的值(即<option value=""/>中的value對應(yīng)的值)
optionValue="categoryName"表示用每個(gè)Category的categoryName作為每個(gè)選項(xiàng)的顯示結(jié)果(如:<option>test</option> 中test對應(yīng)內(nèi)容)
value指定當(dāng)前列表中與value等值的選項(xiàng)。
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指定每次取出元素的名稱,默認(rèn)為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的指定屬性,能自動執(zhí)行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?
天蒼蒼,野茫茫,風(fēng)吹草底見牛羊