JSF1.2到JSF2.1迁移:使用a4j:ajax / f:ajax在第一个页面引起:“ReferenceError: RichFaces / jsf没有定义”

时间:2022-08-05 20:10:49

I am migrating JSF1.2 application to JSF 2.1. It has a Login page, which uses facelets template. And the template page has h:head tag. Login page has a tag h:selectBooleanCheckbox inside ui:composition/ui:define/h:form/a4j:outputPanel/h:panelGrid/h:panelGroup tags.

我正在将JSF1.2应用程序迁移到JSF 2.1。它有一个登录页面,使用facelets模板。模板页有h:head标签。登录页面有一个标签h:selectBooleanCheckbox inside ui:composition/ui:define/h:form/a4j:outputPanel/h:panelGrid/h:panelGroup标签。

<h:selectBooleanCheckbox value="#{bean.alogin}" >
  <a4j:ajax event="click" execute="@form" render="loginPanel" />    
</h:selectBooleanCheckbox>

On click of check box, I am getting 'ReferenceError: RichFaces is not defined' in Browser Error Console.

单击复选框,我将得到“ReferenceError: RichFaces没有定义”在浏览器错误控制台。

The issue is same even with using f:ajax tag, and having

这个问题甚至与使用f:ajax标记和拥有相同。

<h:outputScript name="jsf.js" library="javax.faces" target="head"/>

in template page/login page.

在模板页面/登录页面。

This issue (of not finding/loading js libs) is coming only on the First load of Login page. That means if I login to my application and logout and then use the above check box, there is no issue.

这个问题(没有找到/加载js libs)只出现在登录页面的第一个负载上。这意味着如果我登录到我的应用程序并注销,然后使用上面的复选框,就没有问题了。

Please direct with any pointers and that will be very helpful. Thanks very much in advance.

请直接使用任何指针,这将是非常有用的。非常感谢。

And following is the html generated in head tag:

以下是在head标签中生成的html:

<script src="/myapp/javax.faces.resource/jsf.js.faces?ln=javax.faces" type="text/javascript">&lt;!--
//--&gt;</script>

I have the two *.faces mappings in web.xml. One is CustomFilter (implementing javax.servlet.Filter) and the other is CustomServlet (extending org.apache.myfaces.webapp.MyFacesServlet).

我有两个*。面临在web . xml映射。一个是CustomFilter(实现javax.servlet.Filter),另一个是CustomServlet(扩展org.apache.myfaces.webapp.MyFacesServlet)。

1 个解决方案

#1


2  

ReferenceError: RichFaces / jsf is not defined

ReferenceError: RichFaces / jsf没有定义。

This is a JavaScript error. This means that neither var RichFaces = ...; nor var jsf = ...; is anywhere been defined in JavaScript context. This in turn means that auto-including the JSF and RichFaces-provided JavaScript files jsf.js and richfaces.js has failed. This can in turn be caused by not having used the <h:head> component to declare the HTML head which is a mandatory hook for JSF to auto-include JavaScript files.

这是一个JavaScript错误。这意味着var RichFaces =…;也不是var jsf =…;在JavaScript上下文中定义任何地方。这又意味着自动包括JSF和richfacet—提供了JavaScript文件JSF。js和richfaces。js已经失败了。这可能是由于没有使用 组件声明HTML head,这是JSF自动包含JavaScript文件的强制钩子。

Apparently you forgot to replace the

很明显你忘了换了。

<head>
    ...
</head>

in your templates by

在你的模板

<h:head>
    ...
</h:head>

Fix it accordingly.

相应的修复它。

Using <h:outputScript name="jsf.js" library="javax.faces" target="head"/> only fixes the JSF part of the error, not the RichFaces part and is actually a workaround, not a solution.

使用< h:outputScript名称= " jsf。js "库= " javax。faces" target="head"/>只修复了错误的JSF部分,而不是RichFaces部分,实际上是一个解决方案,而不是解决方案。


