带有< f:ajax>的JSF2.0只工作一次 [英] JSF2.0 with <f:ajax> only works once

查看:75
本文介绍了带有< f:ajax>的JSF2.0只工作一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF2.0中的标签有问题,希望有人指出我做错了什么.这是用户界面中的内容:

I'm having a problem with the tag in JSF2.0 and I hope someone can point out what I'm doing wrong. Here's what I've got in the UI:

<h:panelGroup>
  <h:form id="theForm">
    <h:selectOneMenu id="theMenu" value="#{viewBean.selectedItem}">
        <f:ajax event="change" render="selectedItemText"/>
    <f:selectItem itemLabel=""/>
    <f:selectItems value="#{viewBean.selectableItems}"/>
    </h:selectOneMenu>
    <h:outputText id="selectedItemText" value="#{viewBean.selectedItemText}" />
  </h:form>
</h:panelGroup>

这很好用-我的对话范围内的后备bean有一个方法setSelectedItem,它被调用,并且它在我第一次从菜单中选择另一个项目时就起作用了.输出文本在前端更新,很高兴.但是,对菜单选择的进一步更改不会触发通过ajax调用设置器.我还尝试过在f:ajax标记上使用侦听器进行此操作-该侦听器方法也仅在第一次调用(代码中的断点才能解决).

This is working great - my conversation-scoped backing bean has a method setSelectedItem, and it's called and it does its thing the first time I select a different item from the menu; the output text is updated in the frontend, and I'm happy. However, further changes to the menu selection do not trigger a call to the setter via ajax. I've also tried this with a listener on the f:ajax tag - the listener method is only called that first time as well (breakpoints in the code to figure this out).

我做错了什么吗?

推荐答案

我遇到了类似的问题.

I had a similar problem.

下面的第二个commandButton在具有视图参数的JSF视图中只能使用一次.将<f:param>添加到我的第一个commandButton中解决了该问题.这种情况在BalusC的未必有用的讨论中.

My second commandButton below only works once in the JSF view below that has a view param. Adding <f:param> to my first commandButton solved the problem. This is a situation not covered by BalusC's very helpful discussion.

<!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:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

<f:view>
    <f:metadata>
        <f:viewParam name="id" value="#{fooManager.millis}" required="true"/>
    </f:metadata>

    <h:head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    </h:head>

    <h:body>
        <h:form id="fooForm">
            <h:commandButton
                    id="barBbutton"
                    value="foo:test"
                    action="#{fooManager.test}">
                <f:param name="id" value="1"/>
                <f:ajax render="fooMillis1"/>
            </h:commandButton>

            <p>
                <h:outputText id="fooMillis1" value="foo:display1: #{fooManager.millis}"/>
            </p>
            <p>
                <h:outputText id="fooMillis2" value="foo:display2: #{fooManager.millis}"/>
            </p>
        </h:form>
        <h:form id="barForm">
            <h:commandButton
                    id="barButton"
                    value="bar:test"
                    action="#{barManager.test}">
                <f:ajax render="barMillis1"/>
            </h:commandButton>

            <p>
                <h:outputText id="barMillis1" value="bar:display1: #{barManager.millis}"/>
            </p>
            <p>
                <h:outputText id="barMillis2" value="bar:display2: #{barManager.millis}"/>
            </p>
        </h:form>
    </h:body>
</f:view>
</html>

我的FooManager和BarManager看起来相同:

And my FooManager and BarManager look the same:

@ManagedBean
@ViewScoped
public class FooManager {

    public long getMillis() {
        return millis;
    }

    public void setMillis(long millis) {
        this.millis = millis;
    }

    public void test() {
        setMillis(System.currentTimeMillis());
    }
    private long millis;

}

当它不起作用时,我的Weblogic/Mojarra库没有给出任何有用的提示.任何地方都没有错误.只是经过无数次尝试,我才想到了一个像上面的第一个一样的工作按钮.

When it is not working, my Weblogic/Mojarra library does not give any helpful hint. There is no error anywhere. It was only after numerous tries that I came up with a working button like the first one above.

这篇关于带有&lt; f:ajax&gt;的JSF2.0只工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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