2 Replies Latest reply on Jan 7, 2008 1:34 PM by Jason Long

    Does facesMessages.clear() work for conversion errors?

    Jason Long Master

      Using Seam 2.0 on 4.2.2

      I have a converter that I use for a datatable with dropdown filters and a button to update multiple values at once.

      Each row has a single input box that should only accept positive doubles. When a dropdown changes I use a4j:support to rerender the entire datatable.

      The update button also rerenders the datatable.

      If I

      throw new ConverterException(new FacesMessage("You must enter a positive number."));


      The table is reloaded and the FacesMessages are correctly attached to the correct input components, but all values are reverted to their initial value and any changes are lost even if that field passes conversion.

      If I
      throw new ConverterException("You must enter a positive number.");


      and then I change the filter and reload the datatable, both the value and the error message are carried with that row. The rest of the columns contain the correct data. I have to select a filter that has no results or less rows than where the conversion error occurs to clear it. Also the error message is not reflected and the error reads "value could not be converted to the expected type."

      facesMessages.clear();


      seemed to work when I was adding them in a validator
      private void addMessage(UIComponent component, Object value)
       {
       HtmlInputText htmlInputText = (HtmlInputText) component;
       htmlInputText.setValid(false);
       facesMessages.addToControl(htmlInputText.getId(), new FacesMessage("Must be >= 0."));
       }

      , but not when the converter adds them.

      1. How can I clear the conversion errors when I change the filter?
      2. Or, how can I throw the error with the FacesMessage and have the values perserverd?


      Complete converter code
      @Name("positiveDoubleConverter")
      @BypassInterceptors
      @Converter
      public class PositiveDoubleConverter implements javax.faces.convert.Converter
      {
       public PositiveDoubleConverter() { }
      
       public String getAsString(FacesContext context, UIComponent component, Object value)
       {
       return (value==null) ? null : value.toString();
       }
      
       public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException
       {
       if(value==null || value.length()<1) return null;
       try {
       Double d = Double.parseDouble(value);
       if(d<0)
       {
       throwConverterException();
       }
       return d;
       } catch (NumberFormatException e) {
       return throwConverterException();
       }
       }
      
       private Object throwConverterException() throws ConverterException
       {
       //throw new ConverterException(new FacesMessage("You must enter a positive number."));
       throw new ConverterException("You must enter a positive number.");
       }
      
      }