Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewParam + Ajax Call issue #4734

Closed
erickdeoliveiraleal opened this issue Jul 22, 2020 · 26 comments
Closed

ViewParam + Ajax Call issue #4734

erickdeoliveiraleal opened this issue Jul 22, 2020 · 26 comments
Assignees

Comments

@erickdeoliveiraleal
Copy link

erickdeoliveiraleal commented Jul 22, 2020

I still have a problem with JSF 2.3 related to ViewParam, I tested it with WildFly 21 (released october 2020) and the bug is still there. The code is in the following repositories: Jetty example: https://github.com/erickdeoliveiraleal/primefaces-test/tree/viewparam Wildfly example https://gitlab.com/erickdeoliveiraleal/simpleproject

Note that Wildfly already incorporated all the fixes recently done recently in Mojarra 2.3 repository.

When you click on button the second time a exception happens, this is not the case when using mojarra 2.2, myfaces 2.2 or myfaces 2.3

XHTML:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

<f:metadata>
	<f:viewParam id="id" name="id" value="#{testView.testClass.id}" />
</f:metadata>

<h:form>

	<h:commandButton>
		<f:ajax execute="@form"  />
	</h:commandButton>

	<h:selectOneMenu value="#{testView.testClass}">
		<f:selectItem itemValue="null" itemLabel="Sel. classe" />
		<f:selectItems value="#{testView.testClasses}" var="cl"
			itemValue="#{cl}" itemLabel="#{cl.id}" />
	</h:selectOneMenu>

</h:form>

</html>

Bean

package org.primefaces.test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class TestView implements Serializable {

	private TestClass testClass;
	private List<TestClass> testClasses;

	@PostConstruct
	public void init() {
		testClass = new TestClass();
		testClasses = new ArrayList<>();
		testClasses.add(new TestClass(1));
	}

	public TestClass getTestClass() {
		return testClass;
	}

	public void setTestClass(TestClass testClass) {
		this.testClass = testClass;
	}

	public List<TestClass> getTestClasses() {
		return testClasses;
	}

	public void setTestClasses(List<TestClass> testClasses) {
		this.testClasses = testClasses;
	}

}


Entity Class

package org.primefaces.test;

public class TestClass {
	Integer id;

	public TestClass() {
	}

	public TestClass(Integer a) {
		id = a;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TestClass other = (TestClass) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Classe [id=" + id + "]";
	}
}

Converter

package org.primefaces.test;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

//@FacesConverter(value = "TestClassConverter")    
@FacesConverter(forClass = TestClass.class)
public class TestClassConverter implements Converter {
    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
        if (value != null && !value.isEmpty()) {
            return (TestClass) uiComponent.getAttributes().get(value);
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
        if (value instanceof TestClass) {
            TestClass entity= (TestClass) value;
            if (entity != null && entity instanceof TestClass && entity.getId() != null) {
                uiComponent.getAttributes().put( entity.getId().toString(), entity);
                return entity.getId().toString();
            }
        }
        return "";
    }
}

You also need to set INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL as true

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
  </context-param>

the exception

WARNING: /test.xhtml @10,68 value="#{testView.testClass.id}": Target Unreachable, [testClass] returned null
javax.el.PropertyNotFoundException: /test.xhtml @10,68 value="#{testView.testClass.id}": Target Unreachable, [testClass] returned null
        at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:64)
        at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:71)
        at javax.faces.component.UIViewParameter.getConvertedValue(UIViewParameter.java:458)
        at javax.faces.component.UIInput.validate(UIInput.java:1006)
        at javax.faces.component.UIInput.executeValidate(UIInput.java:1317)
        at javax.faces.component.UIInput.processValidators(UIInput.java:733)
        at javax.faces.component.UIViewParameter.processValidators(UIViewParameter.java:279)
        at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
        at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:921)
        at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1310)
        at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:53)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
        at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
        at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1386)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1617)
        at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:590)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1300)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1215)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.Server.handle(Server.java:500)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, [testClass] returned null
        at org.apache.el.parser.AstValue.getTarget(AstValue.java:124)
        at org.apache.el.parser.AstValue.getType(AstValue.java:58)
        at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:174)
        at org.apache.webbeans.el22.WrappedValueExpression.getType(WrappedValueExpression.java:59)
        at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
        ... 52 more