Update: as per your question update, you confirmed that you've mapped sort of a login Filter on the exact URL pattern of those resources (at least, the filter name "session filter" in combination with the problem symptoms described so far indicates that you're blocking requests whereby the user is not logged-in). JSF resources are served by *.faces URL pattern through the FacesServlet as well and thus they are checked by that filter as well (if you have studied the generated <script src> URL closely, you'd have realized that).

更新:根据你的问题更新,你确认你映射的一个登录过滤这些资源的URL模式(至少,过滤器的名字“会话过滤器”结合到目前为止所描述的问题症状表明你阻塞请求,用户没有登录)。JSF资源由*提供。通过FacesServlet来面对URL模式,因此它们也会被该过滤器检查(如果您仔细研究了生成的 <脚本src> URL,您就会意识到)。

You likely need to alter your Filter to skip the logged-in check on those resources so that those resources won't be redirected to the login page as well. You could do that by checking if the request URI does not concern the ResourceHandeler.RESOURCE_IDENTIFIER URLs.

您可能需要更改过滤器,以跳过对这些资源的登录检查,以便这些资源不会被重定向到登录页面。您可以通过检查请求URI是否与ResourceHandeler无关。RESOURCE_IDENTIFIER url。

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    if (req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
        chain.doFilter(request, response); // Skip JSF resources (CSS/JS/Images/etc)
        return;
    }

    // ... Continue your login check here.
}

#1


2  

ReferenceError: RichFaces / jsf is not defined

ReferenceError: RichFaces / jsf没有定义。

This is a JavaScript error. This means that neither var RichFaces = ...; nor var jsf = ...; is anywhere been defined in JavaScript context. This in turn means that auto-including the JSF and RichFaces-provided JavaScript files jsf.js and richfaces.js has failed. This can in turn be caused by not having used the <h:head> component to declare the HTML head which is a mandatory hook for JSF to auto-include JavaScript files.

这是一个JavaScript错误。这意味着var RichFaces =…;也不是var jsf =…;在JavaScript上下文中定义任何地方。这又意味着自动包括JSF和richfacet—提供了JavaScript文件JSF。js和richfaces。js已经失败了。这可能是由于没有使用 组件声明HTML head,这是JSF自动包含JavaScript文件的强制钩子。

Apparently you forgot to replace the

很明显你忘了换了。

<head>
    ...
</head>

in your templates by

在你的模板

<h:head>
    ...
</h:head>

Fix it accordingly.

相应的修复它。

Using <h:outputScript name="jsf.js" library="javax.faces" target="head"/> only fixes the JSF part of the error, not the RichFaces part and is actually a workaround, not a solution.

使用< h:outputScript名称= " jsf。js "库= " javax。faces" target="head"/>只修复了错误的JSF部分,而不是RichFaces部分,实际上是一个解决方案,而不是解决方案。


Update: as per your question update, you confirmed that you've mapped sort of a login Filter on the exact URL pattern of those resources (at least, the filter name "session filter" in combination with the problem symptoms described so far indicates that you're blocking requests whereby the user is not logged-in). JSF resources are served by *.faces URL pattern through the FacesServlet as well and thus they are checked by that filter as well (if you have studied the generated <script src> URL closely, you'd have realized that).

更新:根据你的问题更新,你确认你映射的一个登录过滤这些资源的URL模式(至少,过滤器的名字“会话过滤器”结合到目前为止所描述的问题症状表明你阻塞请求,用户没有登录)。JSF资源由*提供。通过FacesServlet来面对URL模式,因此它们也会被该过滤器检查(如果您仔细研究了生成的 <脚本src> URL,您就会意识到)。

You likely need to alter your Filter to skip the logged-in check on those resources so that those resources won't be redirected to the login page as well. You could do that by checking if the request URI does not concern the ResourceHandeler.RESOURCE_IDENTIFIER URLs.

您可能需要更改过滤器,以跳过对这些资源的登录检查,以便这些资源不会被重定向到登录页面。您可以通过检查请求URI是否与ResourceHandeler无关。RESOURCE_IDENTIFIER url。

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    if (req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
        chain.doFilter(request, response); // Skip JSF resources (CSS/JS/Images/etc)
        return;
    }

    // ... Continue your login check here.
}