1

How is it possible to display a simple message in a JSF application when the mouse moves over a specific element of the interface? I have tried this code, but it didn't work, no message is displayed:

JSF file:

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

The backing bean Hello (ManagedBean) contains the method message() as:

public void message(){
    FacesContext.getCurrentInstance().addMessage("f", new FacesMessage("Done"));
}

I suppose I should add somewhere a tag h:message, but I couldn't get it done, despite my efforts. Any hint?

9
  • Have you tried adding a title attribute containing your message as a String? Commented Mar 6, 2013 at 15:15
  • onmouseover is a JavaScript function and you're passing a server side method. Change it for a JavaScript function that handles your message presentation (an alert or something else). Commented Mar 6, 2013 at 15:16
  • @f_puras have you read OP's code? Commented Mar 6, 2013 at 15:17
  • @LuiggiMendoza Yes, it won't work. I supposed he just wants a tooltip for the checkboxes. Commented Mar 6, 2013 at 15:26
  • @LuiggiMendoza - I want necessarily to pass the server side method. How can this be done in JSF? That is my question. I am not interested in implementing it in Javascript. Commented Mar 6, 2013 at 15:30

3 Answers 3

1

To satisfy your curiosity, use <f:ajax event="mouseover" listener="#{hello.messageListener}" />:

JSF code

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

Hello bean code

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

But more importantly, are you sure this is the solution to your real problem? It would be better to specify the functional requirement in order to get better help.

Sign up to request clarification or add additional context in comments.

Comments

1

you should handle it in javascript as mouseOver is a dom event

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

and the rollover.js :

function mouseOn(text) {
   alert(text)
}

Comments

0

If you just want a static message being shown, which does not change while the page is displayed:

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

And the bean:

public String getMessage() {
    return "Done";
}

No JavaScript at all ;-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.