[WARNING] /primefaces-test/test.xhtml
javax.servlet.ServletException: javax.servlet.ServletException: /test.xhtml @10,68 value="#{testView.testClass.id}": Target Unreachable, [testClass] returned null
    at org.eclipse.jetty.server.handler.HandlerCollection.handle (HandlerCollection.java:162)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.Server.handle (Server.java:500)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1 (HttpChannel.java:383)
    at org.eclipse.jetty.server.HttpChannel.dispatch (HttpChannel.java:547)
    at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:375)
    at org.eclipse.jetty.server.HttpConnection.onFillable (HttpConnection.java:273)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:311)
    at org.eclipse.jetty.io.FillInterest.fillable (FillInterest.java:103)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run (ChannelEndPoint.java:117)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask (EatWhatYouKill.java:336)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce (EatWhatYouKill.java:313)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce (EatWhatYouKill.java:171)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run (EatWhatYouKill.java:129)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run (ReservedThreadExecutor.java:375)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:806)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run (QueuedThreadPool.java:938)
    at java.lang.Thread.run (Thread.java:834)
Caused by: javax.servlet.ServletException: /test.xhtml @10,68 value="#{testView.testClass.id}": Target Unreachable, [testClass] returned null
    at javax.faces.webapp.FacesServlet.executeLifecyle (FacesServlet.java:725)
    at javax.faces.webapp.FacesServlet.service (FacesServlet.java:451)
    at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service (ServletHolder.java:1386)
    at org.eclipse.jetty.servlet.ServletHolder.handle (ServletHolder.java:755)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1617)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter (WebSocketUpgradeFilter.java:226)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1604)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:545)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:590)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:235)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:1610)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:233)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1300)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:188)
    at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:485)
    at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:1580)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:186)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1215)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:221)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle (HandlerCollection.java:146)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.Server.handle (Server.java:500)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1 (HttpChannel.java:383)
    at org.eclipse.jetty.server.HttpChannel.dispatch (HttpChannel.java:547)
    at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:375)
    at org.eclipse.jetty.server.HttpConnection.onFillable (HttpConnection.java:273)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:311)
    at org.eclipse.jetty.io.FillInterest.fillable (FillInterest.java:103)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run (ChannelEndPoint.java:117)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask (EatWhatYouKill.java:336)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce (EatWhatYouKill.java:313)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce (EatWhatYouKill.java:171)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run (EatWhatYouKill.java:129)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run (ReservedThreadExecutor.java:375)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:806)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run (QueuedThreadPool.java:938)
    at java.lang.Thread.run (Thread.java:834)
