You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dave <ja...@yahoo.com> on 2005/11/01 08:24:56 UTC

deal with Model update exception

How to catch exception during model update phase and display a nicer message?
 
There was an exception during model update, but I did not catch it, the error message on the screen is:

 Conversion Error "_id30": Error during model data update.
 
If I catch exception, the life cycle will continue to Invoke Application, that is not desired.
 
Thanks, dave 

		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  

Re: deal with Model update exception

Posted by Mike Kienenberger <mk...@gmail.com>.
Dave,

I think you are correct in that this behavior can be improved
(although the current implementation is not a bug but merely an
implementation choice).

The spec refers the implementor to UIInput.updateModel().

http://java.sun.com/j2ee/javaserverfaces/1.1/docs/api/javax/faces/component/UIInput.html#updateModel(javax.faces.context.FacesContext)

The relevent part of that is here:

        * If the setValue() method call fails:
              o Enqueue an error message by calling addMessage() on
the specified FacesContext instance.

I took a quick look at an old nightly for JSF RI 1.2 (the only JSF RI
source I have downloaded), and I see that for certain classes of
Exceptions (ELException), they use the exception message rather than
javax.faces.component.UIInput.UPDATE.

To be safe, you should probably take a look at the JSF RI 1.1 source
for UIInput and see what they do, but it seems to me that there's
nothing in the spec or JSF 1.1 RI javadocs stopping MyFaces from using
the ConverterException.getFacesMessage() if one was provided.

Open a jira improvement issue and supply a patch.

Of course, I've misread the RI javadocs before, so I could be wrong again :)

-Mike

On 11/6/05, Dave <ja...@yahoo.com> wrote:
> I am looking at UIInput.java.
>
>    public void updateModel(FacesContext context)
>     {
>         if (!isValid()) return;
>         if (!isLocalValueSet()) return;
>         ValueBinding vb = getValueBinding("value");
>         if (vb == null) return;
>         try
>         {
>             vb.setValue(context, getLocalValue());
>             setValue(null);
>             setLocalValueSet(false);
>         }
>         catch (RuntimeException e)
>         {
>      &nbs p;   //Object[] args = {getId()};
>             context.getExternalContext().log(e.getMessage(), e);
>             _MessageUtils.addErrorMessage(context,
> this,CONVERSION_MESSAGE_ID,new Object[]{getId()});
>             setValid(false);
>         }
>     }
>
>
> The method just log the exception, and what shows up on page is predefined
> conversion error message. I like the error message from the exception to
> show up on page telling user what is wrong. The predefined message says
> nothing more than an Model update error.
> This is a bug.  Thanks. Dave
>
> Mike Kienenberger <mk...@gmail.com> wrote:
> It's not a bug, but it certainly makes it more difficult to write
> meaningful error messages.
>
> I'm taking a look at the UIInput code, and it looks like you can
> provide a FacesMessage on your ConverterException constructor call.
> If you do that, the FacesMessage you provide will be used instead of
> building one using
> javax.faces.component.UIInput.CONVERSION.
>
> I guess that's not so bad, and it'll probably do what you want.
>
>
> On 11/2/05, Dave wrote:
> > I throw my own exception, I hope JSF to catch the exception and display
> the
> > message from the exception. but JSF just display its own message. This
> might
> > be a bug.
> >
> > Mike Kienenberger wrote:
> > The message comes from the messages.properties file:
> >
> > javax.faces.component.UIInput.CONVERSION = Conversion
> Error
> > javax.faces.component.UIInput.CONVERSION_detail = "{0}":
> > Error during
> > model data update.
> >
> > I'm guessing you'd need to provide your own message bundle that
> > provides an alternate value.
> >
> > On 11/1/05, Dave wrote:
> > > How to catch exception during model update phase and display a nicer
> > > message?
> > >
> > > There was an exception during model update, but I did not catch it, the
> > > error message on the screen is:
> > >
> > > Conversion Error "_id30": Error during model data update.
> > >
> > > If I catch exception, the life cycle will continue to Invoke
> Application,
> > > that is not desired.
> > >
> > > Thanks, dave
> > >
> > > ________________________________
> > > Yahoo! FareChase - Search multiple travel sites in one click.
> > >
> > >
> >
> >
> > ________________________________
> &gt ; Yahoo! FareChase - Search multiple travel sites in one click.
> >
> >
>
>
>  ________________________________
>  Yahoo! FareChase - Search multiple travel sites in one click.
>
>

Re: deal with Model update exception

Posted by Dave <ja...@yahoo.com>.
I am looking at UIInput.java.
 
   public void updateModel(FacesContext context)
    {
        if (!isValid()) return;
        if (!isLocalValueSet()) return;
        ValueBinding vb = getValueBinding("value");
        if (vb == null) return;
        try
        {
            vb.setValue(context, getLocalValue());
            setValue(null);
            setLocalValueSet(false);
        }
        catch (RuntimeException e)
        {
         //Object[] args = {getId()};
            context.getExternalContext().log(e.getMessage(), e);
            _MessageUtils.addErrorMessage(context, this,CONVERSION_MESSAGE_ID,new Object[]{getId()});
            setValid(false);
        }
    }
 
 
