Values from a jsp page are null in an Action class

hi, i am working on an application...i have a jsp page with several inputs (type=text) and when a submit the form to to my action class all values received are null.

Here is a part of code:

the jsp file: letter.jsp

<form target="_self" action="/Test/editLetter.do" name="letterTF">

<table>

<tbody>

<tr>

<th>

No of objects

</th>

<th>

Weight

</th>

<th>

Description

</th>

</tr>

<tr>

<td>

Package

<input name="package" id="package" type="checkbox">

</td>

<td>

<input name="package_No" type="text" value="<%=currentBean.getPackageNo() %>"> <%-- from session...have to edit some date from a data base--%>

</td>

<td>

<input name="package_weight" type="text" value="<%=currentBean.geWeight()%>">

</td>

<td>

<input name="description" type="text" value="<%=currentBean.Description()%>"

></td>

</tr>

<tr>

..................................................... <%-- It's a big form --%>

</tr>

<tr>

<input type="submit" name="send" value="Send">

</tr>

</tbody>

</table>

</form>

struts-config.xml:

<form-bean

name="letterTF"

type="Test.LetterForm">

</form-bean>

<action path="/editLetter"

type="Test.LetterAction"

name="scrisoareTF"

input="/letter.jsp"

scope="request"

validate="false">

<forward name="success" path="/index_orders.jsp"/>

</action>

The ActionForm class:

public class LetterForm extends ActionForm{

private String package;

private String package_No;

private String package_weight;

public void setPackage(String package){

this.package = package

}

public String getPackage(){

return package;

}

.......................................

}

The action class:

public class LetterAction extends Action{

public ActionForward execute(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception{

String package;

String package_No;

String package_weight;

LetterForm letterTF = (LetterForm) form;

package = letterTF.getPackage();

package_No = letterTF.getPackageNo()

package_weight = letterTF.getPackageWeight();

System.out.println("Package: "+package);//it will print Package: null

System.out.println("Weight: "+weight);//it will print Weight: null

System.out.println("Description "+description) //it will print Description: null

}

}

As I observed its not making the set methods from LetterForm.java

I am dealing with this bug for a couple of days an i didn't managed to break it. If anyone has an idea or a solution would he be so kind to share it with me

Thanks in advance,

David

[3231 byte] By [Ichybana] at [2007-11-27 5:14:00]
# 1
In your ActionForm class, follow the naming convention. That might me the issue. eg. private String packageWeight = null;
skp71a at 2007-7-12 10:35:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
could you be more specific please ... many thanks
Ichybana at 2007-7-12 10:35:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Why did you use form name as name="scrisoareTF" in your action mappings. It should be "letterTF".
skp71a at 2007-7-12 10:35:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Basically your form beans are the place holders or containers for your jsp attributes. It has to be mapped in such a way that when the form is submitted the user entered values get populated on to your form bean.

For Eg:

JSP

<html:form action="accountSearchResults.do">

...... ....... ....... ...... ....... ....... ...... ....... .......

...... ....... ....... ...... ....... ....... ...... ....... .......

<html:text property="myName" size="15"/>

//USE ONLY STRUTS TAGS IN JSP's. U CAN REFER TO

//http://struts.apache.org/1.x/struts-taglib/tlddoc/index.html

//THE PROPERTY NAME "myName" SHOULD BE DEFINED IN

//YOUR FORMBEAN WITH getMyName AND setMyName

//METHODS DEFINED

...... ....... ....... ...... ....... ....... ...... ....... .......

...... ....... ....... ...... ....... ....... ...... ....... .......

</html:form>

struts-config.xml

...... ....... ....... ...... ....... ....... ...... ....... .......

...... ....... ....... ...... ....... ....... ...... ....... .......

<form-beans>

<form-bean name="addEditAccount" type="org.apache.struts.validator.LazyValidatorForm">

<form-property name="myName" type="java.lang.String">

</form-property>

</form-bean>

</form-beans>

...... ....... ....... ...... ....... ....... ...... ....... .......

...... ....... ....... ...... ....... ....... ...... ....... .......

<action-mappings>

<action path="/accountSearchResults" type="com.zzz.AccountSearchResultAction" name="addEditAccount" scope="request">

<forward name="success" path="NextPage.jsp">

</forward>

</action>

</action-mappings>

...... ....... ....... ...... ....... ....... ...... ....... .......

...... ....... ....... ...... ....... ....... ...... ....... .......

Action Class

Since we have defined the form bean as a lazyvalidator instance you can use:

PropertyUtils.copyProperties(targetBean, form);

to fetch the values entered by the user. Try to use struts tags in your jsp's and map the properties to your form bean variables. Hope that helps.

SirG

SirGenerala at 2007-7-12 10:35:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
change it and still not working
Ichybana at 2007-7-12 10:35:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
org.apache.jasper.JasperException: /letter.jsp(21,0) Attribute id invalid for tag form according to TLD
Ichybana at 2007-7-12 10:35:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
many 10X sirG...i have put jsp tags and it works fineNext time you come to Romania the bear is on me :P
Ichybana at 2007-7-12 10:35:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
I have the same problem, inside my action form all properties come out null. But I realized it worked correctly in mozilla firefox.The problem comes when I use IE6.can anyone help us please?Message was edited by: tomas.novellino
tomas.novellinoa at 2007-7-12 10:35:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...