Search code examples
javajspjsf-2

JSF h:commandlink not working after updating version


I am working on migrating an application from websphere to tomcat which was been for the most part completely successful. The previous application was running on Java EE 5 and I updated it to Java 7. In the process I updated JSTL to 1.2, myfaces to 2.0, and a few other things. This is my current lib of jars:

Library of Jars

Everything about the application works except for the h:commandlink. I believe this has to do with updating the jars and java version. I have access to all other pages it's just the nav buttons do not work. This is the jsp for them:

<%-- 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>

When a link is clicked it is suppose to call the corresponding method found in this class. However, it never actually makes it into this class. It's suppose to make a call in the index then based on the navigation rule it returns the proper view, but it never makes it into the correct method.

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";
    }

}

The onclick is different from the one that was working previous, which makes me believe it has to do with the version but I haven't found anything relating to why the onclick would change.

The onclick previous was:

<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>

The onclick for the new one is:

<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>

Simply, I guess I'm asking is how can I make the new link look like the old one with the update versions?


Solution

  • I found out that the issue related to using the old Websphere jars that were still "in use". I had the tag library above, of IBM faces using the prefix hx. This only works on Websphere server. So in the process of removing them I had to redo the tags that were implemented which most had easy equivalents. The other issue that came up, on the backend of it, we implemented for IBM Faces so I am currently in the process of rewriting to incorporate the actually used tags. I also had to change the web.xml which was still set up to include IMB context-params, so I removed them.

    As you can see here, I removed the hx tag library which allowed the links to work and there are no problems. I also had to remove all mention of IBM instnaces and sources from the web.xml file.

    <%-- 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://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">
    
        <% 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="Credit/Gift Card Request"></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="My Requests"></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="My ToDo's"></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="Search"></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="Accounting"></h:outputText>
                </h:commandLink></li>
                <li><a href="<%= request.getContextPath() %>/forms/Help.pdf" target="_blank">Help</a></li>
                <% } %>
            </ul>
        </h:form>