У меня есть приложение, которое использует JSF 2.2 на payara 4.1.9.2 с
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Здесь все работает как положено.
Теперь я пытаюсь обновить его до Payara 5.1.9.3, которая работает с Mojarra 2.3.9.payara-p3.
Проблема, с которой я сталкиваюсь сейчас, заключается в том, что если ViewScope bean-компонент с параметрами, установленными с помощью f: viewParam при создании bean-компонента, используется для запуска ajax-запросов, viewParams теряются(нормальный) и модель обновлена со значениями NULL .
Итак, изначально viewParams работает нормально, значения берутся из GET, и модель устанавливается соответствующим образом. Когда первый запрос ajax запускается в UPDATE_MODEL_VALUES PHASE, значение атрибута bean устанавливается со старым значением (котороевсе в порядке), но во втором запросе ajax также в PHASE 4 значение атрибута обновляется с помощью NULL.
Я знаю, что по этой теме много сообщений (f: viewParams теряется при запросах ajax), но то, что мне не ясно, это:
Почему, если я отключаю директиву javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL, все в порядке, и если я ее больше не включаю?
PS. с Payara 4.1.2.174 и Мохаррой 2.2.14
Обновление:
здесь мы видим counter.xhtml
<ui:composition template="../layouts/user.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:sec="http://www.springframework.org/security/tags">
<f:metadata>
<f:viewParam name="id" value="#{counterMB.id}"/>
</f:metadata>
<ui:param name="currentMB" value="#{counterMB}"/>
<ui:define name="title">Counter </ui:define>
<h:form id="myForm">
Id is <h:outputText value="#{counterMB.id}" id="outputTxt"/>
<p:commandLink
action="#{counterMB.incrementCounter()}"
value="Increment"
update="outputTxt"
/>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</h:form>
и bean-компонент:
@Named
@Scope("view")
public class CounterMB extends GenericMB implements Serializable{
private static final long serialVersionUID = 1L;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
System.out.println("Setting the id with:"+id);
this.id = id;
}
public void incrementCounter() {
id = id +1;
// do something with id
System.out.println("Id is="+Integer.toString(id));
}
}
и некоторые журналы:
http://localhost:8080/myapp/counter.xhtml?id=4
(LifecycleListener.java:22) - START PHASE RESTORE_VIEW 1
(LifecycleListener.java:26) - END PHASE RESTORE_VIEW 1
(LifecycleListener.java:22) - START PHASE APPLY_REQUEST_VALUES 2
(LifecycleListener.java:26) - END PHASE APPLY_REQUEST_VALUES 2
(LifecycleListener.java:22) - START PHASE PROCESS_VALIDATIONS 3
(LifecycleListener.java:26) - END PHASE PROCESS_VALIDATIONS 3
(LifecycleListener.java:22) - START PHASE UPDATE_MODEL_VALUES 4
2019-10-24T13:43:52.573+0000|Info: Setting the id with:4
(LifecycleListener.java:26) - END PHASE UPDATE_MODEL_VALUES 4
(LifecycleListener.java:22) - START PHASE INVOKE_APPLICATION 5
(LifecycleListener.java:26) - END PHASE INVOKE_APPLICATION 5
(LifecycleListener.java:22) - START PHASE RENDER_RESPONSE 6
(LifecycleListener.java:26) - END PHASE RENDER_RESPONSE 6
//click on increment 1st time
(LifecycleListener.java:22) - START PHASE RESTORE_VIEW 1
(LifecycleListener.java:26) - END PHASE RESTORE_VIEW 1
(LifecycleListener.java:22) - START PHASE APPLY_REQUEST_VALUES 2
(LifecycleListener.java:26) - END PHASE APPLY_REQUEST_VALUES 2
(LifecycleListener.java:22) - START PHASE PROCESS_VALIDATIONS 3
(LifecycleListener.java:26) - END PHASE PROCESS_VALIDATIONS 3
(LifecycleListener.java:22) - START PHASE UPDATE_MODEL_VALUES 4
2019-10-24T13:44:07.013+0000|Info: Setting the id with:4
(LifecycleListener.java:26) - END PHASE UPDATE_MODEL_VALUES 4
(LifecycleListener.java:22) - START PHASE INVOKE_APPLICATION 5
2019-10-24T13:44:07.014+0000|Info: Id is=5
(LifecycleListener.java:26) - END PHASE INVOKE_APPLICATION 5
(LifecycleListener.java:22) - START PHASE RENDER_RESPONSE 6
(LifecycleListener.java:26) - END PHASE RENDER_RESPONSE 6
// click on icrement the second time
(LifecycleListener.java:22) - START PHASE RESTORE_VIEW 1
(LifecycleListener.java:26) - END PHASE RESTORE_VIEW 1
(LifecycleListener.java:22) - START PHASE APPLY_REQUEST_VALUES 2
(LifecycleListener.java:26) - END PHASE APPLY_REQUEST_VALUES 2
(LifecycleListener.java:22) - START PHASE PROCESS_VALIDATIONS 3
LifecycleListener.java:26) - END PHASE PROCESS_VALIDATIONS 3
(LifecycleListener.java:22) - START PHASE UPDATE_MODEL_VALUES 4
2019-10-24T13:44:12.548+0000|Info: Setting the id with:null
(LifecycleListener.java:26) - END PHASE UPDATE_MODEL_VALUES 4
(LifecycleListener.java:22) - START PHASE INVOKE_APPLICATION 5
2019-10-24T13:44:12.549+0000|Warning: #{counterMB.incrementCounter()}: java.lang.NullPointerException
javax.faces.FacesException: #{counterMB.incrementCounter()}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.getNavigationOutcome(ActionListenerImpl.java:96)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:71)
at org.springframework.faces.webflow.FlowActionListener.processAction(FlowActionListener.java:71)
at org.springframework.faces.model.SelectionTrackingActionListener.processAction(SelectionTrackingActionListener.java:64)
at org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:54)
at javax.faces.component.UICommand.broadcast(UICommand.java:222)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:847)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1395)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:58)
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.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1628)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:339)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:209)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:251)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:209)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:124)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:155)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:251)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:209)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:251)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:209)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:755)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:575)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:76)
at com.sun.faces.application.ActionListenerImpl.getNavigationOutcome(ActionListenerImpl.java:82)
... 82 more
Caused by: java.lang.NullPointerException
at com.myapp.jsf.user.CounterMB.incrementCounter(CounterMB.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.el.ELUtil.invokeMethod(ELUtil.java:263)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:494)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:215)
at com.sun.el.parser.AstValue.invoke(AstValue.java:285)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:65)
at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:66)
... 83 more
2019-10-24T13:44:12.551+0000|Info: INFO [http-thread-pool::http-listener-1(2)] (LifecycleListener.java:26) - END PHASE INVOKE_APPLICATION 5
Обходной путь должен быть выполнен = "# {not FaceContext.postback} "on f: viewParam, но я не думаю, что это правильное поведение.
Обновление:
В Kukestje sugestion я попробовал с простым приложением JSF, с @ViewScoped, и оно работает как положено. С этим я продолжу добавлять простые выражения и пружину и .... всечто у меня есть в текущем приложении, чтобы попытаться смоделировать текущую ситуацию.
Обновление:
Причина, по которой он работал с простым jsf, заключалась в том, что h: commandLink не выдавал ajax-запрос. Я смог воспроизвести его с этими файлами:
`
<!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:p="http://primefaces.org/ui">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</f:facet>
<title> Simulator - Counter rest</title>
</h:head>
<h:body>
<f:metadata>
<f:viewParam name="id" value="#{counterMB.id}"/>
</f:metadata>
<h:form id="myForm">
Id is <h:outputText value="#{counterMB.id}" id="outputTxt"/>
<h:commandButton value="Increment"update="outputTxt">
<f:ajax listener="#{counterMB.incrementCounter()}" execute="myForm" render="outputTxt"/>
</h:commandButton>
</h:form>
</h:body>
</html>
`
и с этим бобом
import java.io.Serializable;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
@Named
@ViewScoped
public class CounterMB implements Serializable{
private static final long serialVersionUID = 1L;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
System.out.println("Setting the id with:"+id);
this.id = id;
}
public void incrementCounter() {
id = id +1;
System.out.println("Id is="+Integer.toString(id));
}
}