我在表单中有一个表格,其中包含下拉列表和隐藏的 input
.
I have a table inside a form that contains dropdowns and a hidden 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>
输出:
但是,在从下拉列表中选择一个新值并单击 Save
时,我收到一个错误消息.以下是 devMode
日志:
However, upon choosing a new value from the dropdown and clicking Save
, I am receiving an error. Below is the devMode
log:
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]]!
如何解决?
你不需要提交表的所有个id.因为您不想将 profId
转换为列表或数组.为每条记录使用单独的表格.
You don't need to submit all ids of the table. Because you don't want to convert profId
to a list or array. Use a separate form for each record.
<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>
这篇关于ParametersInterceptor error: Unexpected Exception catched, Error setting expression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!