Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String value substitution  RSS feed

 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!