2 Replies Latest reply on Feb 6, 2010 11:41 AM by Nick Belaevski

    ConverterException not supported by UIActionParameter

    Kerdudou Ronan Apprentice

      Hi !

       

      When we are using a "a4j:actionparam" with a converter. And if the converter throws a ConverterException (like it's suposed to be if the argument can't be converted) then the UIActionParameter and thoses who called it are not treating the ConverterException and all crashes in ViewExpiredException...

      detail :

      javax.faces.convert.ConverterException ...
          at ... Converter.getAsObject(...)
          at org.ajax4jsf.component.UIActionParameter.processAction(UIActionParameter.java:181)
          at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
          at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:766)
          at javax.faces.component.UICommand.broadcast(UICommand.java:372)
          at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
      ...
      [lifecycle] - jsf.lifecycle.phase.exception
      ...
      [BaseXMLFilter] - Exception in the filter chain
      ...
      Caused by: javax.faces.application.ViewExpiredException
      

       

      I think we should handle this type of exception in UIActionParameter.java because an ActionEvent or UIComponentBase doesn't have converters, it's the UIActionParameter that adds this capability and have to handle its specifications.

       

      in UIActionParameter.processAction we should do :

      if (null != converter) {
           try {
                requestValue = converter.getAsObject(context, this, (String) requestValue);
           } catch (ConverterException converterException) {
                // we inform the user of this incident like if it was a UIInput
                context.addMessage(this.getClientId(context),converterException.getFacesMessage());
                // caller of this method treat AbortProcessingException but not ConverterException
                throw new AbortProcessingException(converterException);
           }
      }
      

       

      in UIActionParameter.getValue() we can probably change something like that but I don't know :

      if (null != converter) {
           try {
                value = converter.getAsString(context, this, value);
           } catch (ConverterException converterException) {
                //shall we inform the user of this ?
                //context.addMessage(this.getClientId(context),converterException.getFacesMessage());
                //useless encapsulation : throw new FacesException(converterException);
                throw converterException;
           }
      }

       

      I'm not sure if we always have  to add a FacesMessage (in my case we have to, and i don't like putting it inside the converter).

      see UIInput.addConversionErrorMessage() to make something better than my converterException.getFacesMessage()

       

      NOTE : there is another post for a bug in this same class 'UIActionParameter' that doesn't get the converter, you must correct this bug first to be able to enter in the 'if' ;-)

       

      regards.