Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在JSF应用程序中显示消息_Javascript_Jsf_Onmouseover - Fatal编程技术网

Javascript 在JSF应用程序中显示消息

Javascript 在JSF应用程序中显示消息,javascript,jsf,onmouseover,Javascript,Jsf,Onmouseover,当鼠标移动到接口的特定元素上时,如何在JSF应用程序中显示简单消息?我已尝试此代码,但无效,未显示任何消息: <h:form> <h:selectManyCheckbox title="#{hello.message}" layout="pageDirection" border="1" value="#{hello.customersSelect}"> <f:selectItems value="#{hello.custom

当鼠标移动到接口的特定元素上时,如何在JSF应用程序中显示简单消息?我已尝试此代码,但无效,未显示任何消息:

<h:form>
    <h:selectManyCheckbox title="#{hello.message}" layout="pageDirection"
        border="1" value="#{hello.customersSelect}">
        <f:selectItems value="#{hello.customers}"></f:selectItems>
    </h:selectManyCheckbox><br />
    <h:commandButton action="response.xhtml" value="Click me" />
</h:form>
JSF文件:

<h:form id ="f">
<h:selectManyCheckbox onmouseover="#{hello.message()}" layout="pageDirection" border="1"  value="#{hello.customersSelect}">
    <f:selectItems value="#{hello.customers}"></f:selectItems>
</h:selectManyCheckbox><br />
<h:commandButton action="response.xhtml" value="Click me" />
</h:form>

我想我应该在某个地方添加一个标记h:message,但尽管我付出了努力,还是没能完成。有什么提示吗?

您应该在javascript中处理它,因为mouseOver是一个dom事件

<h:head>    
<h:outputScript library="js" name="rollover.js" />
[...]
<h:form id ="f">
<h:selectManyCheckbox onmouseover="mouseOn('foobar')" layout="pageDirection" border="1"  value="#{hello.customersSelect}">

为了满足您的好奇心,请使用

JSF代码

<h:selectManyCheckbox layout="pageDirection" border="1"
    value="#{hello.customersSelect}">
    <f:selectItems value="#{hello.customers}"></f:selectItems>

    <f:ajax event="mouseover" listener="#{hello.messageListener}" render="messages" />
</h:selectManyCheckbox>
<br />
<h:messages id="messages" />

但更重要的是,你确定这是你真正问题的解决方案吗?为了获得更好的帮助,最好指定功能要求。

如果您只想显示静态消息,而该消息在显示页面时不会更改:

<h:form>
    <h:selectManyCheckbox title="#{hello.message}" layout="pageDirection"
        border="1" value="#{hello.customersSelect}">
        <f:selectItems value="#{hello.customers}"></f:selectItems>
    </h:selectManyCheckbox><br />
    <h:commandButton action="response.xhtml" value="Click me" />
</h:form>

完全没有JavaScript;-)

您是否尝试添加将消息作为字符串包含的
title
属性?
onmouseover
是一个JavaScript函数,您正在传递一个服务器端方法。将其更改为处理消息表示的JavaScript函数(警报或其他内容)。@f_puras你读过OP的代码吗?@luigimendoza是的,它不起作用。我想他只是想要一个复选框的工具提示。@LuiggiMendoza-我需要传递服务器端方法。在JSF中如何做到这一点?这是我的问题。我对用Javascript实现它不感兴趣。
@ManagedBean
@ViewScoped
public class Hello {
    //attributes, constructor and other methods

    public void messageListener(AjaxBehaviorEvent event) { 
        System.out.println("OnMouseOver ajax event.");
        FacesContext.getCurrentInstance().addMessage(
            null, new FacesMessage("Done"));
    }
}
<h:form>
    <h:selectManyCheckbox title="#{hello.message}" layout="pageDirection"
        border="1" value="#{hello.customersSelect}">
        <f:selectItems value="#{hello.customers}"></f:selectItems>
    </h:selectManyCheckbox><br />
    <h:commandButton action="response.xhtml" value="Click me" />
</h:form>
public String getMessage() {
    return "Done";
}