Caused by: javax.el.PropertyNotFoundException: /test.xhtml @10,68 value="#{testView.testClass.id}": Target Unreachable, [testClass] returned null
    at com.sun.faces.facelets.el.TagValueExpression.getType (TagValueExpression.java:64)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue (HtmlBasicInputRenderer.java:71)
    at javax.faces.component.UIViewParameter.getConvertedValue (UIViewParameter.java:458)
    at javax.faces.component.UIInput.validate (UIInput.java:1006)
    at javax.faces.component.UIInput.executeValidate (UIInput.java:1317)
    at javax.faces.component.UIInput.processValidators (UIInput.java:733)
    at javax.faces.component.UIViewParameter.processValidators (UIViewParameter.java:279)
    at javax.faces.component.UIComponentBase.processValidators (UIComponentBase.java:921)
    at javax.faces.component.UIComponentBase.processValidators (UIComponentBase.java:921)
    at javax.faces.component.UIViewRoot.processValidators (UIViewRoot.java:1310)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute (ProcessValidationsPhase.java:53)
    at com.sun.faces.lifecycle.Phase.doPhase (Phase.java:76)
    at com.sun.faces.lifecycle.LifecycleImpl.execute (LifecycleImpl.java:177)
    at javax.faces.webapp.FacesServlet.executeLifecyle (FacesServlet.java:707)
    at javax.faces.webapp.FacesServlet.service (FacesServlet.java:451)
    at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service (ServletHolder.java:1386)
    at org.eclipse.jetty.servlet.ServletHolder.handle (ServletHolder.java:755)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1617)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter (WebSocketUpgradeFilter.java:226)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1604)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:545)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:590)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:235)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:1610)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:233)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1300)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:188)
    at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:485)
    at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:1580)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:186)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1215)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:221)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle (HandlerCollection.java:146)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.Server.handle (Server.java:500)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1 (HttpChannel.java:383)
    at org.eclipse.jetty.server.HttpChannel.dispatch (HttpChannel.java:547)
    at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:375)
    at org.eclipse.jetty.server.HttpConnection.onFillable (HttpConnection.java:273)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:311)
    at org.eclipse.jetty.io.FillInterest.fillable (FillInterest.java:103)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run (ChannelEndPoint.java:117)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask (EatWhatYouKill.java:336)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce (EatWhatYouKill.java:313)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce (EatWhatYouKill.java:171)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run (EatWhatYouKill.java:129)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run (ReservedThreadExecutor.java:375)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:806)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run (QueuedThreadPool.java:938)
    at java.lang.Thread.run (Thread.java:834)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, [testClass] returned null
    at org.apache.el.parser.AstValue.getTarget (AstValue.java:124)
    at org.apache.el.parser.AstValue.getType (AstValue.java:58)
    at org.apache.el.ValueExpressionImpl.getType (ValueExpressionImpl.java:174)
    at org.apache.webbeans.el22.WrappedValueExpression.getType (WrappedValueExpression.java:59)
    at com.sun.faces.facelets.el.TagValueExpression.getType (TagValueExpression.java:62)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue (HtmlBasicInputRenderer.java:71)
    at javax.faces.component.UIViewParameter.getConvertedValue (UIViewParameter.java:458)
    at javax.faces.component.UIInput.validate (UIInput.java:1006)
    at javax.faces.component.UIInput.executeValidate (UIInput.java:1317)
    at javax.faces.component.UIInput.processValidators (UIInput.java:733)
    at javax.faces.component.UIViewParameter.processValidators (UIViewParameter.java:279)
    at javax.faces.component.UIComponentBase.processValidators (UIComponentBase.java:921)
    at javax.faces.component.UIComponentBase.processValidators (UIComponentBase.java:921)
    at javax.faces.component.UIViewRoot.processValidators (UIViewRoot.java:1310)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute (ProcessValidationsPhase.java:53)
    at com.sun.faces.lifecycle.Phase.doPhase (Phase.java:76)
    at com.sun.faces.lifecycle.LifecycleImpl.execute (LifecycleImpl.java:177)
    at javax.faces.webapp.FacesServlet.executeLifecyle (FacesServlet.java:707)
    at javax.faces.webapp.FacesServlet.service (FacesServlet.java:451)
    at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service (ServletHolder.java:1386)
    at org.eclipse.jetty.servlet.ServletHolder.handle (ServletHolder.java:755)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1617)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter (WebSocketUpgradeFilter.java:226)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1604)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:545)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:590)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:235)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:1610)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:233)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1300)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:188)
    at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:485)
    at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:1580)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope (ScopedHandler.java:186)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1215)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:221)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle (HandlerCollection.java:146)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:127)
    at org.eclipse.jetty.server.Server.handle (Server.java:500)
    at org.eclipse.jetty.server.HttpChannel.lambda$handle$1 (HttpChannel.java:383)
    at org.eclipse.jetty.server.HttpChannel.dispatch (HttpChannel.java:547)
    at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:375)
    at org.eclipse.jetty.server.HttpConnection.onFillable (HttpConnection.java:273)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:311)
    at org.eclipse.jetty.io.FillInterest.fillable (FillInterest.java:103)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run (ChannelEndPoint.java:117)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask (EatWhatYouKill.java:336)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce (EatWhatYouKill.java:313)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce (EatWhatYouKill.java:171)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run (EatWhatYouKill.java:129)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run (ReservedThreadExecutor.java:375)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:806)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run (QueuedThreadPool.java:938)
    at java.lang.Thread.run (Thread.java:834)
