bertolami
bertolami

Reputation: 2936

JSF Request Parameter in AJAX Form

I have a Page that is called with a request parameter id that is used to select the drop down elements

<h:selectOneMenu value="#{bean.selectedService}">
  <f:selectItems value="#{bean.getServices(param.id)}" var="_s" 
     itemLabel="#{_s.description}" itemValue="#{_s.value}" />
    <f:ajax render="@all" />
</h:selectOneMenu>

Is there any simple possibility that I can keep the param.id in the AJAX request. Currently it is lost.

Upvotes: 1

Views: 741

Answers (1)

BalusC
BalusC

Reputation: 1108567

Make it a view param instead.

<f:metadata>
    <f:viewParam name="id" value="#{bean.id}" required="true" />
    <f:event type="preRenderView" listener="#{bean.preRenderView}" />
</f:metadata>

with

@ManagedBean
@ViewScoped
public class Bean {

    private Long id;
    private List<Service> services;

    public void preRenderView() {
        if (services == null) {
            services = getServices(id);
        }
    }

    // ...
}

and

<f:selectItems value="#{bean.services}" ... />

Upvotes: 1

Related Questions