1
votes

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

2
Can you post more of your backing bean? For example you refer to in.getValue, but you haven't posted that code here.Catfish
I added the parts of backing beanveote

2 Answers

2
votes

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 ?

1
votes

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.