Mais uma dificuldade básica com struts [resolvido]

8 respostas
M

Olá pessoal,

Em um programinha de teste que estou fazendo, estou tendo um problema. O ActionForm parece não estar pegando os dados do jsp, retornando nulo. Acredito que fiz todas as “ligações” necessárias… mas ainda assim, retorna sempre nulo: não vê o que digito no text.

Coloco abaixo alguns trechos de arquivos importante pra solucionar o problema:

struts-config.xml, ao declarar o form-bean:

<form-bean name="addItemForm" type="com.edhand.example1.AddItemForm"/>
      <form-bean name="delItemForm" type="com.edhand.example1.DelItemForm"/>

struts-config.xml, no action-mappings:

<action path="/addItem" type="com.edhand.example1.AddItemAction" 
		name="addItemForm" scope="request" validate="true" 
		input="/pages/AddItem.jsp">
		<forward name="success" path="/pages/Welcome.jsp"/>
		<forward name="failure" path="/pages/erro.jsp" /> 
	</action>
        
	<action path="/delItem" type="com.edhand.example1.DelItemAction" 
		name="delItemForm" scope="request" validate="true" 
		input="/pages/DelItem.jsp">
		<forward name="success" path="/pages/Welcome.jsp"/>
		<forward name="failure" path="/pages/erro.jsp" /> 
	</action>

DelItemForm.java:

package com.edhand.example1;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class DelItemForm extends ActionForm {
    
	private Long id;

	public ActionErrors validate(
		ActionMapping mapping,
		HttpServletRequest request)
	{
		ActionErrors errors = new ActionErrors();

		if (id == null)
		{
			errors.add("id", new ActionError("errors.required", "Código"));
		}
		return errors;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request)
	{
		this.clear();
	}

      	public Long getId()
	{
		return id;
	}

	public void clear()
	{
                this.id = null;
	}        
}

DelItem.jsp

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ page import="com.edhand.example1.ItemService" %>
<%@ page import="java.util.List" %>

<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Deleta Matéria Prima</title>
    </head>
    <body>

    <h1>Deleta Matéria Prima</h1>
   <html:errors/>

   <html:form action="delItem.do" method="post">
      <table border=1>
         <tr><td>Código: </td><td><html:text property="id"/></td></tr>      
      </table><br/>
      <html:submit/>
   </html:form>
<p><a href="Welcome.jsp">Voltar</a>
</body>

</html>

Percebam que acima tenho os beans addItemForm e delItemForm. O primeiro funciona perfeitamente, o segundo nao. Por isso coloquei os codigos soh dele.

Agradeço qq ajuda

8 Respostas

Kleber_Santos

e o public Long setId(Long id)?

existe issu ai?

:shock:

M

existe agora :mrgreen: :oops:

obrigada

Kleber_Santos

de nada querida…

estamos aqui pra aprender e ajudar tbm

:mrgreen: :mrgreen: :mrgreen: :mrgreen: :stuck_out_tongue:

danieldestro

Kleber Santos:
de nada querida…
estamos aqui pra aprender e ajudar tbm
:mrgreen: :mrgreen: :mrgreen: :mrgreen: :stuck_out_tongue:

[detected] chaveco furado [/detected]

Kleber_Santos

gostei danieldestro,

vou quebrar suas pernas sou casado heheheh

t+

:mrgreen: :mrgreen: :mrgreen: :stuck_out_tongue:

Mauricio_Linhares

Kleber Santos:
gostei danieldestro,

vou quebrar suas pernas sou casado heheheh

t+

:mrgreen: :mrgreen: :mrgreen: :stuck_out_tongue:

Mas que coisa feia heim :lol:

Kleber_Santos

foi mal pessoal, é bricandeira heim

:oops: :oops: :oops:

M

:shock:
aeiuhaeiuhaeuihae

Criado 22 de junho de 2005
Ultima resposta 22 de jun. de 2005
Respostas 8
Participantes 4