The method just log the exception, and what shows up on page is predefined conversion error message. I like the error message from the exception to show up on page telling user what is wrong. The predefined message says nothing more than an Model update error.
This is a bug.  Thanks. Dave

Mike Kienenberger <mk...@gmail.com> wrote:
It's not a bug, but it certainly makes it more difficult to write
meaningful error messages.

I'm taking a look at the UIInput code, and it looks like you can
provide a FacesMessage on your ConverterException constructor call. 
If you do that, the FacesMessage you provide will be used instead of
building one using javax.faces.component.UIInput.CONVERSION.

I guess that's not so bad, and it'll probably do what you want.


On 11/2/05, Dave wrote:
> I throw my own exception, I hope JSF to catch the exception and display the
> message from the exception. but JSF just display its own message. This might
> be a bug.
>
> Mike Kienenberger wrote:
> The message comes from the messages.properties file:
>
> javax.faces.component.UIInput.CONVERSION = Conversion Error
> javax.faces.component.UIInput.CONVERSION_detail = "{0}":
> Error during
> model data update.
>
> I'm guessing you'd need to provide your own message bundle that
> provides an alternate value.
>
> On 11/1/05, Dave wrote:
> > How to catch exception during model update phase and display a nicer
> > message?
> >
> > There was an exception during model update, but I did not catch it, the
> > error message on the screen is:
> >
> > Conversion Error "_id30": Error during model data update.
> >
> > If I catch exception, the life cycle will continue to Invoke Application,
> > that is not desired.
> >
> > Thanks, dave
> >
> > ________________________________
> > Yahoo! FareChase - Search multiple travel sites in one click.
> >
> >
>
>
> ________________________________
> Yahoo! FareChase - Search multiple travel sites in one click.
>
>

		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  

Re: deal with Model update exception

Posted by Mike Kienenberger <mk...@gmail.com>.
It's not a bug, but it certainly makes it more difficult to write
meaningful error messages.

I'm taking a look at the UIInput code, and it looks like you can
provide a FacesMessage on your ConverterException constructor call.  
If you do that, the FacesMessage you provide will be used instead of
building one using javax.faces.component.UIInput.CONVERSION.

I guess that's not so bad, and it'll probably do what you want.


On 11/2/05, Dave <ja...@yahoo.com> wrote:
> I throw my own exception, I hope JSF to catch the exception and display the
> message from the exception. but JSF just display its own message. This might
> be a bug.
>
> Mike Kienenberger <mk...@gmail.com> wrote:
> The message comes from the messages.properties file:
>
> javax.faces.component.UIInput.CONVERSION = Conversion Error
> javax.faces.component.UIInput.CONVERSION_detail = "{0}":
> Error during
> model data update.
>
> I'm guessing you'd need to provide your own message bundle that
> provides an alternate value.
>
> On 11/1/05, Dave wrote:
> > How to catch exception during model update phase and display a nicer
> > message?
> >
> > There was an exception during model update, but I did not catch it, the
> > error message on the screen is:
> >
> > Conversion Error "_id30": Error during model data update.
> >
> > If I catch exception, the life cycle will continue to Invoke Application,
> > that is not desired.
> >
> > Thanks, dave
> >
> > ________________________________
> > Yahoo! FareChase - Search multiple travel sites in one click.
> >
> >
>
>
>  ________________________________
>  Yahoo! FareChase - Search multiple travel sites in one click.
>
>

Re: deal with Model update exception

Posted by Dave <ja...@yahoo.com>.
I throw my own exception, I hope JSF to catch the exception and display the message from the exception. but JSF just display its own message. This might be a bug.

Mike Kienenberger <mk...@gmail.com> wrote:The message comes from the messages.properties file:

javax.faces.component.UIInput.CONVERSION = Conversion Error
javax.faces.component.UIInput.CONVERSION_detail = "{0}": Error during
model data update.

I'm guessing you'd need to provide your own message bundle that
provides an alternate value.

On 11/1/05, Dave wrote:
> How to catch exception during model update phase and display a nicer
> message?
>
> There was an exception during model update, but I did not catch it, the
> error message on the screen is:
>
> Conversion Error "_id30": Error during model data update.
>
> If I catch exception, the life cycle will continue to Invoke Application,
> that is not desired.
>
> Thanks, dave
>
> ________________________________
> Yahoo! FareChase - Search multiple travel sites in one click.
>
>


		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  

Re: deal with Model update exception

Posted by Mike Kienenberger <mk...@gmail.com>.
The message comes from the messages.properties file:

javax.faces.component.UIInput.CONVERSION        = Conversion Error
javax.faces.component.UIInput.CONVERSION_detail = "{0}": Error during
model data update.

I'm guessing you'd need to provide your own message bundle that
provides an alternate value.

On 11/1/05, Dave <ja...@yahoo.com> wrote:
> How to catch exception during model update phase and display a nicer
> message?
>
> There was an exception during model update, but I did not catch it, the
> error message on the screen is:
>
>  Conversion Error "_id30": Error during model data update.
>
> If I catch exception, the life cycle will continue to Invoke Application,
> that is not desired.
>
> Thanks, dave
>
>  ________________________________
>  Yahoo! FareChase - Search multiple travel sites in one click.
>
>