@erickdeoliveiraleal
Copy link
Author

erickdeoliveiraleal commented Jul 22, 2020

@soul2zimate can you have a look? I will try again to reduce the code to not use PrimeFaces.
@codylerum

@arjantijms
Copy link
Contributor

I will try again to reduce the code to not use PrimeFaces.

It would be very helpful to provide a reproducer that doesn't use PrimeFaces. If this is not possible, maybe the bug is in PF?

@erickdeoliveiraleal
Copy link
Author

erickdeoliveiraleal commented Sep 4, 2020

It's not a PF bug, because with Mojarra 2.2 it works. And also MyFaces 2.2 or 2.3

@arjantijms
Copy link
Contributor

I dont believe it is PF bug, because with Mojarra 2.2 it works. And also MyFaces 2.2 or 2.3

That does provide a good hint, though it could still be something PF does that just happens to work there. Anyway, a reproducer without PF would be really cool to have ;)

@erickdeoliveiraleal
Copy link
Author

erickdeoliveiraleal commented Oct 14, 2020

I dont believe it is PF bug, because with Mojarra 2.2 it works. And also MyFaces 2.2 or 2.3

That does provide a good hint, though it could still be something PF does that just happens to work there. Anyway, a reproducer without PF would be really cool to have ;)

@arjantijms I was able to reduce to a pure mojarra code and updated the issue description. If you can, please look to this issue.

@soul2zimate
Copy link
Contributor

@arjantijms @erickdeoliveiraleal I don't understand why the exception appears at the second time, but this javax.el.PropertyNotFoundException: Target Unreachable, [testClass] returned null reminds me errors relate to activating CDI in JSF 2.3

@erickdeoliveiraleal Could you try the solution at https://www.thetopsites.net/article/58334699.shtml ? add the required changes for beans.xml, faces-config.xml and Jsf23Activator in order to activate CDI in JSF 2.3?

@erickdeoliveiraleal
Copy link
Author

@arjantijms @erickdeoliveiraleal I don't understand why the exception appears at the second time, but this javax.el.PropertyNotFoundException: Target Unreachable, [testClass] returned null reminds me errors relate to activating CDI in JSF 2.3

@erickdeoliveiraleal Could you try the solution at https://www.thetopsites.net/article/58334699.shtml ? add the required changes for beans.xml, faces-config.xml and Jsf23Activator in order to activate CDI in JSF 2.3?

I used it now and I got the same result.

@codylerum
Copy link
Contributor

codylerum commented Oct 15, 2020

@erickdeoliveiraleal This is definitely an interesting case which may be related to some extreamly intermittent issues I've been having with Mojarra and Wildfly going back to earlier wildfly released (at least 14 and may earlier). The issue always presents as a @ViewScoped bean which ends up being null after post back. The bean was previously initialized and the @PreDestroy was never called.

It is a situation where I would have expected a view expired exception but instead get a null on a bean that should exist.

That said it has been impossible to reproduce on my end. The closest I have gotten is this Wildfly issue https://issues.redhat.com/projects/WFLY/issues/WFLY-13666 which I feel like could be related, but only started presenting in Wildfly 19 and higher. Though this feels more like an undertow issue.

@erickdeoliveiraleal
Copy link
Author

I updated the code

@erickdeoliveiraleal This is definitely an interesting case which may be related to some extreamly intermittent issues I've been having with Mojarra and Wildfly going back to earlier wildfly released (at least 14 and may earlier). The issue always presents as a @ViewScoped bean which ends up being null after post back. The bean was previously initialized and the @PreDestroy was never called.

It is a situation where I would have expected a view expired exception but instead get a null on a bean that should exist.

That said it has been impossible to reproduce on my end. The closest I have gotten is this Wildfly issue https://issues.redhat.com/projects/WFLY/issues/WFLY-13666 which I feel like could be related, but only started presenting in Wildfly 19 and higher. Though this feels more like an undertow issue.

