jacktrades
jacktrades

Reputation: 7392

p:command inside carousel

Why below works:

<h:form id="form1">
<p:carousel id="carousel" value="#{galleriaBean.paths_tn}" var="img" itemStyle="width: 200px">
<p:graphicImage value="#{img}"/>
</p:carousel>

<p:commandLink id="here" value="click me" update="hello11" oncomplete="dlg.show()">
<f:setPropertyActionListener value="hello!!!" target="#{galleriaBean.selected}"/>
</p:commandLink>

<p:dialog widgetVar="dlg">
<h:outputText id="hello11" value="#{galleriaBean.selected}"/>
</p:dialog>
</h:form>

But moving the commandLink into the carousel, it doesn't work? setPropertyActionListener does not even set the variable in the bean.

@RequestScoped CDI Bean.

<p:carousel id="carousel" value="#{galleriaBean.paths_tn}" var="img" itemStyle="width: 200px">
<p:graphicImage value="#{img}"/>
<p:commandLink id="here" value="click me" update=":form1:hello11" oncomplete="dlg.show()">
<f:setPropertyActionListener value="#{img}" target="#{galleriaBean.selected}"/>
</p:commandLink>
</p:carousel>

Upvotes: 0

Views: 1034

Answers (1)

partlov
partlov

Reputation: 14277

You didn't show second version of your code (when you put p:commandLink inside p:carousel), but I suppose that you putted some property of backing bean inside value attribute of p:commandLink. You must be aware that AJAX request is also request, so you request scoped bean is recreated in each AJAX request. To preserve state of property, which you are using for f:setPropertyActionListener you must make your bean at least view scoped, or somehow retain state in @PostConstructor method. If you can use view scoped bean, that should be done.

Upvotes: 2

Related Questions