二传手使用F时,未调用:AJAX [英] Setter not invoked when using f:ajax

查看:99
本文介绍了二传手使用F时,未调用:AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何在JSF使用AJAX,我做了一个网页,做其实也没什么,就是充满了数字输入文本,提交给服务器,调用制定者提交的值元素,显示吸气的价值。

I'm learning how to use ajax within jsf, I made a page that does actually nothing, an input text that is filled with a number, submitted to the server, call the setter for that element with the value submitted, and display the getter's value.

下面是简单的bean的code:

Here's the simple bean's code:

@ManagedBean(name="helper",eager=true)
public class HealthPlanHelper {


    String random = "1";

    public void setRandomize(String s){
        random = s;
                System.out.println("Calling setter");
    }

    public String getRandomize(){
        return random;
    }

}

和JSF页面:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<h:body>

    <h:form>
        <h:commandButton action="nothing">
            <f:ajax render="num"/>
        </h:commandButton>

        <h:inputText value="#{helper.randomize}" id="num"/>
    </h:form>

</h:body>
</html>

正如你看到的,这是一个请求范围的bean,每当我按一下按钮的服务器显示它创建的bean的实例,但setter方法​​永远不会被调用,因此,吸气收益始终为1作为字符串的值

As you see, this is a request scoped bean, whenever I click the button the server shows that it creates an instance of the bean, but the setter method is never called, thus, the getter return always "1" as the value of the string.

当我删除了二传手通常称为。

When I remove the the setter is called normally.

推荐答案

&LT; F:AJAX&GT; 默认程序(的执行属性nofollow的>阅读说明)仅电流分量。基本上,你的code是完全一样的:

The <f:ajax> processes by default (read description of execute attribute) only the current component. Basically, your code is exactly the same as this:

<h:form>
    <h:commandButton action="nothing">
        <f:ajax execute="@this" render="num"/>
    </h:commandButton>
    <h:inputText value="#{helper.randomize}" id="num"/>
</h:form>

在影响,只有&LT; H:的commandButton作用&gt; 正在被处理和&LT; H:inputText的值GT; (和任何其它的输入字段,如果有的话)被完全忽略。

In effects, only the <h:commandButton action> is been processed and the <h:inputText value> (and any other input field, if any) is completely ignored.

您需要更改执行属性来显式指定的组件或部分你想Ajax请求期间要处理。通常情况下,为了处理整个形式, @form 是被使用:

You need to change the execute attribute to explicitly specify components or sections you'd like to process during the ajax request. Usually, in order to process the entire form, @form is been used:

<h:form>
    <h:commandButton action="nothing">
        <f:ajax execute="@form" render="num"/>
    </h:commandButton>
    <h:inputText value="#{helper.randomize}" id="num"/>
</h:form>

参见:

  • 通讯在JSF 2.0 - 的 AJAX(异步)POST形式
  • See also:

    • Communication in JSF 2.0 - Ajax (asynchronous) POST form
    • 这篇关于二传手使用F时,未调用:AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