It's not intermitent, it's always present, if you copy and paste my code and run on WildFly 21 or any other server the error appears, I posted an example in Jetty using primefaces-test repository, just enter the page without any parameters filled, press the button more than one time and the error appears. I tested it against other servers and different versions of JSF 2.3, the bug is always there.

@erickdeoliveiraleal
Copy link
Author

project.zip
simple maven project with pure JSF to run on WildFly or other server url to test: http://localhost/project-0.0.1-SNAPSHOT/test.xhtml

@soul2zimate
Copy link
Contributor

soul2zimate commented Oct 19, 2020

It seems this fails due to the same broken change made in javaserverfaces/mojarra@4c74d1f since Mojarra 2.3. That change leads to a call on getConvertedValue(context, submittedValue); with a null submittedValue inside UIInput.validate () method. Fix made for #4550 did not change that.

IMHO, getting a converted value for a null value doesn't make sense. However the idea of javaserverfaces/mojarra@4c74d1f is to ensure that validation logic gets a chance to be executed If the EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is true, so the validateValue method must be called.

Below change in UIInput.java can avoid the exception described in this issue, but I can't explain why this eventually makes the javax.el.PropertyNotFoundException: Target Unreachable, [testClass] returned null.

-                    validateValue(context,  getConvertedValue(context, submittedValue));
+                    validateValue(context,  submittedValue);

Based on previous story around this class, in order to prevent any unexpected regression, I would really appreciate opinions from JSF experts who are familiar with this piece of code.

@arjantijms
Copy link
Contributor

@BalusC Can you take a look at it? I think you're most experienced with the EMPTY_STRING_SUBMITTED_VALUES_AS_NULL saga.

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

javaserverfaces/mojarra@4c74d1f says this

I feel this additional check is less disruptive than BalusC's initial proposal.

My initial proposal was to modify ONLY the UIViewParam class as described here: #3343 (comment). But it was eventually implemented in UIInput superclass, hereby also affecting all other input components extending from it, including the UISelectOne/UISelectMany which in turn has in Mojarra also its own special case for an empty string as submitted value. It's in the MenuRenderer interpreted as "component was not submitted at all", as can be seen here: https://github.com/eclipse-ee4j/mojarra/blob/2.3.14/impl/src/main/java/com/sun/faces/renderkit/html_basic/MenuRenderer.java#L879 This shall most probably have gone awry after the change done in issue 1329.

I cannot rollback the original change from issue 1329 anymore as it's basically already set in stone in JSF 2.3 API. So I'll have to focus on fixing the MenuRenderer in order to recognize this condition.

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

Hm.

I cannot reproduce your problem but I have spotted a handful things being odd in your reproducer:

  1. <f:viewParam> unexpectedly uses value="#{bean.entity.id}" instead of value="#{bean.entity}".
  2. Converter unexpectedly abuses JSF component state instead of normally converting.
  3. itemValue of default selection is unexpectedly a literal string of "null" instead of an actual null.

When I have corrected them as below:

public class Issue4734Entity implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    public Issue4734Entity(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    @Override
    public boolean equals(Object other) {
        return Objects.equals(id, ((Issue4734Entity) other).id);
    }
}
@FacesConverter(forClass=Issue4734Entity.class)
public class Issue4734EntityConverter implements Converter {

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object modelValue) {
        Long id = modelValue == null ? null : ((Issue4734Entity) modelValue).getId();
        return id == null ? "" : id.toString();
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
        Long id = submittedValue == null || submittedValue.isEmpty() ? null : Long.valueOf(submittedValue);
        return id == null ? null : new Issue4734Entity(id);
    }

}
@Named
@ViewScoped
public class Issue4734 implements Serializable {

    private static final long serialVersionUID = 1L;

    private Issue4734Entity entity;
    private List<Issue4734Entity> entities;

    @PostConstruct
    public void init() {
        entities = Arrays.asList(new Issue4734Entity(1L));
    }

    public Issue4734Entity getEntity() {
        return entity;
    }

    public void setEntity(Issue4734Entity entity) {
        this.entity = entity;
    }

