JSF生命周期进行2次PrimeFaces阿贾克斯 [英] JSF Lifecycle performed 2 times with PrimeFaces ajax

查看:172
本文介绍了JSF生命周期进行2次PrimeFaces阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用PrimeFaces 3.3.1与Apache WebSphere Application Server上的MyFaces 2。 我BackingBean是SessionScoped。 我有一个selectOneButton形式应该更新整个窗体。

I use PrimeFaces 3.3.1 with Apache MyFaces 2 on WebSphere Application Server. My BackingBean is SessionScoped. I have a form with a selectOneButton should update the whole form.

<h:form id="options">
    <p:panelGrid>
        <p:column rowspan="2" style="width:115px;">
            <p:selectOneButton value="#{graph.diagramdata}" id="diagramdata">           
                <f:selectItem itemLabel="WAS-Diagramm" itemValue="1" />
                <f:selectItem itemLabel="PSC-Diagramm" itemValue="2" />
                <p:ajax listener="#{graph.changeView }" update=":options"/>
            </p:selectOneButton>
            <h:outputText>#{graph.diagramdata}</h:outputText>
        </p:column>
        <p:column rendered="#{graph.diagramdata eq '1' }">
          ...
        </p:column>
    </p:panelGrid>
</h:form>

编辑:第一部分辅助bean

@ManagedBean(name = "graph")
@SessionScoped
public class MyGraphBean implements Serializable {
  private int diagramdata;

  public void changeView(AjaxBehaviorEvent event) {
      LOGGER.info(this.getDiagramData());   
  }

  public int getDiagramdata() {
    return diagramdata;
  }

  public void setDiagramdata(int diagramdata) {
    if(diagramdata == 1 || diagramdata == 2) {
      this.diagramdata = diagramdata;
    }
  }
}

但是,当我改变一个值JSF生命周期进行2次。 在第一次的in.getValue为空的第二时间,它是1或2(从记录器)。 但在结束我的H:的outputText打印0 ...

But when I change a value the jsf Lifecycle is performed 2 times. At first time the in.getValue is null the second time it is 1 or 2 (from LOGGER). But at the end my h:outputText prints 0...

要调试我使用 BalusC:调试JSF生命周期

为什么TE生命周期2进行钻削次?

Why is te Lifecycle perfomed 2 times?

我如何用我的selectOneButton正确地呈现其他列?

How do I have to use my selectOneButton to render the other columns correctly?

编辑:肮脏的解决方案

我发现我的问题的解决方案(非常脏!)。 我换了号码:Ajax组件到f:阿贾克斯。 所以,现在我的值设置为第二生命周期阶段正确的值。

I found a solution for my problem (very dirty!!!). I changed the p:ajax component to f:ajax. So now my value is set to the correct value in the second lifecycle phase.

<p:selectOneButton value="#{graph.diagramdata}" id="diagramdata">           
      <f:selectItem itemLabel="WAS-Diagramm" itemValue="1" />
      <f:selectItem itemLabel="PSC-Diagramm" itemValue="2" />
      <f:ajax listener="#{graph.changeView }" render="options"/>
</p:selectOneButton>

此外,我加了,如果在我的setter方法​​声明中,以避免0的设置。

Also I added a if statement in my setter method to avoid that "0" is set.

现在的第一个JSF生命周期什么都不做,第二个设置我的价值。

Now the first jsf lifecycle does nothing and the second sets my value.

它的工作原理,但不是很细...

It works, but is not very fine...

推荐答案

好像有PrimeFaces selectOneButton的错误。 当我使用如电话号码:!selectOneMenu用于它正常工作与1 JSF生命周期

Seems like a bug with PrimeFaces selectOneButton. When I use e.g. p:selectOneMenu it works fine with 1 JSF Lifecycle!

下面是primefaces已知问题

Here is the known issue from primefaces.

这篇关于JSF生命周期进行2次PrimeFaces阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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