• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

NullPointer Exception

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,

I am getting a NullPointerException when I am using a custom validator in my code. To be specific here is the detail:

Validation.xml snippet:
<formset>
<form name="adminLoginForm">
<field property="userName" depends="required, checkAuthorization">
<arg key="prompt.username"/>
<var>
<var-name>username</var-name>
<var-value>sharpie</var-value>
</var>
</field>
<field property="password" depends="required, checkAuthorization">
<arg key="prompt.password"/>
<var>
<var-name>password</var-name>
<var-value>sharpie</var-value>
</var>
</field>
</form>
</formset>


Validator-rules.xml snippet:
<validator name="checkAuthorization"
classname="com.sharpie.common.utils.CustomValidator"
method="validateAuthorization"
methodParams="java.lang.Object,org.apache.commons.validator.Validator,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.required">
</validator>


Java code for CustomValidator:
public class CustomValidator implements Serializable {

private static final long serialVersionUID = 2765932841116180600L;

public boolean validateAuthorization(Object object, Validator validator, ValidatorAction validatorAction, Field field, ActionErrors errors, HttpServletRequest httpServletRequest) {

String userName = field.getVarValue("username");
if (userName!=null) {
String userNameValue = ValidatorUtils.getValueAsString(object, field.getProperty());
if(!userName.equals(userNameValue)) {
errors.add(field.getKey(),Resources.getActionMessage(validator,httpServletRequest,validatorAction,field));
return false;
}
}

String password = field.getVarValue("password");
if (password!=null) {
String passwordValue = ValidatorUtils.getValueAsString(object, field.getProperty());
if(!password.equals(passwordValue)) {
errors.add(field.getKey(),Resources.getActionMessage(validator,httpServletRequest,validatorAction,field));
return false;
}
}
return true;
}
}


Please assume that the syntax are all perfect if you find any illegal ones. Any help on this matter would be greatly appreciated. Waiting for your reply.


Thanks
Raj
 
Rajkumar Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am so sorry, I am getting the NullPointerException on
errors.add(field.getKey(),Resources.getActionMessage(validator,httpServletRequest,validatorAction,field));

It seems that the ActionErrors is not being initiated by the Struts due to some reason that I am not able to figure it out.
 
I brought this back from the farm where they grow the tiny ads:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic