JSF生命周期进行2次PrimeFaces阿贾克斯生命周期、JSF、阿贾克斯、PrimeFaces

2023-09-11 01:33:24 作者:懂爱旳孤独

我用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.