Reputation: 586
I'm having some trouble where <f:event type="preRenderView" listener="#{decryptionBean.readAllBoards}>
is causing all of my buttons (of default type, not type="button"> to call the same bean method, specifically decryptionBean.readAllBoards
. Here's what I believe to be the relevant part of the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
...
<h:body>
<f:view>
<f:event type="preRenderView" listener="#{decryptionBean.readAllBoards}"/>
</f:view>
...
<p:layout>
<p:layoutUnit id="andon_layout--board1" position="center"
size="50%" styleClass="centered">
<h2>Board 1</h2>
<h:form id="andon_layout--board1--displayForm">
<h:outputLabel for="location_list" value="Board List: " />
<h:selectOneMenu id="location_list" value="Loading..."
required="false">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{decryptionBean.locDropDownArray}" />
</h:selectOneMenu>
<br />
<p:commandButton id="loadBoard1" value="Load board" action="#{decryptionBean.loadBoard}"/>
<h:messages id="b1_messages" />
</h:form>
</p:layoutUnit>
<p:layoutUnit id="andon_layout--board2" position="east"
size="50%" styleClass="centered">
<h2>Board 2</h2>
<h:form id="andon_layout--board2--displayForm">
<h:outputLabel for="location_list" value="Board List: " />
<h:selectOneMenu id="location_list" value="Loading..."
required="false">
<f:selectItem itemLabel="Select One" itemValue="#{decryptionBean.display2}" />
<f:selectItems value="#{decryptionBean.locDropDownArray}" />
</h:selectOneMenu>
<br />
<p:commandButton value="Load board" id="loadBoard2" />
</h:form>
</p:layoutUnit>
</p:layout>
...
loadBoard1 runs decryptionBean.loadBoard()
, as well as decryptionBean.readAllBoards()
, while loadBoard2 only runs decryptionBean.readAllBoards()
. If I remove the <f:event type="preRenderView" listener="#{decryptionBean.readAllBoards}>
line, loadBoard1 and 2 function correctly (calling the correct / no methods). Any ideas about what could be going on?
Thanks in advance!
Upvotes: 0
Views: 3767
Reputation: 73528
I don't know what you expect the preRenderView event to do, but it will always be called before the RENDER_VIEW phase (hence the name).
You clicking the buttons will cause the view to be re-rendered, hence the method will be called always when you click a button. If you used ajax and only rendered small parts of the view, the event would not be triggered.
If you don't want to call that method every time the view is rendered, you could try a ViewScoped bean and a @PostConstruct method.
Upvotes: 1