重定向后不包含jquery(primefaces) [英] jquery(primefaces) is not included after redirect

查看:79
本文介绍了重定向后不包含jquery(primefaces)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是primeface的新手,并尝试使用jsf实现一个简单的Web应用程序.在此应用程序中,我有一个login.xhtml,用户可以在其中输入名称和密码.如果登录成功,我的LoginBean类会将他重定向到文件夹basicSites中的另一个页面,称为index.xhtml. 在login.xhtml上一切正常时,在index.xhtml上发生错误.重定向到此站点后,我仅看到一个白色站点,并且浏览器控制台告诉我存在参考错误,因为未定义jQuery.我研究了许多其他有类似问题的文章,但是我的问题仍然没有解决.

I'm new to primefaces and try to realize a simple web-app with jsf. In this app I have a login.xhtml where a user can enter a name and his password. If login is successfull, my LoginBean class redirects him to another page called index.xhtml in the folder basicSites. While on login.xhtml everything works fine, on index.xhtml occured an error. After the redirect to this site i only see a white site, and the browser console told me that there was a reference error, because jQuery is not defined. I researched through many other articles that have had a similar problem, but my problem isnt still solved.

这里有一些代码片段供您更好地理解.

Here are some code snippets for better understanding.

login.xhtml

login.xhtml

<h:head>
    <title>Zugangsverwaltung | Login</title>
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/default.css" />
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/syntax.css" />
    <script type="text/javascript" href="#{request.contextPath}/scripts.js"/>
</h:head>

<h:body>
    <script type="text/javascript"> 
        jQuery(document).ready(function () {
            jQuery('#logoutLink').fadeOut();
        });
        function handleLoginRequest(xhr, status, args) { 
            if(args.validationFailed || !args.loggedIn) {  
                jQuery('#dialog').effect("shake", { times:3 }, 100);  
            } else {  
                dlg.hide();  
                jQuery('#loginLink').fadeOut(0); 
                jQuery('#logoutLink').fadeIn();
            }  

        } </script>

LoginBean.java

LoginBean.java

public void login(ActionEvent actionEvent) {
    RequestContext context = RequestContext.getCurrentInstance();
    FacesMessage msg = null;
    boolean loggedIn = false;

    FacesContext ctx = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();

    try {
        request.login(username, password);
        loggedIn = true;
        msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Willkommen", username);
        FacesContext.getCurrentInstance().addMessage("global", msg);
    } catch (ServletException e) {
        loggedIn = false;
        msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login fehlgeschlagen!", "Invalid credentials");
        FacesContext.getCurrentInstance().addMessage("local", msg);
    }

    try {
        if (loggedIn) {
            ExternalContext ectx = ctx.getExternalContext();
            ectx.redirect(request.getContextPath() + "/basicSites/index.xhtml");
        }
    } catch (Exception e) {
        System.out.println("LoginBean - login: " + e.getMessage());
    }

至少出现错误的index.xhtml:

And at least the index.xhtml, where the error occurs:

<h:head>
    <title>Zugriffsverwaltung | Backend</title>
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/default.css" />
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/syntax.css" />
    <script type="text/javascript" href="#{request.contextPath}/scripts.js" />
</h:head>

<h:body>
    <script type="text/javascript"> 
        jQuery(document).ready(function () { <!-- Here: JQuery is not definded --> 
            jQuery('#logoutLink').fadeOut();
        });</script>

    <p:layout fullPage="true" >
        <p:layoutUnit id="center" position="center"> <!-- ... -->

我希望任何人都知道现在该怎么做;)对于帮助我解决问题的每一个提示,我深表感谢.

I hope anyone have an idea what to do now ;) I'm appreciate for every hint that helps me to solve the problem.

先谢谢您了:D

推荐答案

尝试将xmlns:p="http://primefaces.org/ui"添加到您的页面

如果上述方法无济于事:

If the above wont help :

您还可以添加

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />

对于您的<h:head>,其中应包括与primefacs捆绑在一起的jQuery

To your <h:head> , that should include the jQuery bundled with primefacs

这篇关于重定向后不包含jquery(primefaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