【JSP】struts标签BUG合集

1.<s:file>标签的使用

此标签的特点是用来传文件,要用到流,所以提交参数的时候不能是简单的post,需要指定enctype类型。或者再<s:form>中直接指定属性,或者在提交时调用的function中设置。代码如下:

    // 导入订单
    function importOrder() {//enctype="multipart/form-data"
        document.forms["myForm"].enctype="multipart/form-data";
        document.forms["myForm"].action = "trade!batchSendEmailOrderImport.html?";
        document.forms["myForm"].submit();
    }

 另外如果以弹窗的方式来使用<s:file>标签则需要调用appendto()方法进行一次插入指定,具体原因尚不明。

html代码为:

<!-- 导入订单弹框 -->
        <div id="dialog_target"></div>
        <div id="dlgAddValue" class="easyui-dialog" title="导入订单 "
            data-options="iconCls:'icon-save',buttons: '#dlg-buttons-meals',resizable:true,modal:true"
            style="width: 750px; height: 420px; padding: 5px; position: relative; top: 5px;">
            <table>
                <tr>
                    <td>
                        <table align="center" cellpadding="10px"
                            style="border-width: 1px 1px 1px 1px; border-spacing: 0; border-style: solid; border-color: #95B8E7;">
                            <tbody>
                                <tr>
                                    <td>选择文件:</td>
                                    <td colspan="2"><s:file name="excel" id="excelName" />&nbsp;&nbsp;
                                        <button type="button" onclick="return importOrder();">导入订单</button>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                </tr>
                                <tr>
                                    <td colspan="4"><p /></td>
                                </tr>
                                <tr>
                                    <td colspan="4">
                                        <ul>
                                        </ul>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>

            </table>
        </div>
        </div>

js代码为:

    //打开订单导入弹框
    var flagAddValue = true;
    function openImportOrder() {
        if (flagAddValue) {
            //关闭操作
            flagAddValue = false;
            $('#dlgAddValue').dialog('close');
        } else {
            //打开操作
            flagAddValue = true;
            $('#dlgAddValue').dialog('open');
            $("#dlgAddValue").parent().appendTo("#dialog_target");
        }
    }

 2:<s:iterator>中通过点击按钮获取指定某行某列的值

这里要实现的功能是点击某列的按钮之后将该行的input中填入的值与<s:property>中显示的值传回后台action中。

html部分代码为:

