Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String value substitution

 
nachagoni rishi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way i can replace "ticketNumber==null" and "plateNumber==null" with value of errorField, so that my code is shorter.


public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

HttpSession session = request.getSession();
String errorField = (String) session.getAttribute("errorField");
if (errorField.equalsIgnoreCase("ticketNumber")) {

if ((ticketNumber == null) || (ticketNumber.trim().length() == 0))
errors.add(errorField,new ActionError("error." + errorField + ".null"));
}
if (errorField.equalsIgnoreCase("plateNumber")) {
if ((plateNumber == null) || (plateNumber.trim().length() == 0))
errors.add(errorField,new ActionError("error." + errorField + ".null"));
}

return errors;
}
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import the GenericValidator class and use the isBlankOrNull method.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic