java - JSF h :commandlink not working after updating version

标签 java jsp jsf-2

我正在致力于将应用程序从 websphere 迁移到 tomcat,这在很大程度上是完全成功的。之前的应用程序在 Java EE 5 上运行,我将其更新为 Java 7。在此过程中,我将 JSTL 更新为 1.2,将 myfaces 更新为 2.0,以及其他一些内容。这是我当前的 jar 库:

Library of Jars

除了 h:commandlink 之外,应用程序的所有内容都有效。我相信这与更新 jar 和 java 版本有关。我可以访问所有其他页面,只是导航按钮不起作用。这是他们的 jsp:

<%-- tpl:metadata --%>
<%-- jsf:pagecode language="java" location="/src/pagecode/menu/Main.java" --%><%-- /jsf:pagecode --%>
<%-- /tpl:metadata --%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<link rel="stylesheet" type="text/css" media="screen"
href="../theme/menu.css">
<link rel="stylesheet" type="text/css" href="../theme/stylesheet.css"
title="Style">
<hx:viewFragment id="viewFragmentMain"><hx:scriptCollector id="scriptCollector1">

    <% String Page = (session.getAttribute("mainPage") == null) ? "1" : (String)session.getAttribute("mainPage"); %>

    <h:form id="formMenu" styleClass="form">
        <ul id="tabmenu">
            <li<%= (Page.compareTo("1") == 0) ? " class=active" : ""%>><h:commandLink id="link1" action="#{pc_Main.doLink1Action}"><h:outputText id="textMenu1" styleClass="outputText" value="Page 1"></h:outputText></h:commandLink></li>
            <li<%= (Page.compareTo("2") == 0) ? " class=active" : ""%>><h:commandLink id="link2" action="#{pc_Main.doLink2Action}"><h:outputText id="textMenu2" styleClass="outputText" value="Page 2"></h:outputText></h:commandLink></li>
            <li<%= (Page.compareTo("3") == 0) ? " class=active" : ""%>><h:commandLink id="link3" action="#{pc_Main.doLink3Action}"><h:outputText id="textMenu3" styleClass="outputText" value="Page 3"></h:outputText></h:commandLink></li>
            <li<%= (Page.compareTo("5") == 0) ? " class=active" : ""%>><h:commandLink id="link5" action="#{pc_Main.doLink5Action}"><h:outputText id="textMenu5" styleClass="outputText" value="Page 5"></h:outputText></h:commandLink></li>
            <% if (request.isUserInRole("giftAdmin") | request.isUserInRole("giftAdminBackup") | request.isUserInRole("merchAdmin") | request.isUserInRole("merchAdminBackup")){ %>
            <li <%= (Page.compareTo("4") == 0) ? " class=active" : ""%>><h:commandLink
                id="link4" action="#{pc_Main.doLink4Action}">
                <h:outputText id="textMenu4" styleClass="outputText"
                    value="Page 4"></h:outputText>
            </h:commandLink></li>
            <li><a href="<%= request.getContextPath() %>/forms/Help.pdf" target="_blank">Help</a></li>
            <% } %>
        </ul>
    </h:form>
</hx:scriptCollector>

当单击链接时,应该调用此类中的相应方法。然而,它实际上从未进入这个类别。它应该在索引中进行调用,然后根据导航规则返回正确的 View ,但它永远不会进入正确的方法。

import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
import javax.servlet.http.HttpSession;

import com.accounting.credit.ControlBean;
import com.accounting.credit.CreditAction;
import com.accounting.credit.CreditRequest;

import jxl.common.Logger;
import pagecode.PageCodeBase;

public class Main extends PageCodeBase {

    private final static Logger LOG = Logger.getLogger(Main.class);

    protected HtmlCommandLink link2;
    protected HtmlOutputText textMenu1;
    protected HtmlForm formMenu;
    protected HtmlCommandLink link3;
    protected HtmlCommandLink link4;
    protected HtmlCommandLink link1;
    protected HtmlOutputText textMenu2;
    protected HtmlOutputText textMenu3;
    protected HtmlOutputText textMenu4;
    protected CreditAction action;
    protected CreditRequest req;
    protected ControlBean control;
    protected HtmlOutputText textMenu5;
    protected HtmlCommandLink link5;

    protected HtmlCommandLink getLink2() {
        if (link2 == null) {
            link2 = (HtmlCommandLink) findComponentInRoot("link2");
        }
        return link2;
    }

    protected HtmlOutputText getTextMenu1() {
        if (textMenu1 == null) {
            textMenu1 = (HtmlOutputText) findComponentInRoot("textMenu1");
        }
        return textMenu1;
    }

    protected HtmlForm getFormMenu() {
        if (formMenu == null) {
            formMenu = (HtmlForm) findComponentInRoot("formMenu");
        }
        return formMenu;
    }

    protected HtmlCommandLink getLink3() {
        if (link3 == null) {
            link3 = (HtmlCommandLink) findComponentInRoot("link3");
        }
        return link3;
    }

    protected HtmlCommandLink getLink4() {
        if (link4 == null) {
            link4 = (HtmlCommandLink) findComponentInRoot("link4");
        }
        return link4;
    }

    protected HtmlCommandLink getLink1() {
        if (link1 == null) {
            link1 = (HtmlCommandLink) findComponentInRoot("link1");
        }
        return link1;
    }

    public String doLink1Action() {
        // Type Java code that runs when the component is clicked
        LOG.info("In doLink1Action"); 
        HttpSession session = (HttpSession)getFacesContext().getExternalContext().getSession(true);
        session.setAttribute("edit", "False");
        getReq().clear();
        getAction().clear();
        return "page1";
    }

    public String doLink2Action() {
        // Type Java code that runs when the component is clicked
        LOG.info("In doLink2Action");
        HttpSession session = (HttpSession)getFacesContext().getExternalContext().getSession(true);
        session.setAttribute("edit", "False");
        getReq().clear();
        getAction().clear();
        return "page2";
    }

    public String doLink3Action() {
        // Type Java code that runs when the component is clicked
        LOG.info("In doLink3Action");
        HttpSession session = (HttpSession)getFacesContext().getExternalContext().getSession(true);
        session.setAttribute("edit", "False");
        getReq().clear();
        getAction().clear();
        return "pag3";
    }

    public String doLink4Action() {
        // Type Java code that runs when the component is clicked
        LOG.info("In doLink4Action");
        HttpSession session = (HttpSession)getFacesContext().getExternalContext().getSession(true);
        session.setAttribute("edit", "False");
        getReq().clear();
        getAction().clear();
        return "page4";
    }

    protected HtmlOutputText getTextMenu2() {
        if (textMenu2 == null) {
            textMenu2 = (HtmlOutputText) findComponentInRoot("textMenu2");
        }
        return textMenu2;
    }

    protected HtmlOutputText getTextMenu3() {
        if (textMenu3 == null) {
            textMenu3 = (HtmlOutputText) findComponentInRoot("textMenu3");
        }
        return textMenu3;
    }

    protected HtmlOutputText getTextMenu4() {
        if (textMenu4 == null) {
            textMenu4 = (HtmlOutputText) findComponentInRoot("textMenu4");
        }
        return textMenu4;
    }

    /** 
     * @managed-bean true
     */
    protected CreditAction getAction() {
        if (action == null) {
            action = (CreditAction) getFacesContext().getApplication()
                .createValueBinding("#{action}")
                .getValue(getFacesContext());
        }
        return action;
    }

    /** 
     * @managed-bean true
     */
    protected void setAction(CreditAction action) {
        this.action = action;
    }

    /** 
     * @managed-bean true
     */
    protected CreditRequest getReq() {
        if (req == null) {
            req = (CreditRequest) getFacesContext().getApplication()
                .createValueBinding("#{req}").getValue(getFacesContext());
        }
        return req;
    }

    /** 
     * @managed-bean true
     */
    protected void setReq(CreditRequest req) {
        this.req = req;
    }

    /** 
     * @managed-bean true
     */
    protected ControlBean getControl() {
        if (control == null) {
            control = (ControlBean) getFacesContext().getApplication()
                .createValueBinding("#{control}").getValue(
                        getFacesContext());
        }
        return control;
    }

    /** 
     * @managed-bean true
     */
    protected void setControl(ControlBean control) {
        this.control = control;
    }

    protected HtmlOutputText getTextMenu5() {
        if (textMenu5 == null) {
            textMenu5 = (HtmlOutputText) findComponentInRoot("textMenu5");
        }
        return textMenu5;
    }

    protected HtmlCommandLink getLink5() {
        if (link5 == null) {
            link5 = (HtmlCommandLink) findComponentInRoot("link5");
        }
        return link5;
    }

    public String doLink5Action() {
        // Type Java code that runs when the component is clicked
        return "page5";
    }

}

onclick 与之前的不同,这让我相信它与版本有关,但我没有找到任何与 onclick 发生变化的原因相关的信息。

之前的 onclick 是:

<a id="viewFragmentMain:formMenu:link2" href="#" onclick="document.forms['viewFragmentMain:formMenu']['__LINK_TARGET__'].disabled=false;document.forms['viewFragmentMain:formMenu']['__LINK_TARGET__'].value='viewFragmentMain:formMenu:link2'; document.forms['viewFragmentMain:formMenu'].submit();document.forms['viewFragmentMain:formMenu']['__LINK_TARGET__'].disabled=true; return false;"><span id="viewFragmentMain:formMenu:textMenu2" class="outputText">My Requests</span></a>

新的 onclick 是:

<a href="#" onclick="return myfaces.oam.submitForm('viewFragmentMain:formMenu','viewFragmentMain:formMenu:link2');" id="viewFragmentMain:formMenu:link2"><span id="viewFragmentMain:formMenu:textMenu2" class="outputText">My Requests</span></a>

简单地说,我想我要问的是如何使新链接看起来像更新版本的旧链接?

最佳答案

WebSphere 是什么版本? 通常,您不得将 JSF 实现 jar 捆绑到您的应用程序中,除非您明确想要覆盖 WAS 中捆绑的 JSF 实现 jar。如果是这样,请检查文档 here

关于java - JSF h :commandlink not working after updating version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51545176/

相关文章:

java - 从 JSP 调用 servlet

java - 如何在JAVA中创建每个维度具有不同类型数据的二维数组/数组列表?

java - 在不使用 java.util.Properties 的情况下读取文件并获取 key=value

java - 如何从jsp编写.properties文件

java - 绑定(bind) Set 集合中的对象

java - 将 docx 文件转换为 PDF 而不丢失格式?

javascript - 如何将字符串从 primefaces 传递给 javascript 函数?

java - 如何在枚举中不存在的 selectOne 中显示值?

java - mongodb 驱动程序 - 如何使用 log4j 隐藏调试日志记录?

java - NamedParameterJdbcTemplate 批量大小