<table id="stupidtable" width="100%" align="center" class="table">
            <caption>
            <s:if test="cardPwListType == @cn.com.chinatelecom.ecms.action.TradeAction$CardPwListType@All">
                全部卡密列表
            </s:if>
            <s:elseif test="cardPwListType == @cn.com.chinatelecom.ecms.action.TradeAction$CardPwListType@Send">
                已发卡密列表
            </s:elseif>
            <s:elseif test="cardPwListType == @cn.com.chinatelecom.ecms.action.TradeAction$CardPwListType@UnSend">
                待发卡密列表
            </s:elseif>
        </caption>
            <thead>
                <tr>
                    <th data-sort="int">序号</th>
                    <th data-sort="string">订单编号</th>                    
                    <th data-sort="string">收货人email</th>
                    <th data-sort="string">换发email</th>
                    <th data-sort="string">订单类型</th>
                    <th data-sort="string">订单状态</th>
                    <th data-sort="string">AB分类</th>
                    <th data-sort="string">拆单类型</th>
                    <th data-sort="string">所在省</th>
                    <th data-sort="string">所在市</th>
                    <th data-sort="float">金额(元)</th>
                    <th data-sort="string">支付方式</th>
                    <th data-sort="date">订单生成时间</th>
                    <th data-sort="date">支付确认时间</th>
                    <th data-sort="date">支付完成时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <s:iterator value="ddzflist" id="order" status="status">
                    <tr onmouseover="this.bgColor='#EAF2FF'"
                        onmouseout="this.bgColor='#FFFFFF'" align="center">
                        <th><s:property
                                value="%{(#request.pageInfo.pageNo - 1) * #request.pageInfo.pageSize + #status.index + 1}" />
                        </th>
                        <%-- <s:iterator value="#order" id="content" status="status">
                             <td>
                            <s:property value="#content" />
                            </td>
                        </s:iterator> --%>
                        <td ><s:property value="#order.orderId" /></td>
                        <td ><s:property value="#order.dealPayInfo.sendCusemail" /></td>
                        <td><input type="text" id="field1" /><s:hidden value="#emailReceiver" /></td>
                        <td align="left"><s:property value="#order.orderType.dicCn" /></td>
                        <td align="left"><s:property value="#order.orderStatus.dicCn" /></td>
                        <td><s:property value="#order.abType.dicCn" /></td>
                        <td><s:property value="#order.isSplit.dicCn" /></td>
                        <td align="left"><s:property
                                value="#order.provSystemCity.cname" /></td>
                        <td align="left"><s:property
                                value="#order.citySystemCity.cname" /></td>
                        <td align="right"><s:property value="#order.orderPriceText" /></td>
                        <td align="left"><s:property value="#order.payType.dicCn" /></td>
                        <td><s:date name="#order.orderCreatetime"
                                format="yyyy-MM-dd HH:mm" /></td>
                        <td><s:date name="#order.payCommitTime"
                                format="yyyy-MM-dd HH:mm" /></td>
                        <td><s:date name="#order.orderPayTime"
                                format="yyyy-MM-dd HH:mm" /></td>
                        
                        <td align="center">
                        <%-- <s:a href="%{url}">明细</s:a>&nbsp&nbsp
                        <s:a href="%{url1}">重发</s:a>&nbsp&nbsp
                        <s:a href="%{url2}"  onclick="return test($(this).parent().parent().find('input').val());">换发</s:a> --%>
                        <button type="button" onclick="return queryOrderList();">明细</button>
                        <button type="button" onclick="return queryOrderList();">重发</button>
                        <button type="button" onclick="return changeSend(this);">换发</button></td>
                    </tr>
                </s:iterator>
                <s:hidden name="cardPwAddr" value="%{#request.cardPwAddr}"></s:hidden>
            </tbody>

            <tfoot>
                <tr>
                    <td colspan="16"><s:if test="cardPwList.size > 0">
                            <div align="right">
                                <p:pages pageNo="pageInfo.pageNo" total="pageInfo.total"
                                    pageSize="pageInfo.pageSize" count="pageInfo.count"
                                    includes="orderInfo.orderId" />
                            </div>
                        </s:if></td>
                </tr>
            </tfoot>
        </table>

重点是换发的changeSend()实现。首先是把this指针传进去,方便定位到该行,再做进一步操作。

JS代码为:

function changeSend(content){
        var orderId="";
        $(content).parent().parent().find("td").each(function(i){
            if(i==0){
                orderId = $(this).text();
            }
        });
        var newEmail= $(content).parent().parent().find("input").val();
        document.forms["myForm"].action = "trade!changeSendCardPw.html?emailReceiver="+newEmail
                +"&orderInfo.orderId="+orderId;
        document.forms["myForm"].submit();
        return;
    }

根据table的DOM结构,可知$(content).parent()取到的是button所在的父节点,即button所在的td标签。再取一次parent(),得到的就是td所在的行,即tr标签。

然后用find()函数来查找内容,参数为标签类型。tr中包含的td标签有很多,但是我们可以知道需要的orderId在第一个td中,所以直接在i==0时抓值即可。

另外td标签中的内容是用.text()取到。循环中,this指针表示的是当前对象,也即循环中的当前td。

input标签只有一个,所以直接取值即可。

需要说明的是,在table的HTML中加了<s:hidden>特意放入emailReceiver变量,是因为如果不这样做则在生成页面的时候不会将此变量解析为html代码,那么在changeSend()中向action传值的时候就无法找到emailReceiver

posted @ 2013-12-30 17:11  cheps  阅读(351)  评论(0编辑  收藏  举报