Oh I see.  The question was about the validator.  I'm
sorry.  I understand, and of course you are right. 
The validator won't get called.  My mistake.  Thank
you for setting me straight Heath.  :)

Ray

--- Heath Borders <[EMAIL PROTECTED]> wrote:

> The converter will get called as long as the
> submitted value is non-null 
> (and sometimes even if it is null, it depends on the
> renderer 
> implementation), but the validator will never be
> called when the field is 
> null.
> 
> On Apr 9, 2005 4:39 PM, Ray Clark
> <[EMAIL PROTECTED]> wrote:
> > 
> > I am using MyFaces 1.0.8 at home. I have a page
> I've
> > been building that has a custom converter on a
> field.
> > The field doesn't have the required attribute set,
> and
> > the converter does get called when the field is
> empty.
> > 
> > Here is the snippet from my code. When I click on
> the
> > command button the following method does get fired
> and
> > the "ID is required" message does get displayed on
> the
> > page.
> > 
> > I don't know if something changed in 1.0.9, but
> this
> > works in 1.0.8.
> > 
> > <h:inputText value="#{reoccursTypeBean.id}"
> size="2"
> > maxlength="2">
> > <f:converter converterId="converter.Required"/>
> > </h:inputText>
> > 
> > public Object getAsObject(FacesContext context,
> > UIComponent component,
> > String newValue)
> > throws ConverterException {
> > 
> > if (StringUtils.isNullOrEmpty(newValue)) {
> > FacesMessage message = new FacesMessage("Id is
> > required");
> > message.setSeverity(FacesMessage.SEVERITY_ERROR);
> > throw new ConverterException(message);
> > } else if (!ApplicationUtils.isInteger(newValue))
> {
> > FacesMessage message = new FacesMessage("Id must
> > be numeric");
> > message.setSeverity(FacesMessage.SEVERITY_ERROR);
> > throw new ConverterException(message);
> > } else {
> > return newValue;
> > }
> > }
> > 
> > --- Heath Borders <[EMAIL PROTECTED]> wrote:
> > > No, if the field is empty, it will not call your
> > > validator. Your only option
> > > is the required attribute.
> > >
> > > On Apr 8, 2005 10:18 PM, Ray Clark
> > > <[EMAIL PROTECTED]> wrote:
> > > >
> > > > If you want to see if your field is empty and
> you
> > > > don't want to use the required attribute,
> could
> > > you
> > > > make your own converter? I'm thinking that you
> > > could
> > > > catch in their that the field was empty and
> throw
> > > a
> > > > message there. I don't know, but maybe that
> would
> > > > work for you.
> > > >
> > > > --- Heath Borders <[EMAIL PROTECTED]>
> wrote:
> > > > > No, the submittedValue is null, no
> validators
> > > will
> > > > > ever be fired.
> > > > >
> > > > > On Apr 8, 2005 10:13 AM, Borja Mart�n
> > > > > <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > Heath Borders wrote:
> > > > > >
> > > > > > > This is a known issue with the JSF spec.
> The
> > > > > spec says that for any
> > > > > > > UIInput if the submittedValue is null,
> > > > > validation should not be
> > > > > > > called. There's nothing that we can do
> about
> > > it
> > > > > if we want to remain
> > > > > > > standards compliant.
> > > > > > >
> > > > > > then suppose I have a value that I should
> > > handle
> > > > > throughtout the whole
> > > > > > application but cannot use sessions for
> this
> > > (for
> > > > > example a selected id
> > > > > > of a newsitem in a editor)
> > > > > > then if use the 'required' attribute I
> cannot
> > > > > retrieve it as the model
> > > > > > updating phase comes after the validating
> one.
> > > > > > But if I use my own validator I can get
> this
> > > > > variable and validate the
> > > > > > field value as I want(including if was
> empty
> > > or
> > > > > not)
> > > > > >
> > > > > > >
> > > > > > > On Apr 8, 2005 9:59 AM, *Borja Mart�n*
> > > > > <[EMAIL PROTECTED]
> > > > > > > <mailto:[EMAIL PROTECTED]>> wrote:
> > > > > > >
> > > > > > > hi,
> > > > > > > I have seen that my own validator method
> > > isnt
> > > > > called when the field
> > > > > > > value is empty(I'm making this to be
> able to
> > > get
> > > > > some sent form values
> > > > > > > during the validation). I have this:
> > > > > > >
> > > > > > > ...
> > > > > > > <h:inputText id="title"
> > > value="#{news.title}"
> > > > > > > validator="#{news.validateTitle}" />
> > > > > > > <h:message for="title" />
> > > > > > > ...
> > > > > > >
> > > > > > > and in the NewsForm class:
> > > > > > > ...
> > > > > > > public void validateTitle(FacesContext
> > > context,
> > > > > UIComponent comp,
> > > > > > > Object
> > > > > > > obj)
> > > > > > > {
> > > > > > > throw new ValidatorException(
> > > > > > > new FacesMessage("just testing the
> method is
> > > > > called"));
> > > > > > > }
> > > > > > >
> > > > > > > as you can see the method should send
> the a
> > > > > validatorexception
> > > > > > > whenever
> > > > > > > the form is sent(just for testing
> purposes).
> > > > > well, if the field is
> > > > > > > totally blank it isnt called, but when
> it
> > > > > contains at least one
> > > > > > > character it is.
> > > > > > >
> > > > > > > Maybe that has something to do with what
> we
> > > > > talked before about that
> > > > > > > previously blank fields where handled as
> > > empty
> > > > > strings and now as null
> > > > > > > values...
> > > > > > >
> > > > > > > thanks in advance
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > -Heath Borders-Wing
> > > > > > > [EMAIL PROTECTED]
> > > > > <mailto:[EMAIL PROTECTED]>
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > -Heath Borders-Wing
> > > > > [EMAIL PROTECTED]
> > > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to