var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20738293-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script')"/>
<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jutleo
    歡迎走進(jìn)有風(fēng)的地方~~
    posts - 63,  comments - 279,  trackbacks - 0
     

    最近做畢業(yè)設(shè)計(jì)用到Struts2 的標(biāo)簽庫,遇到一些比較復(fù)雜的數(shù)據(jù)顯示,個(gè)人還是比較喜歡用tag顯示的,Struts2 tags內(nèi)容豐富,但是所提供的文檔不是很詳細(xì)(個(gè)人認(rèn)為)在showcase下的例子如:<s:select /> <s:doubleselect /> <s:updownselect /> <s:optiontransferselect />等都是一些簡(jiǎn)單的值顯示,在實(shí)際的開發(fā)中并沒有那么簡(jiǎn)單,如果我們要迭代顯示ListMapSet里的值,我們?cè)撛鯓幼瞿兀?/span>

       
    看看html里的例子,

    <select name="sex">

        <option value="man"></option>

        <option value="women"></option>

    </select>

    Sex表示提交的nameman/women是對(duì)應(yīng)頁面顯示提交后所代表的值,男/女則為頁面最終看到的值

       
    而如果我們要顯示一個(gè)List集合里的數(shù)據(jù)該怎么做呢?
       
    看下面的Jsp頁面:

    <select name="department">

        <%

           Department department = null;

           List list = (List) request.getAttribute("list");

           Iterator iter = list.iterator();

           while (iter.hasNext()) {

               department = (Department) iter.next();

        %>

        <option value="<%=department.getDep_name() %>"><%=department.getDep_name()%>&nbsp;&nbsp;&nbsp;</option>

        <%

        }

        %>

    </select>

    迭代的是Department的屬性dep_name,這樣顯示顯得很麻煩,如果Iterator輸出可能會(huì)好點(diǎn),采用JSTL輸出:

    <c:forEach var="department" items="" varStatus="status">

        <tr>

           <td>${status.dep_name }</td>

           <td>${status.dep_id }</td>

           <td>......</td>

        </tr>

    </c:forEach>


    現(xiàn)在看看Struts2的例子:這是Strust2 showcase例子

    <%@ page contentType="text/html; charset=UTF-8"%>

    <%@ taglib prefix="s" uri="/struts-tags"%>

    <html>

    <head>

    <title>Test</title>

    </head>

    <body>

    <center><br>

    <br>

    <br>

    <hr>

    <br>

    <br>

    <s:form action="test_showPost" method="post" theme="simple">

        <table>

           <tr>

               <td><s:select

                  list="{'Windows','Linux','Java','.net','Pertl','PHP'}"

                  name="program" tooltip="select your program" /></td>

           </tr>

            <tr>

               <td><s:select list="posts" name="post.post_name"

                  listKey="post_name" listValue="post_name" headerKey="0"

                  headerValue="請(qǐng)選擇你的職位" required="true"></s:select></td>

           </tr>

           <tr>

               <td><s:checkboxlist name="skills1" label="Skills 1"

                  tooltip="bulktree" list="{'Java', '.Net', 'RoR', 'PHP' }"

                  value="{'Java', '.Net' }" /></td>

           </tr>

           <tr>

               <td><s:checkboxlist name="skills2" label="Skills 2"

                  tooltip="bulktree" list="#{1:'Java', 2:'.Net', 3:'RoR', 4:'PHP' }"

                  listKey="key" listValue="value" value="{1, 2, 3 }" /></td>

           </tr>

           <tr>

               <td><s:doubleselect label="doubleselect test1" name="menu"

                  list="{'fruit','other'}" doubleName="dishes"

                  doubleList="top == 'fruit' ? {'apple', 'orange'} : {'monkey', 'chicken'}" />

               </td>

           </tr>

           <tr>

               <td><s:updownselect label="Favourite Countries"

                  list="#{'england':'England', 'america':'America', 'germany':'Germany'}"

                  name="prioritisedFavouriteCountries" headerKey="-1"

                  headerValue="--- Please Order Them Accordingly ---"

                  emptyOption="true" /></td>

           </tr>

           <tr>

               <td><s:optiontransferselect

                  tooltip="Select Your Favourite Cartoon Characters"

                  label="Favourite Cartoons Characters"

                  name="leftSideCartoonCharacters" leftTitle="Left Title"

                  rightTitle="Right Title" list="{'Popeye', 'He-Man', 'Spiderman'}"

                  multiple="true" headerKey="headerKey"

                  headerValue="--- Please Select ---" emptyOption="true"

                  doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"

                  doubleName="rightSideCartoonCharacters"

                  doubleHeaderKey="doubleHeaderKey"

                  doubleHeaderValue="--- Please Select ---" doubleEmptyOption="true"

                  doubleMultiple="true" /></td>

           </tr>

           <tr>

               <td><s:submit></s:submit></td>

           </tr>

        </table>

    </s:form></center>

    </body>

    </html>

    注意:上面的代碼不需要用table布局,Struts2內(nèi)置了表格功能,run顯示如下:

     


       
    上面的代碼都是一些簡(jiǎn)單的值顯示,實(shí)際的開發(fā)所出現(xiàn)的數(shù)據(jù)都不是現(xiàn)成的。大家可能注意了這段代碼:
       

    <tr>

               <td><s:select list="posts" name="post.post_name"

                  listKey="post_name" listValue="post_name" headerKey="0"

                  headerValue="請(qǐng)選擇你的職位" required="true"></s:select></td>

           </tr>


    下來就來說說Struts2 tag怎么顯示List/Map/Set里的值:
    采用POJO方式訪問 VO是一些最基本的getter/setter省略不寫。
        action
    代碼:

    package com.bulktree.AutoOffice.action;

    import java.util.List;

    import java.util.Map;

    import com.bulktree.AutoOffice.factory.DAOFactory;

    import com.bulktree.AutoOffice.vo.Client;

    import com.bulktree.AutoOffice.vo.ClientUser;

    import com.bulktree.AutoOffice.vo.User;

    import com.opensymphony.xwork2.ActionContext;

    import com.opensymphony.xwork2.ActionSupport;

    publicclass ClientUserAction extends ActionSupport {

       

        private List<Client> clients;

        private List<User> users;

       

        public List<Client> getClients() {

           returnclients;

        }

        publicvoid setClients(List<Client> clients) {

           this.clients = clients;

        }

        public List<User> getUsers() {

           returnusers;

        }

        publicvoid setUsers(List<User> users) {

           this.users = users;

        }

        public String queryClientID() throws Exception {

           Map session = ActionContext.getContext().getSession();

           String userid = (String)session.get("userid");

          

           setUsers(DAOFactory.getEmployeeInstance().queryUidUserid());

           setClients(DAOFactory.getClientInstance().queryByAll(userid));

          

           returnSUCCESS;

        }

    }


       
    下面是用來測(cè)試上面actionjsp頁面:分別使用了<s:select/> <s:doubleselect /> <s:updownselect />來接收List集合里的值

    <s:form action="clientuser_changeClient" method="post">

           <s:doubleselect list="clients" name="client.client_id"

               listKey="client_id" listValue="client_id"

               doubleName="client.client_name" doubleList="clients"

               doubleListKey="client_name" doubleListValue="client_name" />

           <s:updownselect label="All Clients ID" tooltip="show all clients"

               list="clients" headerKey="0" headerValue="--所有客戶編號(hào)--"

               listKey="client_id" listValue="client_id" emptyOption="true"

               moveUpLabel="向上" moveDownLabel="向下" selectAllLabel="全選" />

           <s:updownselect label="All Clients name" tooltip="show all clients"

               list="clients" headerKey="0" headerValue="--所有客戶姓名--"

               listKey="client_name" listValue="client_name" moveUpLabel="向上"

               moveDownLabel="向下" selectAllLabel="全選" emptyOption="true" />

           <s:select list="clients" name="clientuser.client_id"

               tooltip="Change Your Client" label="選擇你將要轉(zhuǎn)讓的客戶" listKey="client_id"

               listValue="client_id" required="true" />

           <s:select list="users" name="clientuser.userid" label="將要轉(zhuǎn)讓給同事"

               tooltip="Choose your partner" listKey="userid" listValue="userid"

               required="true" />

           <s:submit value=" 確認(rèn)轉(zhuǎn)讓 " onclick="alert('轉(zhuǎn)讓后你就失去了該客戶');" />

        </s:form>


       
    說說最簡(jiǎn)單的<s:selelct />其他的以此類推:
    ·select標(biāo)簽必須屬性只有一個(gè)為List
    ·select一定要有值,否則出錯(cuò)。如果我們?cè)?/span>html中使用select時(shí)會(huì)有個(gè)默認(rèn)的值,在Struts2中也是一樣的,如果List,沒有值可以加上headerKey,headerValue就可以通過。
    ·List屬性的值在Action中定義,必須為一個(gè)迭代的List/Map/Set,本例采用List
    · listKey對(duì)應(yīng)html表單select中的value,listValue對(duì)應(yīng)html表單中的option
    ·List/SetlistKeylistValue是一樣的
    ·如果是Map,則mapkey對(duì)應(yīng)key,mapvalue對(duì)應(yīng)value
       
    如下代碼:

    <s:select list="clients" name="clientuser.client_id"

               tooltip="Change Your Client" label="選擇你將要轉(zhuǎn)讓的客戶" listKey="client_id"

               listValue="client_id" required="true" />

        Clientsactionlist的對(duì)象,也就是getter/setter方法的名字,Struts2支持POJO訪問,listKey的值”client_id”則為VO對(duì)象 (client)的屬性(client_id(Struts2支持OGNL)我們還可以加上headerKeyheaderValue用以顯示首行的提示,大家可以加上試試,注意:headerKey的值不能為-1否則編譯不能通過。
        <s:doubleselect />
    <s:select />運(yùn)行機(jī)制是一樣的,不同的就是<s:doubleselect />顯示的是兩個(gè)list/doubleList的值,doubleList的值牽制于list的值,它的內(nèi)部實(shí)現(xiàn)機(jī)制是采用JavaScript
       

    <s:doubleselect list="clients" name="client.client_id"

               listKey="client_id" listValue="client_id"

               doubleName="client.client_name" doubleList="clients"

               doubleListKey="client_name" doubleListValue="client_name" />

        這個(gè)<s:doubleselect />是有問題的,只是為了演示有值,但是沒有真正起到doubleselect的作用,doubleList是按編號(hào)取值的,doubleList對(duì)應(yīng)Map中一個(gè)keyvalue。采用本例的話可以把這樣做:

    Map<Integer, List<clients>> maps = new HashMap<Integer, List<clients>>();

    maps.put(1, clients);

    maps.put(2, clients);

    maps.put(3, clients);

     
    maps
    key為第一級(jí)下拉列表的listKeytopclient的實(shí)例

    <s:doubleselect list="clients" name="client.client_id"

               listKey="id" listValue="client_id"

               doubleName="client.client_name" doubleList="maps.get(top. id)"

               doubleListKey="client_name" doubleListValue="client_name" />

    posted on 2008-04-02 08:46 凌晨風(fēng) 閱讀(10414) 評(píng)論(8)  編輯  收藏 所屬分類: Spring/Hibernate/Struts2

    FeedBack:
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-04-02 09:07 | 凌晨風(fēng)
    順便說說,畢業(yè)在即,我的系統(tǒng)側(cè)重業(yè)務(wù)邏輯,主要是想用Struts2,嚴(yán)格按照MVC三大模塊做,業(yè)務(wù)邏輯全部封裝在DAO工廠中,前臺(tái)JSP顯示OGNL,由于導(dǎo)師要求后面加了QQ/MSN、短信平臺(tái)(測(cè)試成功未實(shí)現(xiàn)),哪位能提供個(gè)就業(yè)的機(jī)會(huì),本人感激不盡,后續(xù)將繼續(xù)整理系統(tǒng)的相關(guān)知識(shí)發(fā)布上來。謝謝關(guān)注!  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-05-08 17:31 | 愛愛愛
    建議業(yè)務(wù)邏輯放在Bo 中  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-07-08 14:21 | 汽車
    寫的真好,struts2就是好用.  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-08-14 17:35 | KingBack
    嗨, 你好, select List試了半天總是不成功, 能把你用select的完整代碼貼出來嗎?  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-09-13 14:50 | waylon
    LZ能不能把源代碼貼出來啊,我調(diào)試了兩天,沒成功,有個(gè)錯(cuò)誤
    tag 'select', field 'list', name 'post.post_name': The requested list key 'Category' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-11-19 19:02 | 有點(diǎn)暈
    select的還是不行,可不可以把你
    <tr>

    <td><s:select list="posts" name="post.post_name"

    listKey="post_name" listValue="post_name" headerKey="0"

    headerValue="請(qǐng)選擇你的職位" required="true"></s:select></td>

    </tr>
    對(duì)應(yīng)的action代碼貼出來看看呢?  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2008-11-20 10:20 | 凌晨風(fēng)
    這些是我畢業(yè)設(shè)計(jì)里的東東摘出來寫了點(diǎn),最近忙一項(xiàng)目沒有時(shí)間找這些,你要是需要的話我把整個(gè)包發(fā)給你吧!laoshulin@gmail.com  回復(fù)  更多評(píng)論
      
    # re: Struts2中select/doubleselect標(biāo)簽數(shù)據(jù)顯示
    2009-01-03 18:27 | 曾紅偉
    其實(shí)作者沒有寫全,s:select要想從數(shù)據(jù)庫中獲取值,首先創(chuàng)建一個(gè)action,然后在s:select標(biāo)簽前加一段話:
    <s:action name="***" id="***"></s:action>
    <s:set name="**" value="#***.**"></s:set>  回復(fù)  更多評(píng)論
      

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    <2008年11月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    30123456

    常用鏈接

    留言簿(11)

    我參與的團(tuán)隊(duì)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    收藏夾

    圍脖

    最新隨筆

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲av伊人久久综合密臀性色| 亚洲an日韩专区在线| 亚洲heyzo专区无码综合| 一个人免费视频在线观看www| 日韩一级视频免费观看| 337p欧洲亚洲大胆艺术| www成人免费观看网站| 思思99re66在线精品免费观看| 久久亚洲精品无码| 日韩成人毛片高清视频免费看| xxxxwww免费| 亚洲AV无码一区二区二三区入口| 黄色免费网址在线观看| 成全高清视频免费观看| 亚洲精品午夜在线观看| 国色精品va在线观看免费视频| 吃奶摸下高潮60分钟免费视频| 亚洲一区二区三区丝袜| 国产精品成人观看视频免费| 亚洲av中文无码乱人伦在线咪咕| 极品美女一级毛片免费| 日本免费人成黄页在线观看视频| 亚洲av无码一区二区三区观看| 无码日韩精品一区二区免费暖暖 | 免费大香伊蕉在人线国产| 亚洲伊人久久精品| 91高清免费国产自产拍2021| 国产成人精品日本亚洲| 国产成人1024精品免费| 亚洲AⅤ永久无码精品AA| 久久无码av亚洲精品色午夜| 最近最好的中文字幕2019免费| 亚洲字幕在线观看| 91av视频免费在线观看| 亚洲男人第一av网站| 国产一精品一av一免费爽爽| 亚洲免费观看视频| 中国国产高清免费av片| 亚洲综合日韩久久成人AV| 精品国产免费一区二区三区| 亚洲性日韩精品国产一区二区|