开发者

Trouble using <f:ajax> on JSF 2.0

I posted a question here last week about using Ajax with J2EE and got and answer about the build in support of ajax with JSF 2.0开发者_JAVA技巧. Unfortunately I just cant seem to get any example of this to work!

I have tried out using different IDEs with different servers but I cant get this basic example to work.

A session scoped managed bean:

public class testBean 
{
    private String name;

    public testBean() {}


    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }
}

And the xhtml page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<head>
  <title>Default title</title>
</head>

    <body>

        <h:form id="testForm"> 

            <h:inputText id="test" value="#{testBean.name}" > 
                <f:ajax event="keyup" render="testForm:name" execute="testForm:test"/> 
            </h:inputText> 


            <h:outputText id="name" value="#{testBean.name}" /> 
        </h:form>   

    </body>

</html>

From my knowledge the page should display the text that is written while it is being written right next to the inputText form, but that is not happening.

I hate making two topics about roughly the same thing but I really dont know whats wrong here, from what Ive read this code should work.


You have the wrong event specified in your f:ajax. Use keyup or keypress instead of click:

<h:inputText id="test" value="#{testBean.name}" > 
  <f:ajax event="keyup" render="name" execute="test"/> 
</h:inputText>

the onclick / click event handler is only fired by a mouse click.

UPDATE:

Didn't notice it before:

I think you should use <h:head> instead of <head> to include all javascript resources for ajax correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