You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Julien Martin <ba...@gmail.com> on 2007/02/21 16:54:20 UTC

MyFaces and valueChangeListener??

Hello,

I have several components in my jsf page each having a valuechangelistener
attribute and each attribute having a corresponding  methods in my backing
bean.

public void attributeAChanged(ValueChangeEvent evt){
public void attributeBChanged(ValueChangeEvent evt){

in the jsp:

valueChangeListener="#{PopulateListsBean.attributeAChanged}"
valueChangeListener="#{PopulateListsBean.attributeBChanged}"

Does anyone know why the first declared method is always called even if
attributeB is changed??

I was not able to find anywhere in the spec anything related to that.

Can anyone help?

Thanks in advance,

Julien.

Re: MyFaces and valueChangeListener??

Posted by Simon Kitching <si...@rhe.co.nz>.
While most people fail to trim irrelevant info from emails, 
unfortunately Julien has trimmed a little too vigorously :).

The original posting on this subject showed that he was using two 
separate h:selectOneMenu tags each with one valueChangeListener 
attribute, which looks ok to me.

http://www.nabble.com/Several-value-change-listener-methods-in-a-backing-bean--tf3266143.html



Mike Kienenberger wrote:
> You can have multiple valueChangeListener components as children of a
> UIInput.   You can have one-and-only one valueChangeListener attribute
> on a UIInput.
> 
> It looks like Julien is trying to use multiple attributes, not
> multiple components.


Re: MyFaces and valueChangeListener??

Posted by Mike Kienenberger <mk...@gmail.com>.
You can have multiple valueChangeListener components as children of a
UIInput.   You can have one-and-only one valueChangeListener attribute
on a UIInput.

It looks like Julien is trying to use multiple attributes, not
multiple components.

On 2/21/07, Simon Kitching <si...@rhe.co.nz> wrote:
> Julien Martin wrote:
> > Hello,
> >
> > I have several components in my jsf page each having a valuechangelistener
> > attribute and each attribute having a corresponding  methods in my backing
> > bean.
> >
> > public void attributeAChanged(ValueChangeEvent evt){
> >
> > public void attributeBChanged(ValueChangeEvent evt){
> >
> > in the jsp:
> >
> > valueChangeListener="#{PopulateListsBean.attributeAChanged}"
> > valueChangeListener="#{PopulateListsBean.attributeBChanged}"
> >
> >
> > Does anyone know why the first declared method is always called even if
> > attributeB is changed??
> >
> > I was not able to find anywhere in the spec anything related to that.
> >
> > Can anyone help?
>
> This sure looks like a bug to me; I can't see anything wrong with your
> code. Multiple valueChangeListener methods should be supported AFAIK. I
> presume you are checking which methods are called by logging output in
> each one, or using breakpoints?
>
> By the way, in a later email you give this code:
>  > ***********************
>  >  public void contractCodeChanged(ValueChangeEvent evt){
>  >         log.info("contractCodeChanged");
>  >         this.contractCode = (String) evt.getNewValue();
>  >     }
>
> Updating the model from a value-changed-event is probably not a good
> idea. These callbacks get executed at the end of the validation phase,
> and are run even if validation failures have occurred on other
> components. Therefore if a validation failure has occurred then the
> value-change-listener method is called but the model is never updated
> from other components.
>
> Note also that you have:
> <h:selectOneMenu
>    value="#{PopulateListsBean.contractCode}"
>    ...
> so during the update phase the contractCode field will be updated by the
> component, ie your contractCodeChanged method's change to that property
> will be very brief. Of course in this case you're just assigning the
> final value a bit early (for some reason) so in this case a value X is
> being overwritten with value X.
>
> And finally, if there *is* a validation failure then the selectOneMenu
> component will re-render itself using the value cached in the model
> rather than fetching from the model.
>
> Regards,
>
> Simon
>
>

Re: MyFaces and valueChangeListener??

Posted by Simon Kitching <si...@rhe.co.nz>.
Julien Martin wrote:
> Hello,
> 
> I have several components in my jsf page each having a valuechangelistener
> attribute and each attribute having a corresponding  methods in my backing
> bean.
> 
> public void attributeAChanged(ValueChangeEvent evt){
> 
> public void attributeBChanged(ValueChangeEvent evt){
> 
> in the jsp:
> 
> valueChangeListener="#{PopulateListsBean.attributeAChanged}"
> valueChangeListener="#{PopulateListsBean.attributeBChanged}"
> 
> 
> Does anyone know why the first declared method is always called even if
> attributeB is changed??
> 
> I was not able to find anywhere in the spec anything related to that.
> 
> Can anyone help?

This sure looks like a bug to me; I can't see anything wrong with your 
code. Multiple valueChangeListener methods should be supported AFAIK. I 
presume you are checking which methods are called by logging output in 
each one, or using breakpoints?

By the way, in a later email you give this code:
 > ***********************
 >  public void contractCodeChanged(ValueChangeEvent evt){
 >         log.info("contractCodeChanged");
 >         this.contractCode = (String) evt.getNewValue();
 >     }

Updating the model from a value-changed-event is probably not a good 
idea. These callbacks get executed at the end of the validation phase, 
and are run even if validation failures have occurred on other 
components. Therefore if a validation failure has occurred then the 
value-change-listener method is called but the model is never updated 
from other components.

Note also that you have:
<h:selectOneMenu
   value="#{PopulateListsBean.contractCode}"
   ...
so during the update phase the contractCode field will be updated by the 
component, ie your contractCodeChanged method's change to that property 
will be very brief. Of course in this case you're just assigning the 
final value a bit early (for some reason) so in this case a value X is 
being overwritten with value X.

And finally, if there *is* a validation failure then the selectOneMenu 
component will re-render itself using the value cached in the model 
rather than fetching from the model.

Regards,

Simon


Re: MyFaces and valueChangeListener??

Posted by Andrew Robinson <an...@gmail.com>.
valueChangeListener equates to "public MethodBinding
getValueChangeListener()" and "public void
getValueChangeListener(MethodBinding method)" on the "UIInput" class.
As you can see, it isn't an add/remove. The JSP tag class may be
different, but if you are using facelets, you can only have one value
change listener as an EL expression.

On 2/21/07, Julien Martin <ba...@gmail.com> wrote:
> Hello Andrew,
>
> I know what you mean but please have a look at that:
> ***********************
>  public void contractCodeChanged(ValueChangeEvent evt){
>         log.info("contractCodeChanged");
>         this.contractCode = (String) evt.getNewValue();
>     }
> ***********************
>
> The above code NEVER gets called by that:
> *********************
> valueChangeListener="#{
> PopulateListsBean.contractCodeChanged}"
> *********************
>
> BECAUSE there are several value change listener methods in my bean.
>
> What I find strange or even "flawed" is that MyFaces won't even find the
> second listener method.
>
> Any clue??
>
> Julien.

Re: MyFaces and valueChangeListener??

Posted by Julien Martin <ba...@gmail.com>.
Hello Andrew,

I know what you mean but please have a look at that:
***********************
 public void contractCodeChanged(ValueChangeEvent evt){
        log.info("contractCodeChanged");
        this.contractCode = (String) evt.getNewValue();
    }
***********************

The above code NEVER gets called by that:
*********************
valueChangeListener="#{PopulateListsBean.contractCodeChanged}"
*********************

BECAUSE there are several value change listener methods in my bean.

What I find strange or even "flawed" is that MyFaces won't even find the
second listener method.

Any clue??

Julien.

Re: MyFaces and valueChangeListener??

Posted by Andrew Robinson <an...@gmail.com>.
The value change listener fires a change if the submitted value of the
UIInput component is different from the current value. It has nothing
to do with attributes, only the value of the UIInput.

On 2/21/07, Julien Martin <ba...@gmail.com> wrote:
> Hello,
>
> I have several components in my jsf page each having a valuechangelistener
> attribute and each attribute having a corresponding methods in my backing
> bean.
>
> public void attributeAChanged(ValueChangeEvent evt){
>
> public void attributeBChanged(ValueChangeEvent evt){
>
> in the jsp:
>
> valueChangeListener="#{PopulateListsBean.attributeAChanged}"
> valueChangeListener="#{PopulateListsBean.attributeBChanged}"
>
>
> Does anyone know why the first declared method is always called even if
> attributeB is changed??
>
> I was not able to find anywhere in the spec anything related to that.
>
> Can anyone help?
>
> Thanks in advance,
>
>
> Julien.
>

Re: MyFaces and valueChangeListener??

Posted by Julien Martin <ba...@gmail.com>.
Try sending them here: balteo@gmail.com

2007/2/22, wang suya <o-...@seiss.co.jp>:
>
> Hi Julien Martin
>
>   I tryed to send my war file but it returned to me I could not send it.
>
> Wang suya
>
> Julien Martin さんは書きました:
> >try your basic example with the Sun RI or please send me your war here:
> >balteo@yahoo.fr
> >Julien.
> >
> >2007/2/22, wang suya <o-...@seiss.co.jp>:
> >>
> >> Hello Julien Martin
> >>
> >>    Thank you for your hlep. Maybe it is the problem of version of
> MyFaces.
> >> Hope somebody can hlep me.
> >>
> >> Wang suya
> >>
> >>
> >> Julien Martin さんは書きました:
> >> >Hello Wang,
> >> >I tried to recreate your bug by deploying the artifacts you gave me
> but
> >> was
> >> >not able to reproduce the bug. In other words it WORKS fine and there
> is
> >> >nothing wrong with your code. Can someone bear me out on this please?
> >>
> >> wang suya
> >>
>
> wang suya
>

Re: MyFaces and valueChangeListener??

Posted by wang suya <o-...@seiss.co.jp>.
Hi Julien Martin

  I tryed to send my war file but it returned to me I could not send it.

Wang suya

Julien Martin さんは書きました:
>try your basic example with the Sun RI or please send me your war here:
>balteo@yahoo.fr
>Julien.
>
>2007/2/22, wang suya <o-...@seiss.co.jp>:
>>
>> Hello Julien Martin
>>
>>    Thank you for your hlep. Maybe it is the problem of version of MyFaces.
>> Hope somebody can hlep me.
>>
>> Wang suya
>>
>>
>> Julien Martin さんは書きました:
>> >Hello Wang,
>> >I tried to recreate your bug by deploying the artifacts you gave me but
>> was
>> >not able to reproduce the bug. In other words it WORKS fine and there is
>> >nothing wrong with your code. Can someone bear me out on this please?
>>
>> wang suya
>>

wang suya

Re: MyFaces and valueChangeListener??

Posted by Julien Martin <ba...@gmail.com>.
try your basic example with the Sun RI or please send me your war here:
balteo@yahoo.fr
Julien.

2007/2/22, wang suya <o-...@seiss.co.jp>:
>
> Hello Julien Martin
>
>    Thank you for your hlep. Maybe it is the problem of version of MyFaces.
> Hope somebody can hlep me.
>
> Wang suya
>
>
> Julien Martin さんは書きました:
> >Hello Wang,
> >I tried to recreate your bug by deploying the artifacts you gave me but
> was
> >not able to reproduce the bug. In other words it WORKS fine and there is
> >nothing wrong with your code. Can someone bear me out on this please?
>
> wang suya
>

Re: MyFaces and valueChangeListener??

Posted by wang suya <o-...@seiss.co.jp>.
Hello Julien Martin

   Thank you for your hlep. Maybe it is the problem of version of MyFaces.
Hope somebody can hlep me.

Wang suya


Julien Martin さんは書きました:
>Hello Wang,
>I tried to recreate your bug by deploying the artifacts you gave me but was
>not able to reproduce the bug. In other words it WORKS fine and there is
>nothing wrong with your code. Can someone bear me out on this please?

wang suya

Re: MyFaces and valueChangeListener??

Posted by Julien Martin <ba...@gmail.com>.
Hello Wang,
I tried to recreate your bug by deploying the artifacts you gave me but was
not able to reproduce the bug. In other words it WORKS fine and there is
nothing wrong with your code. Can someone bear me out on this please?

Re: MyFaces and valueChangeListener??

Posted by wang suya <o-...@seiss.co.jp>.
Hi Julien Martin

   Thank you for your replay. I used both MyFaces1.1.5 and MyFaces1.1.5-SNAPSHOT but
it did not work. My code is as below:

<%@page contentType="text/html; charset=Shift_JIS" %>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>

<html>
<head>
<title>jsfsample1</title>
</head>
<body bgcolor="#ffffff">
<h1>JSF sample</h1>
<f:view>
	<h:form id="form1">
		<h:outputText
		id="text1" 
		binding="#{SampleJsfBean.text1}"/>
		<br />
		<h:selectBooleanCheckbox 
		id="check1"
		immediate="true"
		onchange="this.form.submit();"
		binding="#{SampleJsfBean.check1}"
		valueChangeListener="#{SampleJsfBean.check1_valueChanged}" />
		<h:messages/>
		<h:outputText	
		value="check"/>
	</h:form>

</f:view>
</body>
</html>

package jp.tuyano.eclipsebook3;

import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlSelectBooleanCheckbox;
import javax.faces.event.ValueChangeEvent;

/**
 * @author 王
 *
 */
public class SampleJsfBean {
	private HtmlOutputText text1;
	private HtmlSelectBooleanCheckbox check1;
	
	/**
	 * @return check1 を戻します。
	 */
	public HtmlSelectBooleanCheckbox getCheck1() {
		return check1;
	}
	/**
	 * @param check1 設定する check1。
	 */
	public void setCheck1(HtmlSelectBooleanCheckbox check1) {
		this.check1 = check1;
	}
	/**
	/**
	 * @return text1 を戻します。
	 */
	public HtmlOutputText getText1() {
		return text1;
	}
	/**
	 * @param text1 設定する text1。
	 */
	public void setText1(HtmlOutputText text1) {
		this.text1 = text1;
	}
	
	
	public void check1_valueChanged(ValueChangeEvent valueChangeEvent){
		Boolean neu =(Boolean)valueChangeEvent.getNewValue();
		text1.setValue("check is " + neu.toString());
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
	<display-name>JSFSample</display-name> 
		<servlet>
			<servlet-name>Faces Servlet</servlet-name> 
			<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
			<load-on-startup>1</load-on-startup> 
		</servlet>
		<servlet-mapping>
			<servlet-name>Faces Servlet</servlet-name> 
			<url-pattern>*.jsf</url-pattern> 
		</servlet-mapping>
</web-app>

I don't know why it is not work. Hope you can help me. Thank you very much.

wang suya




Julien Martin さんは書きました:
>Hello,
>
>Thank you all for your feedback. I realized after posting this email that
>the internet is replete with posts of people having had the same problem as
>me i.e. multiple components trying to trigger each its value change listener
>and that no one has got the solution...
>
>Wang, for you info, I use MyFaces 1.1.4.
>
>Post your code and I'll tell you how to get it working.
>
>Best regards,
>
>Julien.
>
>2007/2/22, wang suya <o-...@seiss.co.jp>:
>>
>>
>> Hello Julien Martin
>>
>>    Why your valueChangeListener worked and my valueChangeListener does not
>> work?
>> Which version of myfaces and tomahawk and tomahawk-sandbox do you use and
>> which
>> OS do you use?
>>
>> Wang suya
>>
>>
>> Julien Martin さんは書きました:
>> >Hello,
>> >
>> >I have several components in my jsf page each having a
>> valuechangelistener
>> >attribute and each attribute having a corresponding  methods in my
>> backing
>> >bean.
>> >
>> >public void attributeAChanged(ValueChangeEvent evt){
>> >public void attributeBChanged(ValueChangeEvent evt){
>> >
>> >in the jsp:
>> >
>> >valueChangeListener="#{PopulateListsBean.attributeAChanged}"
>> >valueChangeListener="#{PopulateListsBean.attributeBChanged}"
>> >
>> >Does anyone know why the first declared method is always called even if
>> >attributeB is changed??
>> >
>> >I was not able to find anywhere in the spec anything related to that.
>> >
>> >Can anyone help?
>> >
>> >Thanks in advance,
>> >
>> >Julien.
>>
>> wang suya
>>

wang suya

Re: MyFaces and valueChangeListener??

Posted by Julien Martin <ba...@gmail.com>.
Hello,

Thank you all for your feedback. I realized after posting this email that
the internet is replete with posts of people having had the same problem as
me i.e. multiple components trying to trigger each its value change listener
and that no one has got the solution...

Wang, for you info, I use MyFaces 1.1.4.

Post your code and I'll tell you how to get it working.

Best regards,

Julien.

2007/2/22, wang suya <o-...@seiss.co.jp>:
>
>
> Hello Julien Martin
>
>    Why your valueChangeListener worked and my valueChangeListener does not
> work?
> Which version of myfaces and tomahawk and tomahawk-sandbox do you use and
> which
> OS do you use?
>
> Wang suya
>
>
> Julien Martin さんは書きました:
> >Hello,
> >
> >I have several components in my jsf page each having a
> valuechangelistener
> >attribute and each attribute having a corresponding  methods in my
> backing
> >bean.
> >
> >public void attributeAChanged(ValueChangeEvent evt){
> >public void attributeBChanged(ValueChangeEvent evt){
> >
> >in the jsp:
> >
> >valueChangeListener="#{PopulateListsBean.attributeAChanged}"
> >valueChangeListener="#{PopulateListsBean.attributeBChanged}"
> >
> >Does anyone know why the first declared method is always called even if
> >attributeB is changed??
> >
> >I was not able to find anywhere in the spec anything related to that.
> >
> >Can anyone help?
> >
> >Thanks in advance,
> >
> >Julien.
>
> wang suya
>

Re: MyFaces and valueChangeListener??

Posted by wang suya <o-...@seiss.co.jp>.
Hello Julien Martin

   Why your valueChangeListener worked and my valueChangeListener does not work?
Which version of myfaces and tomahawk and tomahawk-sandbox do you use and which
OS do you use?

Wang suya


Julien Martin さんは書きました:
>Hello,
>
>I have several components in my jsf page each having a valuechangelistener
>attribute and each attribute having a corresponding  methods in my backing
>bean.
>
>public void attributeAChanged(ValueChangeEvent evt){
>public void attributeBChanged(ValueChangeEvent evt){
>
>in the jsp:
>
>valueChangeListener="#{PopulateListsBean.attributeAChanged}"
>valueChangeListener="#{PopulateListsBean.attributeBChanged}"
>
>Does anyone know why the first declared method is always called even if
>attributeB is changed??
>
>I was not able to find anywhere in the spec anything related to that.
>
>Can anyone help?
>
>Thanks in advance,
>
>Julien.

wang suya