tags:

views:

42

answers:

0

While creating a Custom component that works like h:messages tag but in addition with that, if I click the messages, it focuses to each input fields from where the error occured. It works fine but the form gets empty. All the values get disappeared if any error occurs in the form. I was not able to figure out why?

I am extending Renderer and I am using:

    public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
--------
----- all the remaining codes
-------
}

The renderer is defined as :

<code>
<render-kit>
    <description>add to base HTML_BASIC renderkit</description>
    <display-name>HTML_BASIC</display-name>
    <render-kit-id>HTML_BASIC</render-kit-id>
    <renderer>
      <display-name>CustomErrorRenderer</display-name>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>custom.CustomErrorRenderer</renderer-type>
      <renderer-class>custom.CustomErrorRenderer</renderer-class>
    </renderer>
  </render-kit>
</code>

Component is defined as:

<code>
<component>
    <display-name>CustomErrorMessages</display-name>
    <component-type>custom.Errors</component-type>
    <component-class>javax.faces.component.UIOutput</component-class>
  </component>

The tag class is defined as:

package custom;

import javax.faces.webapp.UIComponentELTag;

public class CustomErrorTag extends UIComponentELTag {

  @Override
  public String getComponentType() {
    return "custom.Errors";
  }

  @Override
  public String getRendererType() {
    return "custom.CustomErrorRenderer";
  }

}

The tld file is defined as:



<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
  version="2.1">
  <tlib-version>1.0</tlib-version>
  <short-name>custom</short-name>
  <uri>http://custom&lt;/uri&gt;
  <tag>
    <name>errors</name>
    <tag-class>custom.CustomErrorTag</tag-class>
    <body-content>empty</body-content>
  </tag>
</taglib>

Everything seems working but the form gets empty if validation error occurs.

For complete code: refer question under : displaying errors with <h:messages>