JSF: Solution for managed beans being called twice?

I”m playing around with JSF and a *small* web app but I have noticed managed bean’s methods are getting called twice. This present a problem when trying to build a select menu drop down collection list of superset values.

This selectOne:

<h :selectOneMenu id="hardwareTypeItem" value="#{Model.hardwareTypeItem}">
<f :selectItems value="#{Item.hardwareTypeItems}"></f>

Will cause this issue when the selectItems collection is being populated.

13:13:11,828 INFO ItemForm:? - ItemForm()
13:13:12,048 INFO HibernateTransactionManager:313 - Initiating transaction commit
13:13:12,048 INFO ItemForm:? - [javax.faces.model.SelectItem@b28f30, javax.faces.model.SelectItem@d6a0e0, javax.faces.model.SelectItem@dbf04d, javax.faces.model.SelectItem@17d80e9, javax.faces.model.SelectItem@9a44d6, javax.faces.model.SelectItem@1d5ebc, javax.faces.model.SelectItem@36b1bb, javax.faces.model.SelectItem@ce88d2, javax.faces.model.SelectItem@1789a96, javax.faces.model.SelectItem@ecfaea, javax.faces.model.SelectItem@4d37e5]
13:13:12,058 INFO HibernateTransactionManager:313 - Initiating transaction commit
13:13:12,058 INFO ItemForm:? - [javax.faces.model.SelectItem@1c8c58, javax.faces.model.SelectItem@422510, javax.faces.model.SelectItem@8f5944, javax.faces.model.SelectItem@12d9844, javax.faces.model.SelectItem@67a232, javax.faces.model.SelectItem@1c98c1b, javax.faces.model.SelectItem@10d78ec, javax.faces.model.SelectItem@17df472, javax.faces.model.SelectItem@3b9a5f, javax.faces.model.SelectItem@113dd59, javax.faces.model.SelectItem@12929b2]

The only work around solution is to check if the ArrayList == null and not populate the list again. This is not an ideal solution because if another application/person is updating those drop down supersets I”ll miss out on a new updated list until the session scoped bean is destroyed.

This entry was posted in Tech and tagged , . Bookmark the permalink.

Comments are closed.