重定向后不包含 jquery(primefaces)

2023-12-26

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

以下是一些代码片段,以便更好地理解。

登录.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

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:

<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"> <!-- ... -->

我希望任何人都知道现在该怎么做;)我很感激每一个帮助我解决问题的提示。

先谢谢了


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

如果上述内容没有帮助:

您还可以添加

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

To your <h:head>,应该包括与 primefacs 捆绑在一起的 jQuery

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

重定向后不包含 jquery(primefaces) 的相关文章

随机推荐