1

I've a p:selectOneMenu component within a h:form component like:

<p:selectOneMenu id="scroll" rendered="#{projectPageBean.rendered}"
    value="#{projectPageBean.selectedInstrument}">
    <f:selectItems value="#{projectPageBean.instruments}"/>
    <p:ajax event="change" listener="#{projectPageBean.valueChanged}" update="test" />
</p:selectOneMenu>

Within the same form I defined a p:commandButton component:

<p:commandButton id="test"
    value="View Instrument"
    action="#{projectPageBean.getPage}"
    update="@this,:add-instrument-dialog-form:scrolladd"/>

Depending on the selectedInstrument from the selecOneMenu the navigation through the action attribute of the p:commandButton ought to be different.

The managed bean projectPageBean is request scoped.

Is this feasible or should I try a different approach?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
g.verhaag
  • 139
  • 3
  • 11

1 Answers1

0

The action attribute is evaluated during the request of the actual form submit. As this is happening during a different request than the one on which you've changed it, and as your bean is request scoped, it will fail. The bean is namely reconstructed with all properties set to default.

You need to put the bean in the view scope in order to get this construct to work.

@ManagedBean
@ViewScoped
public class ProjectPageBean {}

Alternatively, if the getPage() merely returns a String, rather use <p:button> instead.

<p:button ... outcome="#{projectPageBean.page}" />

The outcome attribute is evaluated during rendering the HTML output, thus it will work just fine in such construct.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This scope 'thing' is rather tricky, and have to be very much aware of it! Thanks again! – g.verhaag Jun 26 '13 at 14:24
  • It'll be easier if you understand the underlying basic concepts JSF is sitting on top of (and is abstracting away to a rather high degree that you don't see it anymore), such as HTTP request, HTML form postbacks, HTTP session, etc. – BalusC Jun 26 '13 at 14:27