我在一个带有两个下拉菜单的 portlet 页面中有一个表单;每次用户从第一个菜单中选择一个值时,我都想提交表单,以便我可以填充第二个菜单。真正的提交是在用户单击一个按钮时处理的,该按钮调用一个在提交表单之前设置区分参数的 JavaScript。
这是成功重定向到 JSP inserisciOrganoEnteBando的页面中的操作 bean :
<bean id="aggiungiEnteOrganoBando" class="it.milano.comune.pi.nomine.service.AggiungiEnteOrganoBando">
<property name="sessionForm" value="true" />
<property name="commandName" value="aggiungiEnteOrganoBandoForm" />
<property name="commandClass" value="it.milano.comune.pi.nomine.backoffice.model.AggiungiEnteOrganoBandoForm" />
<property name="formView" value="gestisciOrganiEntiBando" />
<property name="successView" value="inserisciOrganoEnteBando" />
<property name="entiOrganiDao" ref="entiOrganiDao" />
<property name="entiDao" ref="entiDao" />
</bean>
在控制器中使用此onSubmitRender
方法:AggiungiEnteOrganoBando
protected ModelAndView onSubmitRender(RenderRequest request, RenderResponse response, Object obj, BindException exceptions)
throws Exception {
PortletSession session = request.getPortletSession();
Map results = (Map) session.getAttribute("results");
ModelAndView mav = new ModelAndView(getSuccessView(), "results", results);
Map listaEnti= (Map)results.get("listaEnti");
mav.addObject("listaEnti", listaEnti);
return mav;
}
这是来自 JSP inserisciOrganoEnteBando的表格:
<form id="insertEnteOrganoBandoForm" name="insertEnteOrganoBandoForm" method="POST" class="form-search"
action='<portlet:actionURL>
<portlet:param name="action" value="insertEnteOrganoBando" />
</portlet:actionURL>'
>
<label for="id_ente">Ente</label>
<select id="id_ente" name="id_ente" onchange="realSubmit('KO')">
<option value="" label="Seleziona ente"/>
<c:forEach var="lie" items="${listaEnti}">
<option value="<c:out value="${lie.key}"/>" label="<c:out value="${lie.value}"/>" />
</c:forEach>
</select><br>
<label for="id_ente_organo">Organo</label>
<select id="id_ente_organo" name="id_ente_organo">
<option value="" label="Seleziona organo"/>
<c:forEach var="leo" items="${listaEntiOrgani}">
<option value="<c:out value="${leo.key}"/>" label="<c:out value="${leo.value}"/>" />
</c:forEach>
</select><br>
<label for="descrizione">Descrizione</label>
<textarea id="descrizione" name="descrizione"></textarea><br>
<input type="hidden" id="tipoSubmit" name="tipoSubmit"/>
<input type="hidden" id="id_bando" name="id_bando" value="<%= id_bando %>"/>
<input type="button" id="confirmInsertEnteOrganoBando" name="confirmInsertEnteOrganoBando" class="wpsButtonText btn" value="Aggiungi"
onclick="realSubmit('OK')"/>
</form>
变量 *id_bando*、listaEnti和listaEntiOrgani都从前一个控制器正确传递到 JSP,并且第一个下拉列表正确填充,而第二个下拉列表如预期的那样为空。
这是 JavaScript:
<script type="text/javascript">
var realSubmit = function(stato){
$("#tipoSubmit").val(stato);
document.forms["insertEnteOrganoBandoForm"].submit();
};
</script>
我使用该变量tipoSubmit
来检查用户是否真的提交了表单,或者只是从第一个下拉菜单中选择了一个元素。
这是表单对象:
public class InsertEnteOrganoBandoForm {
private Long id_ente;
private Long id_ente_organo;
private String descrizione;
private String tipoSubmit;
private Long id_bando;
public Long getId_ente() {
return id_ente;
}
public void setId_ente(Long id_ente) {
this.id_ente = id_ente;
}
public Long getId_ente_organo() {
return id_ente_organo;
}
public void setId_ente_organo(Long id_ente_organo) {
this.id_ente_organo = id_ente_organo;
}
public String getDescrizione() {
return descrizione;
}
public void setDescrizione(String descrizione) {
this.descrizione = descrizione;
}
public String getTipoSubmit() {
return tipoSubmit;
}
public void setTipoSubmit(String tipoSubmit) {
this.tipoSubmit = tipoSubmit;
}
public Long getId_bando() {
return id_bando;
}
public void setId_bando(Long id_bando) {
this.id_bando = id_bando;
}
}
这是动作 bean:
<bean id="insertEnteOrganoBando" class="it.milano.comune.pi.nomine.service.InsertEnteOrganoBando">
<property name="sessionForm" value="true" />
<property name="commandName" value="insertEnteOrganoBandoForm" />
<property name="commandClass" value="it.milano.comune.pi.nomine.backoffice.model.InsertEnteOrganoBandoForm" />
<property name="formView" value="inserisciOrganoEnteBando" />
<property name="successView" value="inserisciOrganoEnteBando" />
<property name="bandiEntiOrganiDao" ref="bandiEntiOrganiDao" />
<property name="entiOrganiDao" ref="entiOrganiDao" />
<!-- <property name="validator" ref="insertEnteOrganoBandoValidator" />-->
</bean>
验证器被暂时禁用,DAO 被正确初始化和注入,并且 bean 映射为:
<entry key="insertEnteOrganoBando" value-ref="insertEnteOrganoBando" />
我的问题是,当从控制器formBackingObject
调用该方法时,对象是,甚至不是空表单。InsertEnteOrganoBando
sessionForm
null
protected Object formBackingObject(PortletRequest request) throws Exception {
PortletSession session = request.getPortletSession();
InsertEnteOrganoBandoForm sessionForm = (InsertEnteOrganoBandoForm) session.getAttribute("InsertEnteOrganoBandoForm");
if (sessionForm != null)return sessionForm;
return super.formBackingObject(request);
}
这个结构与我在我的 portlet 中用于所有其他页面/控制器/表单/...的结构完全相同,没有问题。我检查了所有名称的拼写错误或不同的情况,一切都很好。
我错过了什么?
PS:我知道 AJAX,但我不能使用它,我正在使用 Java 4、Spring 2、IBM WebSphere 6、Eclipse、IE9,我不能进入 Java 调试模式,只有 JavaScript。
提前致谢