简体   繁体   English

JSF渲染不起作用

[英]JSF render does not work

The following code does not rerender the form: 以下代码不会重新呈现该表单:

xhtml: xhtml:

<ui:composition 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"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/WEB-INF/templates/default.xhtml">
    <ui:define name="content">
        <h:form id="form">
            <rich:panel header="My Header">
                <h2>
                    <h:outputLabel value="#{tournamentBean.mode}" />
                </h2>
                <a4j:commandButton value="Toggle"
                    action="#{tournamentBean.toggleMode()}" render="form" />
            </rich:panel>
        </h:form>
    </ui:define>
</ui:composition>

bean: 豆角,扁豆:

import java.io.Serializable;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@SuppressWarnings("serial")
@Named("tournamentBean")
@ViewScoped
public class TournamentBean implements Serializable {

  private String mode = "A";

  public String getMode() {
    return mode;
  }

  public void toggleMode() {
    if (this.mode.equals("A"))
      this.mode = "B";
    else
      this.mode = "A";
  }
}

I am using Wildfly 8.0 and therefore JSF 2.2. 我使用的是Wildfly 8.0,因此使用的是JSF 2.2。 The method toggleMode is called on every click on the button. 每次单击按钮都会调用方法toggleMode。 In IE 11 it never rerenders the form. 在IE 11中,它从不放弃表单。 In Chrome it works twice but not more times. 在Chrome浏览器中,它可以工作两次,但不能再重复。

What am I missing? 我想念什么?

@Named is CDI annotation, @ViewScoped is from JSF. @Named是CDI批注, @ViewScoped来自JSF。 So you have both CDI and JSF trying to manage the bean, so of course this wont work and the result bean scope can be singleton, if its going to work at all. 因此,您有CDI和JSF都试图管理Bean,因此这当然行不通,并且如果Bean可以正常工作的话,结果Bean范围可以是单例的。

Replace @ViewScoped with for example @javax.enterprise.context.RequestScoped and try running the code. @ViewScoped替换为例如@javax.enterprise.context.RequestScoped然后尝试运行代码。 If you need to use view scope, look around for CDI implementation or conversationscope . 如果您需要使用视图范围,请四处查看CDI实现或conversationscope It can be done somehow even though CDI doesnt directly support viewscope . 即使CDI不直接支持viewscope ,也可以通过某种方式完成。

Or migrate to JSF and its @ManagedBeans , but those are sheduled to be depracated. 或迁移到JSF及其@ManagedBeans ,但是这些都被弃用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM