struts2 counter循環標籤在分頁中的使用

struts2提供了<s:bean/>標籤,且提供了一個bean類:org.apache.struts2.util.Counter,該類中有first、last等屬性,可用使用它獲取自增值,以下:javascript

<s:bean name="org.apache.struts2.util.Counter" id="counter">
<s:param name="first" value="1" />
<s:param name="last" value="10" />
<s:iterator>
<s:property/>
</s:iterator>

</s:bean>java

其中first屬性指定循環起始值,last指定循環終止值,其它相關屬性能夠查看org.apache.struts2.util.Counter類源碼。在下面迭代器中輸入循環的當前值,即:current-1apache


如下struts2 counter循環標籤在分頁中的使用的實例,在jsp中的部分代碼以下:jsp

<form name="userForm" action="**" method="post">
        <select name="currentPage" onchange="submitForm()">
         <s:bean name="org.apache.struts2.util.Counter" id="counter">
          <s:param name="first" value="1" />
          <s:param name="last" value="page.totalPage" />
                     <s:iterator>
                                   <option value="<s:property/>" 
                                   <s:if test="currentPage == currenter -1">selected</s:if>>
                                   <s:property/>
                                   </option>
                      </s:iterator>
          </s:bean>                                                                                                                                                 
     </select>                                                                                                                                                           </form>post

下面是javascript代碼:spa

<script type="text/javascript">
        function submitForm(){
                var frm=document.usertForm;
                frm.submit();
        }                                                                                                                                                          </script>     
orm

相關文章
相關標籤/搜索