• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Library of custom tags that mimic the HTML form tags

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I love a good mentalist. And so does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic