JSF Lifecycle performed 2 times with PrimeFaces ajax

别来无恙 提交于 2019-12-24 10:58:53

问题


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>

EDIT: PART OF BACKING 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;
    }
  }
}

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

To debug I use BalusC: Debug JSF Lifecycle

Why is te Lifecycle perfomed 2 times?

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

EDIT: DIRTY SOLUTION

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>

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

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

It works, but is not very fine...


回答1:


What is that onchange="submit()" you have there ? is it by any chance doing a form submit? If so then remove it...

Also , are you sure you need that immediate="true" are you planning skipping validations ?




回答2:


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

Here is the known issue from primefaces.



来源:https://stackoverflow.com/questions/11611699/jsf-lifecycle-performed-2-times-with-primefaces-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!