无论我做什么,我都会得到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中的任何操作,因为没有任何反应。
答案 0 :(得分:6)
我解决了这个问题:
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
在某些地方,我看到它就像这样javax.faces.PARTIAL_STATE_SAVING
,但它不起作用。