【发布时间】:2012-02-03 16:50:35
【问题描述】:
我已尝试调查此问题,但根本没有找到解决方案。我使用带有分页的 primefaces 数据表。正如 Ed Burns 在他的博客中所建议的那样,我为 viewexpiredexception 错误编写了异常处理程序,但是当与 ajax 提交(例如数据表页面导航)结合使用时,不会处理 vee 上的页面重定向。我在这里使用了 BalusC JSF Status bar / connection status information 建议的解决方案,但 chrome 说它缺少 jsf.ajax.* javascript 命名空间。该页面在tomcat 7.0.22上运行,启动时没有错误/警告,后端基于spring和mybatis。这是web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Discontinui</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<session-config>
<session-timeout>2</session-timeout>
</session-config>
</web-app>
这里是 faces-config.xml
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<factory>
<exception-handler-factory>it.dipvvf.vi.app.common.ViewExpiredExceptionExceptionHandlerFactory</exception-handler-factory>
</factory>
</faces-config>
这里是 index.xhtml 页面:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Prova</title>
<script type="text/javascript">
var statusUpdate = function statusUpdate(data) {
var statusArea = document.getElementById("statusArea");
var text = statusArea.value;
text = text + "Name: "+data.source.id;
if (data.type === "event") {
text = text +" Event: "+data.name+"\n";
} else { // otherwise, it's an error
text = text + " Error: "+data.name+"\n";
}
statusArea.value = text;
};
// Setup the statusUpdate function to hear all events on the page
alert("0");
jsf.ajax.addOnEvent(statusUpdate);
alert("1");
jsf.ajax.addOnError(statusUpdate);
alert("2");
</script>
</h:head>
<h:body>
<h:form>
Selezionare il tipo di accesso:<br />
<p:selectOneMenu id="somAccessMode" value="#{accessMode.mode}">
<f:selectItem itemValue="#{accessMode.ufficioPersonale}"
itemLabel="Ufficio Personale" />
<f:selectItem itemValue="#{accessMode.capoTurno}"
itemLabel="Capo Turno" />
</p:selectOneMenu>
<br />
<p:commandButton id="bEnter" value="Entra"
action="#{accessMode.onEntraClick}" update="growl" />
<br />
<p:dataTable var="nominativo" value="#{accessMode.elencoNominativi}" paginator="true" rows="1"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
Cognome
</f:facet>
<h:outputText value="#{nominativo.cognome}" />
</p:column>
<p:column>
<f:facet name="header">
Nome
</f:facet>
<h:outputText value="#{nominativo.nome}" />
</p:column>
<p:column>
<f:facet name="header">
Data Iscrizione
</f:facet>
<h:outputText value="#{nominativo.iscrizione}">
<f:convertDateTime pattern="dd-MM-yyyy" />
</h:outputText>
</p:column>
</p:dataTable>
<hr />
<br />
<!-- <p:messages showDetail="true" autoUpdate="true"/> -->
<p:growl id="growl" showDetail="true" sticky="true" />
<h3>Status:</h3>
<textarea id="statusArea" cols="40" rows="10" readonly="readonly" />
</h:form>
</h:body>
</html>
我已经为测试提供了超出需要的内容。 alert("1") 和 "2" 不显示,并且 jsf.ajax.add... 在浏览器中引发错误。如果我在 chrome 中查看并生成页面,我看不到任何包含捆绑到 mojarra 包中的 jsf.js。缺陷在哪里?
感谢任何人,对不起!
【问题讨论】:
-
我看到 jsf.js 存在于 jsf-impl-2.1.6.jar 中。只是为了确认您是否可以在表单中包含此标记
并查看页面源中是否包含 jsf.js。 -
是的,Ravi...在表单中添加一个 h: 元素会将 jsf.js 添加到脚本包含列表中。我认为仅仅添加命名空间、h:head 和 h:form 元素就可以解决所有需要的包含问题。我自己找到了另一个解决方案,只需使用 faces-redirect=true 参数重定向到过期信息页面。我现在正在尝试将原始解决方案与 jsf.ajax javascipt 函数一起使用。我会告诉你!无论如何感谢您的回复!
-
哎呀...函数确实存在,但在我的脚本之后声明了!
-
如果你在 中使用
-
嗨@Ravi 我将带有普通脚本标签的脚本包含在 h:head 部分中(如您在源代码中所见)。但问题是,当我按照您的建议添加 h:commandLink 时,jsf.js 脚本将包含在 body 标记中(我看到生成的 html),就在声明 h:commandLink 的同一位置,而不是在 head 部分中。所以脚本是在实际使用后声明的,而 brwoser 将找不到它。需要将我的脚本移到页面底部并使用 h:outputScript 标签...谢谢您的回复!
标签: ajax jsf primefaces mojarra viewexpiredexception