不断收到 javax.faces.application.ViewExpiredException: viewId with jsf 2 [重复]
Posted
技术标签:
【中文标题】不断收到 javax.faces.application.ViewExpiredException: viewId with jsf 2 [重复]【英文标题】:keep getting javax.faces.application.ViewExpiredException: viewId with jsf 2 [duplicate] 【发布时间】:2013-10-23 07:22:45 【问题描述】:无论我做什么,我都会得到 javax.faces.application.ViewExpiredException: viewId。我知道如何处理异常(如果出现错误,请再次重定向到主页),问题是我从 commandButton 调用的任何操作都没有执行。
基本上,我有一个带有操作的 commandButton 的简单视图。我按下它并收到 viewExpiredException,或者如果我处理错误,我没有收到错误消息,但我的 commandButton 仍然不起作用。
我尝试添加这个:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>client</param-value>
</context-param>
但它不起作用。不知道怎么回事。。
这是我的看法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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"
lang="es">
<div class="container">
<h:form id="principal">
<h1>Sistema de carga de publicaciones</h1>
<h:outputText value="Ingrese el año por el que desea buscar publicaciones" />
<h:inputText
id="year"
value="#publicaciones.año" />
<h:commandButton
style="display:block"
id="boton-codigo-facultad"
value="Buscar"
type="submit">
</h:commandButton>
<h:panelGroup id="output">
<h:outputText
style="display:block"
value="Total publicaciones en la DB:#publicaciones.totalPublicacionesDB" />
<h:outputText
style="display:block"
value="Publicaciones obtenidas desde el WS:" />
<h:outputText
style="display:block"
value="Publicaciones nuevas:" />
</h:panelGroup>
<h:commandButton
style="display:block"
id="insertar"
value="Cargar publicacion"
action="#insert.insertPublicacionDB">
</h:commandButton>
</h:form>
</div>
</html>
支持 bean:
@ManagedBean(name="insert")
@ViewScoped
public class comparaDatosBean implements Serializable
private static final long serialVersionUID = 1L;
Map<String, Object> parametros=new HashMap<String, Object>();
Map<String, Object> params2=new HashMap<String, Object>();
@PostConstruct
public void init()
System.out.println("pase por aqui!!");
public void insertPublicacionDB() throws SQLException
ApplicationContext applicationContext = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
ControllerPublicacion controlador= (ControllerPublicacion) applicationContext.getBean("controllerPublicaciones");
parametros.put("ut","234567876545555");
parametros.put("py", 2013);
params2.put("ut", "234567876545555");
params2.put("bp","asjñldfkjsñd");
params2.put("la", "Español");
params2.put("ti","Publicacion de prueba");
params2.put("py",2013);
params2.put("sn", "234wf");
params2.put("di", "asdfsf");
params2.put("j9", "");
params2.put("dt", "");
params2.put("ga", "");
params2.put("dt", "");
params2.put("so", "");
params2.put("fx", "");
params2.put("ep", "");
params2.put("issue", "");
params2.put("parte","");
params2.put("vl", "");
params2.put("rp", "");
params2.put("vinculada", null);
params2.put("ji", "");
params2.put("pd","");
params2.put("pg", "");
params2.put("pa","");
params2.put("ab","");
params2.put("pi", "");
params2.put("numero_articulo", null);
params2.put("tipo_carga_revista",null);
params2.put("id",null );
params2.put("su", "");
System.out.println(params2.get("la"));
if(controlador.existeEnDB(parametros)>0)
System.out.println("La publicacion ya existe en la Base de Datos");
else
controlador.insertPublicacion(params2);
System.out.println("la publicacion ha sido añadida");
public Map<String, Object> getParametros()
return parametros;
public void setParametros(Map<String, Object> parametros)
this.parametros = parametros;
public Map<String, Object> getParams2()
return params2;
public void setParams2(Map<String, Object> params2)
this.params2 = params2;
错误信息:
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/test] threw exception [viewId:/main.jsf - No se pudo restablecer la vista /main.jsf.] with root cause
javax.faces.application.ViewExpiredException: viewId:/main.jsf - No se pudo restablecer la vista /main.jsf.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:212)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
我需要知道为什么会发生这种情况,而不是如何处理异常。我无法从 commandButton 调用任何操作,因为没有任何反应。
【问题讨论】:
你的第一个commandButton
没有action
属性,所以这个肯定不会调用你的backing bean。另一个应该。实际上它在我的本地工作示例中确实如此......您有任何错误消息(浏览器或 java 控制台)吗?
我知道我的第一个 commandButton 没有动作.. 就在那里哈哈...我现在将发布我的完整错误消息。
【参考方案1】:
我用这个解决了:
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
在某些地方我看到它像这样javax.faces.PARTIAL_STATE_SAVING
但它不起作用。
【讨论】:
在客户端保存状态是否有任何安全隐患? @jrobertsz66 如果您可以理解包含在服务器上维护的视图状态的 html 中非常长的散列和编码(可能加密)字符串,理论上您可以修改它们并将其他数据发送到服务器。祝你好运:)以上是关于不断收到 javax.faces.application.ViewExpiredException: viewId with jsf 2 [重复]的主要内容,如果未能解决你的问题,请参考以下文章