Title: RE: valueChangeListener - inputText - Which method is correct?


The spec says ...

MethodBinding representing a value change listener method that will be notified when a new value has been set for this input component.

I was left with the impression from this that when the field's value changes then the method would get called. Not when the form is submitted.

I don’t need to process the form. I'm in the situation where a person types in a "part number", and the several other fields are auto populated from that value (i.e. the part description & manufacture). The form is not submitted thought till they have entered a load of other details.

I guess I can look at getting some _javascript_ to do this. But it’s a shame there isn’t a method for this in MyFaces.

I see that I can write something like this

<h:selectBooleanCheckbox

        valueChangeListener="#{resumeBean.changeColorMode}"

      >

      immediate="true"/>

But this results in the form being submitted & error messages being displayed because of fields not filled. This would confuse the user, since

They've not pressed the submit button yet.

Jeff.




-----Original Message-----
From: Bruno Aranda [mailto:[EMAIL PROTECTED]]
Sent: 25 October 2005 11:57
To: MyFaces Discussion
Subject: Re: valueChangeListener - inputText - Which method is correct?

Yes, but the ValueChangeEvent will be processed in the Process

Validations phase, after submitting the form. So if you want to change

the value of the other inputText when the first changes, you need to

submit the form (technique #1). Otherwise, you can use _javascript_ if

it is an option to you (if you don't have to process the form).

Hope it is clear now,

Bruno

2005/10/25, Jeffrey Porter <[EMAIL PROTECTED]>:

>

> Thanks Bruno. Great links.

>

>

> The spec for h:inputText states that it has the MethodBinding attribute

> valueChangeListener.

>

> So if I set this as...

>

> <h:inputText id="name" value="#{ncm.name}" required="true"

> valueChangeListener="#{ncm.changeEvent}" />

>

> Should it not call my method in the ncm class?

>

> public void changeEvent(ValueChangeEvent event) {

>         String partNo = ((String)event.getNewValue());

> }

>

> Or am I missing something?

>

> Jeff.

>

>

>

> -----Original Message-----

> From: Bruno Aranda [mailto:[EMAIL PROTECTED]]

> Sent: 25 October 2005 11:34

> To: MyFaces Discussion

> Subject: Re: valueChangeListener - inputText - Which method is correct?

>

> If it applies, you can use the technique explained in

> http://wiki.apache.org/myfaces/SubmitPageOnValueChange using the

> inputText instead of the selectOneMenu. It should work.

> Or if you want to play with _javascript_ you can take a look at

> http://www.irian.at/myfaces/jslistener.jsf to see how the jslistener

> works,

>

> Regards,

>

> Bruno

>

> 2005/10/25, Jeffrey Porter <[EMAIL PROTECTED]>:

> >

> >

> >

> > I've seen 3 different examples of using the "valueChangeListener"

> attribute.

> >

> >

> >

> > I've seen...

> >

> >

> >

> > Example 1:

> >

> >

> >

> > JSP <h:inputText value="foo">

> >  <f:valueChangeListener type="com.jsf.MyValueChangeListener"/>

> > </h:inputText>

> >

> >

> >

> >

> > CODE public class MyValueChangeListener implements ValueChangeListener

> {

> >   public MyValueChangeListener() {  }

> >

> >   public void processValueChange(ValueChangeEvent vce)

> > throws AbortProcessingException  {

> >      System.out.println("A value has changed!");

> >   }

> > }

> >

> >

> >

> >

> > Example 2:

> >

> >

> >

> > JSP

> >

> > <h:inputText id="partNumber"

> > value="#{nonConformingMaterial.partNumber}" required="true"

> >

> > valueChangeListener="#{nonConformingMaterial.changeEvent}"

> >

> >       >

> >

> >       immediate="true"

> >

> > />

> >

> >

> >

> > Example 3:

> >

> >

> >

> > JSP <s:inputSuggestAjax

> suggestedItemsMethod="#{inputSuggestAjax.getItems}"

> > styleLocation="" />

> >

> >

> >

> >

> >

> >

> >

> >

> > I like example 3, very sexy. (see

> > http://irian.at/myfaces-sandbox/inputSuggestAjax.jsf)

> >

> > But it's not what I need in my application.

> >

> >

> >

> > What I need is, when an inputText is filled in, an action is called so

> that

> > another inputText field is automatically filled in.

> >

> >

> >

> > I presume that I should be trying to get example 1 working. Would you

> agree?

> >

> >

>

Reply via email to