简体   繁体   English

JSF 1.2 h:commandLink不起作用,未定义mojarra

[英]JSF 1.2 h:commandLink not working, mojarra is not defined

I got a problem with JSF 1.2 on websphere 7. I'm trying to implement a navigation with JSF. 我在Websphere 7上遇到了JSF 1.2的问题。我正在尝试使用JSF实施导航。 I'm also using RichFaces. 我也在使用RichFaces。

In the console of the browser I got this error: Uncaught ReferenceError: mojarra is not defined 在浏览器的控制台中,我收到此错误: Uncaught ReferenceError: mojarra is not defined

I have seen other with this problem and they solved it with adding <h:head> but this didn't work for me. 我看到了其他与此问题有关的问题,他们通过添加<h:head>来解决,但这对我不起作用。

Thank you for helping 感谢您的帮助

My navigation.xhtml 我的navigation.xhtml

<?xml version="1.0" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:composition>
    <h:form>
        <!-- Navigation -->
        <div id="navigation" class="navigation">
            <div class="level0">
               <h:commandLink action="#{navigation.toHome}" value="#{messages.elsi_dg_navigation_home}" />
            </div>
            <div class="level0">
                <h:commandLink action="#{navigation.toHistory}" value="#{messages.elsi_dg_navigation_history}" />
            </div>
        </div>
    </h:form>
</ui:composition></body></html>

The NavigationBean.java NavigationBean.java

@Controller("navigation")
@Scope("session")
@ManagedBean
public class NavigationBean {

private String lastSite = "home";


public String toHome() {
    return this.processOutcome("home");
}

public String toHistory() {
    return this.processOutcome("history");
}

public String toCurrentPage() {
    return this.lastSite;
}

private String processOutcome(String outcome) {
    this.lastSite = outcome;
    return outcome;
}
}

HTML output: HTML输出:

<div id="navigation" class="navigation">
<form id="j_id19" name="j_id19" method="post" action="/elsi-dg/xhtml/home.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_id19" value="j_id19">
    <!-- Navigation -->
    <div id="navigation" class="navigation">
        <div class="level0"><a href="#" onclick="mojarra.jsfcljs(document.getElementById('j_id19'),{'j_id19:j_id21':'j_id19:j_id21'},'');return false">Home</a></div>
        <div class="level0"><a href="#" onclick="mojarra.jsfcljs(document.getElementById('j_id19'),{'j_id19:j_id23':'j_id19:j_id23'},'');return false">History</a></div>
    </div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="3428583661652779493:-8865896015881316410" autocomplete="off">
</form>
</div>

UPDATE 更新

<a4j:commandLink> works without problems.. <a4j:commandLink>可以正常工作。

Maybe the problem is with the tag ui:compostion 也许问题出在ui:compostion标签上

 <ui:composition template="./template/template.xhtml">

It normally needs a template file . 它通常需要一个模板文件

Are you using one? 您正在使用一个吗? If you aren't, try to remove the <ui:composition> tag. 如果不是,请尝试删除<ui:composition>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM