s:selectItems doesn't rerender.
fredrikl74 Nov 24, 2008 3:27 PMHello!
I'm developing a part of an application used for administration of bosses.
I've added possibility to add and remove bosses from DB.
The problem is when I try to remove a boss, the selectOneMenu and s:selectItems
doesn't rerender, the removed boss still appears in the drop-down box.
It rerenders only when I do a explicit refresh (ctrl f5).
Here is my code:
createBoss.xhtml
<div class="overview" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" xmlns:riskintyg="http://www.riskintyg.se/faceletsComponents" xmlns:s="http://jboss.com/products/seam/taglib"> <a4j:outputPanel ajaxRendered="true"> <h:messages styleClass="message"/> <rich:simpleTogglePanel switchType="client" label="Skapa chef"> <h:panelGrid columns="1"> <h:form> <riskintyg:simpleInput label="Namn" value="#{boss.name}" required="true"/> <riskintyg:simpleInput label="Titel" value="#{boss.title_sv}" required="true"/> <riskintyg:simpleInput label="Engelsk titel" value="#{boss.title_en}" required="true"/> <a4j:commandButton action="#{bossController.createBoss}" value="Skapa chef" style="float:left"/> </h:form> </h:panelGrid> </rich:simpleTogglePanel> <rich:simpleTogglePanel switchType="client" label="Ta bort chef"> <h:panelGrid columns="1"> <h:form> <h:selectOneMenu value="#{boss}" > <s:selectItems value="#{bosses}" var="boss" label="#{boss.name}" /> <s:convertEntity/> </h:selectOneMenu> <a4j:commandButton action="#{bossController.deleteBoss}" value="Ta bort chef" style="float:left"/> </h:form> </h:panelGrid> </rich:simpleTogglePanel> </a4j:outputPanel> </div> The backing bean BossController.java @Name("bossController") @Scope(SESSION) @Restrict("#{identity.loggedIn}") public class BossController { @In private EntityManager entityManager; @Logger private Log log; @In private FacesMessages facesMessages; @In private Boss boss; @DataModel List<Boss> bosses; /** * Creates a new boss and stores the entity into DB. * * @param boss the <class>Boss</class> object to be stored. * @throws IllegalArgumentException if argument boss is null. */ public void createBoss() { bosses.add(boss); entityManager.persist(boss); log.info("Boss created, " + boss); facesMessages.add("#{messages['boss.created']}"); } /** * Deletes the selected boss from DB. * * @param boss the <class>Boss</class> object to be deleted. * @throws IllegalArgumentException if argument boss is null. */ public void deleteBoss() { bosses.remove(boss); entityManager.remove(boss); log.info("Boss deleted, " + boss); boss = null; facesMessages.add("#{messages['boss.deleted']}"); } @Factory("bosses") @SuppressWarnings("unchecked") public void findAllBosses(){ bosses = entityManager.createNamedQuery("findAllBosses").getResultList(); } }