Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Library of custom tags that mimic the HTML form tags

 
Salim Khatib
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating a library of custom tags that mimic the HTML form tags. When the user submits a form that fails validation, the JSP form is forwarded back to the user. The <t:textField> tag must support the ability to re-populate the form field with the request parameters from the user’s last request. For example, if the user entered “Samantha” in the text field called firstName, then the form is re-populated like this

<input type = “text” name = ‘firstName’ value = ‘Samantha’>

Which tag handler method will accomplish this goal?

Ans. public int doStartTag() throws JspException {
Servletrequest request = pageContext.getRequest();
String value = request.getParameter(this.name);
If (value == null) value = “”;
JspWriter out = pageContext.getOut();
try {
out.write (String.format (INPUT, this.name, value));
} (Exception e) {throw new JspException (e) ;}
return SKIP_BODY;
}
private static String INPUT = “<input type = ‘text’ name = ‘%s’ value = ‘%s’>”;


Can anybody explain me how this code works?
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!