eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
161 stars 110 forks source link

valueChangeListener doesn't get triggered correctly in request scoped bean #1733

Closed ren-zhijun-oracle closed 14 years ago

ren-zhijun-oracle commented 14 years ago

i implemented a valueChangeListener inside an inputText as a child-element.

<h:inputText id="test" value="#

{test.input1}

" >

</h:inputText>

input1 is an int Value inside a @RequestScoped Bean with set and get-Methods

private int input1;

public int getInput1()

{ return input1; }

public void setInput1(int input1)

{ this.input1 = input1; }

The ValueChangeListener is defined as:

package app;

import javax.faces.event.AbortProcessingException; import javax.faces.event.ValueChangeEvent; import javax.faces.event.ValueChangeListener;

public class listener implements ValueChangeListener {

public void processValueChange(ValueChangeEvent event) throws AbortProcessingException

{ System.out.println("Hello from processValueChange"); }

}

Scenario

if i insert, for example a int like 1 an submit the form, the listener gets triggered correctly.

i insert a 2 and submit, the listener gets triggered.

i insert a 0 and submit, the listener should trigger too, but doesn't.

i assume, he doesn't trigger against the component tree, but against the managed bean.

Environment

Operating System: Windows XP Platform: All URL: http://pastebin.org/386722

Affected Versions

[2.0.3]

ren-zhijun-oracle commented 6 years ago
ren-zhijun-oracle commented 14 years ago

@javaserverfaces Commented Reported by glister

ren-zhijun-oracle commented 14 years ago

@javaserverfaces Commented @edburns said: start eval at 11:15 EDT

ren-zhijun-oracle commented 14 years ago

@javaserverfaces Commented @edburns said: I found another problem while investigating this a masked exception.

I've fixed that one and am running the automated tests to make sure the fix didn't break anything.

I also blogged about the experience at

http://www.java.net/blog/edburns/archive/2010/07/09/lean-team-agressive-schedule-software- ghetto

ren-zhijun-oracle commented 14 years ago

@javaserverfaces Commented @edburns said: The system is performing as specified.

Because the bean is request scoped, the value of the int property always starts out as 0 because that's what the JLS says ints should be if they're not assigned something else at declaration time.

The valueChangeEvent is not fired when the input value is 0 because the valueChangeEvent is only fired if the value changed.

If you add an assignment to the bean declaration, then you'll see the event being fired.

I've added an automated test to show this works, and to catch if it stops working.

Bean:

package com.sun.faces.systest.model;

import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext;

/*

/* Creates a new instance of test / public Bean1729() { }

private int input1 = -1;

public int getInput1()

{ return input1; }

public void setInput1(int input1)

{ this.input1 = input1; }

public void doIt()

{ FacesContext context = FacesContext.getCurrentInstance(); context.getExternalContext().getFlash().put("processActionListenerMessage", "Aufgerufen: " + System.currentTimeMillis()); }

}

Listener:

package com.sun.faces.systest;

import javax.faces.context.FacesContext; import javax.faces.event.AbortProcessingException; import javax.faces.event.ValueChangeEvent; import javax.faces.event.ValueChangeListener;

/*

public void processValueChange(ValueChangeEvent event) throws AbortProcessingException

{ FacesContext context = FacesContext.getCurrentInstance(); context.getExternalContext().getFlash().put("processValueChangeMessage", "Hello from processValueChange: " + System.currentTimeMillis()); }

}

XHTML file:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">

Facelet Title

[https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1729](https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1729)

actionListenerMessage: # {flash['processActionListenerMessage']}

valueChangeListenerMessage: # {flash['processValueChangeMessage']}

Automated Test: package com.sun.faces.event; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.javascript.host.HTMLAnchorElement; import junit.framework.Test; import junit.framework.TestSuite; import com.sun.faces.htmlunit.AbstractTestCase; /** * Unit tests for Composite Components. */ public class ValueChangeListenerCalledTestCase extends AbstractTestCase { public ValueChangeListenerCalledTestCase() { this("ValueChangeListenerCalledTestCase"); } public ValueChangeListenerCalledTestCase(String name) { super(name); } /** * Set up instance variables required by this test case. */ public void setUp() throws Exception { super.setUp(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(ValueChangeListenerCalledTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { super.tearDown(); } // -------------------------------------------------------------- Test Cases public void testValueChangeListenerCalled() throws Exception { HtmlPage page = getPage("/faces/listener-1729.xhtml"); HtmlTextInput textField = (HtmlTextInput) page.getElementById("test"); textField.setValueAttribute("0"); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); String text = page.asText(); String currentTime = "" + System.currentTimeMillis(); currentTime = currentTime.substring(0, 9); assertTrue(text.contains("Aufgerufen: " + currentTime)); assertTrue(text.contains("Hello from processValueChange: " + currentTime)); textField = (HtmlTextInput) page.getElementById("test"); textField.setValueAttribute("3"); HtmlAnchor anchor = (HtmlAnchor) page.getElementById("link"); page = anchor.click(); text = page.asText(); currentTime = "" + System.currentTimeMillis(); currentTime = currentTime.substring(0, 9); assertTrue(text.contains("Aufgerufen: " + currentTime)); assertTrue(text.contains("Hello from processValueChange: " + currentTime)); } } Marking as INVALID
ren-zhijun-oracle commented 14 years ago

@javaserverfaces Commented raydecampo said: The reporter would get the desired results if the property is changed from an int to an Integer.

ren-zhijun-oracle commented 12 years ago

@javaserverfaces Commented @manfredriem said: Closing resolved issue out

ren-zhijun-oracle commented 7 years ago

@javaserverfaces Commented This issue was imported from java.net JIRA JAVASERVERFACES-1729

ren-zhijun-oracle commented 14 years ago

@javaserverfaces Commented Marked as incomplete on Monday, July 12th 2010, 5:09:47 am