aspose file tools*
The moose likes Struts and the fly likes struts-error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts-error" Watch "struts-error" New topic
Author

struts-error

ita Jonnal
Greenhorn

Joined: Feb 16, 2005
Posts: 11
I'm not able to see html error message when I enter all 9's or all 0's for ssn and when I submit it is not getting forwarded to the same jsp again.I get this page cannot be found mesage on submit.What mistake did I do.I'm getting the following errors in the log:

No message text associated with key NULL_MESSAGE_KEY_PASSED in bundle com.ibm.ejs.resources.seriousMessages

E NULL_MESSAGE_KEY_PASSED




My jsp looks like this:
<html:html>
<html:errors/>
<html:form action="pin" method='get' onsubmit="return validate(this)">

<table>
<td align="center">
<html assword property="SSN1" size="3" maxlength="3" styleClass="field_name"/>
<html assword property="SSN2" size="2" maxlength="2" styleClass="field_name"/>
<html assword property="SSN3" size="4" maxlength="4" styleClass="field_name"/>
</td>

<td align="center">
<html:submit property="submit">
</html:submit>
</td>
</table>
</html:form>
</html:html>

my Form is:


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.validator.*;
import org.apache.struts.action.ActionError;



public class PinForm extends ActionForm
{


public void reset(ActionMapping mapping, HttpServletRequest request)
{
this.ssn1 = null;
this.ssn2 = null;
this.ssn3 = null;

}

public String ssn1 = null;
public String ssn2= null;
public String ssn3= null;


public String getSSN1()
{
return ssn1;
}

public void setSSN1(String ssn1)
{
this.ssn1=ssn1;
}

public String getSSN2()
{
return ssn2;
}

public void setSSN2(String ssn2)
{
this.ssn2=ssn2;
}

public String getSSN3()
{
return ssn3;
}

public void setSSN3(String ssn3)
{
this.ssn3=ssn1+ssn2+ssn3;
}


public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = null;
errors = super.validate(mapping,request);


if(this.ssn3 == "000000000" || this.ssn3 =="999999999")
{

errors.add("SSN1", new ActionError("error.Invalid SSN.errorMsg"));

}
return errors;
}

}

Action is:



import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


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


public class PinAction extends Action
{

public ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{

final ActionErrors errors = new ActionErrors();

final PinForm pinForm = (PinForm) form;
boolean ssnValid = true;
final String ssn = pinForm.getSSN3();




return mapping.findForward("pin");


}

}


config.xml is:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"struts-config_1_1.dtd">


<struts-config>

<form-beans>
<form-bean name="PinForm" type="xxx.xxx.xxxPinForm"/>

</form-beans>

<action-mappings>
<action path="/pin" type="xxx.xxxx.xxxxx.PinAction" name="PinForm"
scope="request" input="/pin.jsp" validate="true">
<forward name="pin" path="/pin.jsp" />
</action>
</action-mappings>

<message-resources
parameter="resources.ApplicationResources"
null="false" />


<!-- Validator Configuration -->
<plug-in className="org.apache.struts
.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/
validator-rules.xml, /WEB-INF/
validation.xml"/>
</plug-in>





</struts-config>
application resources file is:

error.Invalid SSN.errorMsg=<span class='error_message'> Please enter a valid SSN. {0}</span>
error. No record found.errorMsg=<span class='error_message'> No record found for this SSN. {0}</span>
prompt.no record = No record found for this SSN. {1}



# Struts Validator Error Messages
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.

errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.

errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Hi,

According to java naming conventions all the property names should start with lower letter and the firstletter of the words following should start with capital letter.

Try changing your ssn properties to start with a lower case instead of upper case.

In your jsp, code this :


I think onsubmit in html:form is necessary only if you use Validator and it should be :



In your Form, in getter and setter methods, the first letter of the property name should start with capital letter :


In your ActionForm, you didn't need to code super.validate because there is no extends to ValidatorForm.

In your struts-config, change name of your ActionForm to pinForm instead of PinForm :




I think it's not working if you code blank in your key messages in application resources file.
Try this :



I hope it helps you.
[ July 11, 2005: Message edited by: cendy nguvy ]
Rashmini Palakurti
Greenhorn

Joined: Jun 29, 2005
Posts: 13
While creating a new ActionError object you are not passing any replacementValue but ur using arguments in your AppResources file.

i.e.,

instead of creating ActionError object as new ActionError("error.Invalid SSN.errorMsg")

instantiate it as new ActionError("error.Invalid SSN.errorMsg","SSN1")

The error message in ur AppResources file is looking for a replacementValue for its argument {0} which it is not getting and it is throwing Null Message Exception.

I hope this will solve ur problem.
ita Jonnal
Greenhorn

Joined: Feb 16, 2005
Posts: 11
thanks for all replies.I still see the sam error even after I specify
new ActionError("error.Invalid SSN.errorMsg","SSN1").Is there anything else that I'm missing.
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Did you try to remove blanks in keys in application resources file ?
ita Jonnal
Greenhorn

Joined: Feb 16, 2005
Posts: 11
I didn't understand that part ..what is removing blanks in the applications keys
ita Jonnal
Greenhorn

Joined: Feb 16, 2005
Posts: 11
I got what you said..But that didn't help either.I don't understand why when I hit submit when it should come back to the same jsp but it is going to page not found page.For some reason it is not reading the config file apart from validations.
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Originally posted by ita Jonnal:
I didn't understand that part ..what is removing blanks in the applications keys


In application resources file :

change

error.Invalid SSN.errorMsg to error.invalidSsn.errorMsg,
error. No record found.errorMsg to error.noRecordFound.errorMsg
prompt.no record to prompt.noRecord.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts-error
 
Similar Threads
blank page - Action is not called
Apache Commons Validator: Working With Arrays
problem in Struts Validation
Struts: No getter method for property name problem
Cannot retrieve mapping for action