    public List<Issue4734Entity> getEntities() {
        return entities;
    }
}
<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
>
    <f:metadata>
        <f:viewParam name="id" value="#{issue4734.entity}" />
    </f:metadata>

    <h:head>
        <title>Issue4734 - Empty submitted value of SelectItem must not be interpreted as RiConstants.NO_VALUE</title>
    </h:head>

    <h:body>
        <h:form id="form">
            <h:selectOneMenu id="menu" value="#{issue4734.entity}">
                <f:selectItem itemValue="#{null}" itemLabel="Select" />
                <f:selectItems value="#{issue4734.entities}" var="entity" itemLabel="#{entity.id}" />
            </h:selectOneMenu>
            <h:commandButton id="submit">
                <f:ajax execute="@form" />
            </h:commandButton>
        </h:form>
    </h:body>
</html>

Then your use case of opening issue4734.xhtml?id=1 and clicking the submit button multiple times (at least twice) works just fine for me.

I'll nonetheless analyze your specific case further as this should IMO indeed not happen.

@erickdeoliveiraleal
Copy link
Author

Really? You tested against JSF 2.2 and couldn't verify a different behaviour?
Clicking button second time with mojarra 2.2 doesn't cause an exception...

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

I tested against Mojarra 2.3.14.

@erickdeoliveiraleal
Copy link
Author

Yes, I tested against 2.3.14 and 2.2.20 and there's an exception that shows in JSF 2.3 and not in 2.2

@erickdeoliveiraleal
Copy link
Author

until tomorrow I will test it again and report here.

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

Have you actually read the entire comment? I have fixed at least three incorrect things in your code snippet. It could be in one of them. I'll analyze further.

@erickdeoliveiraleal
Copy link
Author

Sorry for misinterpret your answer @BalusC and thanks for the analysis

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

Sorry, I still cannot reproduce it after changing the code logic to exactly match the code logic posted in this ticket.

I even downloaded WildFly 21 and tried its bundled Mojarra 2.3.14.SP01 instead but it's also working fine over there.

I'll try checking out your actual project.

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

Nevermind, I have reproduced it with the provided code snippet when opening the page via issue4734.xhtml without passing the ?id=1 argument. This gives something to work with.

It's indeed also happening after I correct the converter and the default selection. This all is caused by unexpected usage of the view parameter as in <f:viewParam value="#{bean.entity.id}"> instead of <f:viewParam value="#{bean.entity}">. It's after all actually not caused by the dropdown component being a dropdown component.

@BalusC
Copy link
Contributor

BalusC commented Nov 15, 2020

I have analyzed the logic and it appears to be a general problem with input components. This won't necessarily only happen in f:viewParam, but all other inputs are prone to this issue as well when the nested property is null.

Indeed, generally the converter shouldn't need to be located when the supplied submitted value is null, but the spec doesn't forbid this condition. So an obscure custom converter might exist somewhere in the world which does a specific thing when a null value is passed as submitted value.

I've opted to fix this issue in Mojarra by simply suppressing any PropertyNotFoundException thrown by ValueExpression#getType() in HtmlBasicInputRenderer#getConvertedValue() when the submitted value is null in first place. This skipping of the conversion is harmless because the same exception will nonetheless be rethrown during update model values phase when the submitted value is actually not null.

PR: #4801, ran run-tests.sh at localhost, all passed, cc: @arjantijms


The 'correct' fix for your specific use case would be to just use

<f:viewParam name="id" value="#{testView.testClass}" />

in combination with a normal converter which really converts id to TestClass via an actual service method rather than trying to find it as a component attribute ;)

@manorrock
Copy link
Contributor

Please fix on 3.0 and master branch as well

BalusC added a commit that referenced this issue Feb 21, 2021
BalusC added a commit that referenced this issue Feb 21, 2021
BalusC added a commit that referenced this issue Feb 21, 2021
@BalusC
Copy link
Contributor

BalusC commented Feb 21, 2021

Done.

@BalusC BalusC closed this as completed Feb 21, 2021
@fcorneli
Copy link

FYI... just encountered something similar on a JSF composite component using a backing component.
When I set javax.faces.PARTIAL_STATE_SAVING to false, I also get the following exception on AJAX calls:

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'cc' resolved to null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants