carlos_santiago
Oct 18th, 2005, 03:36 PM
I have one jsp that he has several checkbox and a list of registers must be presented when the page is presented the first time.
For this I am using a SimpleFormControler and overrinding its referenceData to set one map with the registers.
However this jps has two icons that can be click to submit the selected data of checkbox.
I submit these data for a AbstractCommandController and process these data, but my controller does not show jsp of success.
Submit for the AbstractCommandController is made through Javascript. Which the best strategy of controller for this situation?
Resume:
I have a SimpleFormController that he shows jsp with the registers and in this jsp one javascript that submits form for a AbstractCommandController, and this functions well.
However, the AbstractCommandController does not return any view that she is inserted in ModelAndView, also views that they do not exist do not launch errors.
I do not know what he can be happening or if he is possible to make this with the Spring.
Any aid will be coming well.
My codes:
the SimpleFormController
public class ListaFornecedoresControlador extends SimpleFormController {
private Fornecedor fornecedor;
protected Map referenceData(HttpServletRequest request) {
return fornecedor.listaFornecedores();
}
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object obj, BindException erros)
throws Exception {
FornecedorBean bean = (FornecedorBean) obj;
Map lista = fornecedor.listaFornecedoresPorTipo(new Integer(bean
.getTipoFornecedor()));
return new ModelAndView(getSuccessView(), lista).addAllObjects(erros
.getModel());
}
/**
* @param fornecedor
* seta o valor de fornecedor na variƔvel fornecedor.
*/
public void setFornecedor(Fornecedor fornecedor) {
this.fornecedor = fornecedor;
}
}
the configuration file for this controller:
<bean id="listaFornecedoresControlador" class="br.com.rodobens.web.fornecedor.ListaFornecedoresCo ntrolador">
<property name="sessionForm" value="true"/>
<property name="commandName" value="fornecedor"/>
<property name="commandClass" value="br.com.rodobens.beans.fornecedor.FornecedorBean"/>
<property name="formView" value="fornecedor/ListaFornecedores"/>
<property name="successView" value="fornecedor/ListaFornecedores"/>
<property name="fornecedor" ref="fornecedor"/>
</bean>
.
.
.
<bean id="statusFornecedoresControlador" class="br.com.rodobens.web.fornecedor.StatusFornecedoresC ontrolador">
<property name="fornecedor" ref="fornecedor"/>
</bean>
.
.
.
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/fornecedores/listaFornecedores.lpw">listaFornecedoresControlador</prop>
<prop key="/fornecedores/statusFornecedores.lpw">statusFornecedoresControlador</prop>
</props>
</property>
</bean>
My AbstractCommandController:
public class StatusFornecedoresControlador extends AbstractCommandController{
private Fornecedor fornecedor;
private static final String EXCLUIR = "excluir";
private static final String INCLUIR = "incluir";
public StatusFornecedoresControlador(){
this.setCommandClass(FornecedorBean.class);
}
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response,
Object obj, BindException erros) throws Exception {
FornecedorBean bean = (FornecedorBean)obj;
if(request.getParameter("parametro").equals(INCLUIR))
fornecedor.mudaStatusFornecedores(new Integer(DominioStatus.ATIVO), bean.getCodigoFornecedor());
else if(request.getParameter("parametro").equals(EXCLUIR))
fornecedor.mudaStatusFornecedores(new Integer(DominioStatus.INATIVO), bean.getCodigoFornecedor());
return new ModelAndView("Sucesso");
}
/**
* @param fornecedor seta o valor de fornecedor na variƔvel fornecedor.
*/
public void setFornecedor(Fornecedor fornecedor) {
this.fornecedor = fornecedor;
}
}
and, finally, my jsp with javascript function:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/views/includes.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function enviaConsulta(valor){
document.forms[0].tipoFornecedor.value=valor;
document.forms[0].submit();
}
</script>
<SCRIPT>
function submitFunction(valor) {
if (valor==1)
document.forms[0].action="listaFornecedores.lpw?parametro=excluir";
if(valor == 2)
document.forms[0].action="listaFornecedores.lpw?parametro=incluir";
document.forms[0].submit();
}
</SCRIPT>
<script language="JavaScript1.2" src="<c:url value="/scripts/mm_menu.js"/>"></script>
<%@ include file="/WEB-INF/views/menuLinkPecas.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><fmt:message key="title"/></title>
<link rel="stylesheet"type="text/css" href="<c:url value="/css/layout.css"/>" />
</head>
<body>
<%@ include file="/WEB-INF/views/cabecalho.jsp"%>
<FORM method="POST" action="listaFornecedores.lpw"/>
<table width="768" height="27" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="157" align="center"><!--DWLayoutEmptyCell--></td>
<td width="611"><table width="584" border="0" class=fonte01>
<tr>
<td width="621"><img src="<c:url value="/img/t_lst_fornecedor.gif"/>" width="248" height="30">
<table width="554" border="0" class=fonte01>
<tr>
<td width="359" height="23">Selecione um fornecedor. <strong></strong></td>
<td width="185"><div align="right">
<select class=fonte01 name="tipoFornecedor" onchange="enviaConsulta(this.value)">
<option>Selecione</option>
<option value=<%=DominioTipoFornecedor.TODOS %>>Todos os tipos</option>
<option value=<%=DominioTipoFornecedor.PRINCIPAL %>>Principal</option>
<option value=<%=DominioTipoFornecedor.SECUNDARIO %>>Secundário</option>
</select>
</div></td>
</tr>
</table>
<br>
<table width="602" border="1" bordercolor="#999999" bgcolor="#999999" class=fonte01>
<tr bordercolor="#999999" bgcolor="#999999">
<td width="14"></td>
<td width="130" bordercolor="#999999"><div align="left"><span class="style6">Nome</span></div></td>
<td width="98" bordercolor="#999999"><div align="left"><span class="style6">Cidade</span></div></td>
<td width="104" bordercolor="#999999"><div align="left"><span class="style6">Telefone</span></div></td>
<td width="152" bordercolor="#999999"><div align="left"><span class="style6">Vendedor</span></div></td>
<td width="64" bordercolor="#999999" class="style6">Status</td>
</tr>
</table>
<table width="603" border="1" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" bgcolor="#F7F7F7" class=fonte01>
<c:forEach var="fornecedor" items="${listaFornecedoresAtivos}">
<tr>
<td width="22"><div align="center">
<spring:bind path="fornecedor.codigoFornecedor">
<input type="checkbox" name="codigoFornecedor" value="<c:out value="${fornecedor.codigoFornecedor}"/>">
<!-- erro do campo -->
<FONT color="red" size="0"><c:out value="${status.errorMessage}"/></FONT>
</spring:bind>
</div></td>
<td width="132"><div align="left"><c:out value="${fornecedor.nomeFornecedor}"/></div></td>
<td width="103"><div align="left"><c:out value="${fornecedor.cidade}"/> </div></td>
<td width="107"><div align="left"><c:out value="${fornecedor.telefone}"/> </div></td>
<td width="156"><div align="left"><c:out value="${fornecedor.nomeVendedor1}"/> </div></td>
<td width="69">Ativo</td>
</tr>
</c:forEach>
</table>
<table width="58" border="0" cellspacing="0" cellpadding="0">
<!--DWLayoutTable-->
<tr valign="bottom">
<td width="20" height="25"><div align="center"><a href="" onClick="submitFunction(1)"><img src="<c:url value="/img/trash.gif"/>" width="20" height="25" border="0"></a></div></td>
<td width="38" class="fonte01">Excluir</td>
</tr>
</table>
<br>
<table width="602" border="1" bordercolor="#999999" bgcolor="#999999" class=fonte01>
<tr bordercolor="#999999" bgcolor="#999999">
<td width="14"></td>
<td width="130" bordercolor="#999999"><div align="left"><span class="style6">Nome</span></div></td>
<td width="98" bordercolor="#999999"><div align="left"><span class="style6">Cidade</span></div></td>
<td width="104" bordercolor="#999999"><div align="left"><span class="style6">Telefone</span></div></td>
<td width="152" bordercolor="#999999"><div align="left"><span class="style6">Vendedor</span></div></td>
<td width="64" bordercolor="#999999" class="style6">Status</td>
</tr>
</table>
<table width="603" border="1" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" bgcolor="#F7F7F7" class=fonte01>
<c:forEach var="fornecedor" items="${listaFornecedoresInativos}">
<tr>
<td width="22"><div align="center">
<input type="checkbox" name="codigoFornecedor" value="<c:out value="${fornecedor.codigoFornecedor}"/>">
</div></td>
<td width="132"><div align="left"><c:out value="${fornecedor.nomeFornecedor}"/></div></td>
<td width="103"><div align="left"><c:out value="${fornecedor.cidade}"/> </div></td>
<td width="107"><div align="left"><c:out value="${fornecedor.telefone}"/> </div></td>
<td width="156"><div align="left"><c:out value="${fornecedor.nomeVendedor1}"/> </div></td>
<td width="69">Inativo</td>
</tr>
</c:forEach>
</table>
<table width="61" border="0" cellspacing="0" cellpadding="0">
<!--DWLayoutTable-->
<tr valign="bottom">
<td width="24" height="25" class="fonte01"><a href="" onClick="submitFunction(2)"><img src="<c:url value="/img/certo.gif"/>" width="20" height="25" border="0"></a></td>
<td width="37" class="fonte01">Incluir</td>
</tr>
</table>
<p></p></td>
</tr>
</table>
</body>
</html>
For this I am using a SimpleFormControler and overrinding its referenceData to set one map with the registers.
However this jps has two icons that can be click to submit the selected data of checkbox.
I submit these data for a AbstractCommandController and process these data, but my controller does not show jsp of success.
Submit for the AbstractCommandController is made through Javascript. Which the best strategy of controller for this situation?
Resume:
I have a SimpleFormController that he shows jsp with the registers and in this jsp one javascript that submits form for a AbstractCommandController, and this functions well.
However, the AbstractCommandController does not return any view that she is inserted in ModelAndView, also views that they do not exist do not launch errors.
I do not know what he can be happening or if he is possible to make this with the Spring.
Any aid will be coming well.
My codes:
the SimpleFormController
public class ListaFornecedoresControlador extends SimpleFormController {
private Fornecedor fornecedor;
protected Map referenceData(HttpServletRequest request) {
return fornecedor.listaFornecedores();
}
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object obj, BindException erros)
throws Exception {
FornecedorBean bean = (FornecedorBean) obj;
Map lista = fornecedor.listaFornecedoresPorTipo(new Integer(bean
.getTipoFornecedor()));
return new ModelAndView(getSuccessView(), lista).addAllObjects(erros
.getModel());
}
/**
* @param fornecedor
* seta o valor de fornecedor na variƔvel fornecedor.
*/
public void setFornecedor(Fornecedor fornecedor) {
this.fornecedor = fornecedor;
}
}
the configuration file for this controller:
<bean id="listaFornecedoresControlador" class="br.com.rodobens.web.fornecedor.ListaFornecedoresCo ntrolador">
<property name="sessionForm" value="true"/>
<property name="commandName" value="fornecedor"/>
<property name="commandClass" value="br.com.rodobens.beans.fornecedor.FornecedorBean"/>
<property name="formView" value="fornecedor/ListaFornecedores"/>
<property name="successView" value="fornecedor/ListaFornecedores"/>
<property name="fornecedor" ref="fornecedor"/>
</bean>
.
.
.
<bean id="statusFornecedoresControlador" class="br.com.rodobens.web.fornecedor.StatusFornecedoresC ontrolador">
<property name="fornecedor" ref="fornecedor"/>
</bean>
.
.
.
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/fornecedores/listaFornecedores.lpw">listaFornecedoresControlador</prop>
<prop key="/fornecedores/statusFornecedores.lpw">statusFornecedoresControlador</prop>
</props>
</property>
</bean>
My AbstractCommandController:
public class StatusFornecedoresControlador extends AbstractCommandController{
private Fornecedor fornecedor;
private static final String EXCLUIR = "excluir";
private static final String INCLUIR = "incluir";
public StatusFornecedoresControlador(){
this.setCommandClass(FornecedorBean.class);
}
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response,
Object obj, BindException erros) throws Exception {
FornecedorBean bean = (FornecedorBean)obj;
if(request.getParameter("parametro").equals(INCLUIR))
fornecedor.mudaStatusFornecedores(new Integer(DominioStatus.ATIVO), bean.getCodigoFornecedor());
else if(request.getParameter("parametro").equals(EXCLUIR))
fornecedor.mudaStatusFornecedores(new Integer(DominioStatus.INATIVO), bean.getCodigoFornecedor());
return new ModelAndView("Sucesso");
}
/**
* @param fornecedor seta o valor de fornecedor na variƔvel fornecedor.
*/
public void setFornecedor(Fornecedor fornecedor) {
this.fornecedor = fornecedor;
}
}
and, finally, my jsp with javascript function:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/views/includes.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function enviaConsulta(valor){
document.forms[0].tipoFornecedor.value=valor;
document.forms[0].submit();
}
</script>
<SCRIPT>
function submitFunction(valor) {
if (valor==1)
document.forms[0].action="listaFornecedores.lpw?parametro=excluir";
if(valor == 2)
document.forms[0].action="listaFornecedores.lpw?parametro=incluir";
document.forms[0].submit();
}
</SCRIPT>
<script language="JavaScript1.2" src="<c:url value="/scripts/mm_menu.js"/>"></script>
<%@ include file="/WEB-INF/views/menuLinkPecas.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><fmt:message key="title"/></title>
<link rel="stylesheet"type="text/css" href="<c:url value="/css/layout.css"/>" />
</head>
<body>
<%@ include file="/WEB-INF/views/cabecalho.jsp"%>
<FORM method="POST" action="listaFornecedores.lpw"/>
<table width="768" height="27" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="157" align="center"><!--DWLayoutEmptyCell--></td>
<td width="611"><table width="584" border="0" class=fonte01>
<tr>
<td width="621"><img src="<c:url value="/img/t_lst_fornecedor.gif"/>" width="248" height="30">
<table width="554" border="0" class=fonte01>
<tr>
<td width="359" height="23">Selecione um fornecedor. <strong></strong></td>
<td width="185"><div align="right">
<select class=fonte01 name="tipoFornecedor" onchange="enviaConsulta(this.value)">
<option>Selecione</option>
<option value=<%=DominioTipoFornecedor.TODOS %>>Todos os tipos</option>
<option value=<%=DominioTipoFornecedor.PRINCIPAL %>>Principal</option>
<option value=<%=DominioTipoFornecedor.SECUNDARIO %>>Secundário</option>
</select>
</div></td>
</tr>
</table>
<br>
<table width="602" border="1" bordercolor="#999999" bgcolor="#999999" class=fonte01>
<tr bordercolor="#999999" bgcolor="#999999">
<td width="14"></td>
<td width="130" bordercolor="#999999"><div align="left"><span class="style6">Nome</span></div></td>
<td width="98" bordercolor="#999999"><div align="left"><span class="style6">Cidade</span></div></td>
<td width="104" bordercolor="#999999"><div align="left"><span class="style6">Telefone</span></div></td>
<td width="152" bordercolor="#999999"><div align="left"><span class="style6">Vendedor</span></div></td>
<td width="64" bordercolor="#999999" class="style6">Status</td>
</tr>
</table>
<table width="603" border="1" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" bgcolor="#F7F7F7" class=fonte01>
<c:forEach var="fornecedor" items="${listaFornecedoresAtivos}">
<tr>
<td width="22"><div align="center">
<spring:bind path="fornecedor.codigoFornecedor">
<input type="checkbox" name="codigoFornecedor" value="<c:out value="${fornecedor.codigoFornecedor}"/>">
<!-- erro do campo -->
<FONT color="red" size="0"><c:out value="${status.errorMessage}"/></FONT>
</spring:bind>
</div></td>
<td width="132"><div align="left"><c:out value="${fornecedor.nomeFornecedor}"/></div></td>
<td width="103"><div align="left"><c:out value="${fornecedor.cidade}"/> </div></td>
<td width="107"><div align="left"><c:out value="${fornecedor.telefone}"/> </div></td>
<td width="156"><div align="left"><c:out value="${fornecedor.nomeVendedor1}"/> </div></td>
<td width="69">Ativo</td>
</tr>
</c:forEach>
</table>
<table width="58" border="0" cellspacing="0" cellpadding="0">
<!--DWLayoutTable-->
<tr valign="bottom">
<td width="20" height="25"><div align="center"><a href="" onClick="submitFunction(1)"><img src="<c:url value="/img/trash.gif"/>" width="20" height="25" border="0"></a></div></td>
<td width="38" class="fonte01">Excluir</td>
</tr>
</table>
<br>
<table width="602" border="1" bordercolor="#999999" bgcolor="#999999" class=fonte01>
<tr bordercolor="#999999" bgcolor="#999999">
<td width="14"></td>
<td width="130" bordercolor="#999999"><div align="left"><span class="style6">Nome</span></div></td>
<td width="98" bordercolor="#999999"><div align="left"><span class="style6">Cidade</span></div></td>
<td width="104" bordercolor="#999999"><div align="left"><span class="style6">Telefone</span></div></td>
<td width="152" bordercolor="#999999"><div align="left"><span class="style6">Vendedor</span></div></td>
<td width="64" bordercolor="#999999" class="style6">Status</td>
</tr>
</table>
<table width="603" border="1" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" bgcolor="#F7F7F7" class=fonte01>
<c:forEach var="fornecedor" items="${listaFornecedoresInativos}">
<tr>
<td width="22"><div align="center">
<input type="checkbox" name="codigoFornecedor" value="<c:out value="${fornecedor.codigoFornecedor}"/>">
</div></td>
<td width="132"><div align="left"><c:out value="${fornecedor.nomeFornecedor}"/></div></td>
<td width="103"><div align="left"><c:out value="${fornecedor.cidade}"/> </div></td>
<td width="107"><div align="left"><c:out value="${fornecedor.telefone}"/> </div></td>
<td width="156"><div align="left"><c:out value="${fornecedor.nomeVendedor1}"/> </div></td>
<td width="69">Inativo</td>
</tr>
</c:forEach>
</table>
<table width="61" border="0" cellspacing="0" cellpadding="0">
<!--DWLayoutTable-->
<tr valign="bottom">
<td width="24" height="25" class="fonte01"><a href="" onClick="submitFunction(2)"><img src="<c:url value="/img/certo.gif"/>" width="20" height="25" border="0"></a></td>
<td width="37" class="fonte01">Incluir</td>
</tr>
</table>
<p></p></td>
</tr>
</table>
</body>
</html>