ParametersInterceptor错误:捕获到意外异常,错误设置表达式

时间:2015-01-05 11:31:06

标签: java html jsp parameters struts2

我在表格中有一个表格,其中包含下拉列表和隐藏的input

JSP

<form action="modifyfaculty" method="post">
    <table>
        <thead class="center">
            <tr>
                <!-- column names here -->
            </tr>
        </thead>

        <tbody>
            <c:forEach var="professor" items="${facultyList}">
                <tr>
                    <!-- more <td> -->

                    <td align="center">
                        <c:choose>
                            <c:when test="${professor.profEmplStatus.equals('FULL')}">
                                <select name="profEmplStatus" required>
                                    <option value="FULL" selected>FULL</option>
                                    <option value="PART">PART</option>
                                    <option value="RET">RET</option>
                                    <option value="TRMTD">TRMTD</option>
                                </select>
                            </c:when>

                            <!-- more <c:when> blocks -->
                        </c:choose>
                    </td>

                    <td align="center">
                        <c:choose>
                            <c:when test="${professor.profDept.equals('BSCS-SE')}">
                                <select name="profDept" required>
                                    <option value="BA-MMA">BA-MMA</option>
                                    <option value="BFDT">BFDT</option>
                                    <option value="BS-AN">BS-AN</option>
                                    <option value="BS-GPD">BS-GPD</option>
                                    <option value="BSBA-FM">BSBA-FM</option>
                                    <option value="BSBA-MKT">BSBA-MKT</option>
                                    <option value="BSCS-SE" selected>BSCS-SE</option>
                                    <option value="BSIT-WD">BSIT-WD</option>
                                    <option value="GENED">GENED</option>
                                </select>
                            </c:when>

                            <!-- more <c:when> blocks -->
                        </c:choose>
                    </td>

                    <td class="center">
                        <input type="hidden" name="profId" value="${professor.profId}" />
                        <input type="submit" value="Save" />
                    </td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
</form>

ModifyFacultyAction

public class ModifyFacultyAction extends ActionSupport {
    private static final long serialVersionUID = 1L;

    private Integer profId;
    private String profEmplStatus;
    private String profDept;

    @Override
    public String execute() {
        FacultyManager fm = new FacultyManager();
        fm.modifyFaculty("professor_employment_status", profEmplStatus, profId);
        fm.modifyFaculty("professor_department", profDept, profId);

        return SUCCESS;
    }

    public Integer getProfId() {
        return profId;
    }

    public void setProfId(Integer profId) {
        this.profId = profId;
    }

    public String getProfEmplStatus() {
        return profEmplStatus;
    }

    public void setProfEmplStatus(String profEmplStatus) {
        this.profEmplStatus = profEmplStatus;
    }

    public String getProfDept() {
        return profDept;
    }

    public void setProfDept(String profDept) {
        this.profDept = profDept;
    }
}

struts.xml

<action name="modifyfaculty" class="com.mypackage.action.ModifyFacultyAction">
    <interceptor-ref name="notauth" />
    <interceptor-ref name="defaultStack" />

    <result type="redirectAction">
        <param name="actionName">viewfaculty</param>
    </result>

    <result name="input" type="redirectAction">
        <param name="actionName">viewfaculty</param>
    </result>

    <result name="index" type="redirect">/index.jsp</result>
</action>

输出: enter image description here

但是,从下拉列表中选择新值并点击Save后,我收到错误消息。以下是devMode日志:

Jan 05, 2015 11:34:43 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'profId' on 'class com.mypackage.action.ModifyFacultyAction: Error setting expression 'profId' with value ['100005', '100006', '100007', '100008', '100009', '100010', '100011', ]
Jan 05, 2015 11:34:43 PM com.opensymphony.xwork2.util.LocalizedTextUtil warn
WARNING: Missing key [invalid.fieldvalue.profId] in bundles [[org/apache/struts2/struts-messages, com/opensymphony/xwork2/xwork-messages]]!

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您不需要提交表格的所有 ID。因为您不想将profId转换为列表或数组。为每条记录使用单独的表格。

<table>
    <thead class="center">
        <tr>
            <!-- column names here -->
        </tr>
    </thead>

    <tbody>
        <c:forEach var="professor" items="${facultyList}">
          <tr><td>
          <form action="modifyfaculty" method="post">
          <table>
            <tr>
                <!-- more <td> -->

                <td align="center">
                    <c:choose>
                        <c:when test="${professor.profEmplStatus.equals('FULL')}">
                            <select name="profEmplStatus" required>
                                <option value="FULL" selected>FULL</option>
                                <option value="PART">PART</option>
                                <option value="RET">RET</option>
                                <option value="TRMTD">TRMTD</option>
                            </select>
                        </c:when>

                        <!-- more <c:when> blocks -->
                    </c:choose>
                </td>

                <td align="center">
                    <c:choose>
                        <c:when test="${professor.profDept.equals('BSCS-SE')}">
                            <select name="profDept" required>
                                <option value="BA-MMA">BA-MMA</option>
                                <option value="BFDT">BFDT</option>
                                <option value="BS-AN">BS-AN</option>
                                <option value="BS-GPD">BS-GPD</option>
                                <option value="BSBA-FM">BSBA-FM</option>
                                <option value="BSBA-MKT">BSBA-MKT</option>
                                <option value="BSCS-SE" selected>BSCS-SE</option>
                                <option value="BSIT-WD">BSIT-WD</option>
                                <option value="GENED">GENED</option>
                            </select>
                        </c:when>

                        <!-- more <c:when> blocks -->
                    </c:choose>
                </td>

                <td class="center">
                    <input type="hidden" name="profId" value="${professor.profId}" />
                    <input type="submit" value="Save" />
                </td>
            </tr>
           </table>
          </form>
         </td></tr>
        </c:forEach>
    </tbody>
</table>