Instead of

return new ConverterException("Invalid Ad Id");

you need to use

throw new ConverterException("Invalid Ad Id");

On 9/23/05, Jason Nesbitt <[EMAIL PROTECTED]> wrote:
> I have an input text field that is bound to a long value in the backing
> bean.  I'm using a custom converter because I want the initial value of the
> input text field to be the empty string and because I want to provide an
> error message that is more specific.  However, when I enter a value in the
> text field that is not a valid long I get the following error.
>  ERROR org.apache.myfaces.el.ValueBindingImpl  - Cannot set
> value for expression '#{login.adId}' to a new value of type
> javax.faces.convert.ConverterException
>  javax.servlet.jsp.el.ELException: Attempt to coerce a
> value of type "javax.faces.convert.ConverterException" to
> type "java.lang.Long"
>
>  What am I doing wrong here? My input text declaration is
>
>  <h:inputText size="12" maxlength="25" value="#{login.adId}"
> converter="#{login.adIdConverter}" />
>
>  and my converter property is
>
>  public Converter getAdIdConverter() {
>          return new Converter() {
>                  public Object getAsObject(
>                      FacesContext facesContext,
>                      UIComponent uiComponent,
>                      String s) throws ConverterException {
>                      try {
>                          return new Long(s);
>                      } catch (NumberFormatException e) {
>                          return new ConverterException("Invalid Ad Id");
>                      }
>                  }
>
>                  public String getAsString(
>                      FacesContext facesContext,
>                      UIComponent uiComponent,
>                      Object o) throws ConverterException {
>                      Long adId = (Long) o;
>
>                      if (adId == null || adId.longValue() == 0) {
>                          return "";
>                      } else {
>                          return String.valueOf(adId);
>                      }
>                  }
>              };
>      }
>
>
>
>  Thanks
>
>  Jason
>

Reply via email to