scrollableDetaTable won't be rerendered
funcruiser7 May 25, 2008 3:10 AMHi together,
I have a problem. I have following XHTML-page:
<html 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:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <ui:composition> <rich:modalPanel id="administrationMP" width="800" height="600" zindex="100" border="1"> <f:facet name="header"> <h:outputText value="Verwaltung" style="font-size: 120%; background-color: transparent;" /> </f:facet> <div class="adminMPUserSection"> <rich:panel label="Benutzer/ Gruppen/ Rechte" bodyClass="panelBody" > <rich:panel id="Users"> <f:facet name="header"> <h:outputText value="Benutzer" style="font-size: 120%; background-color: transparent;" /> </f:facet> <h:outputText value="Users..." styleClass="infoMessage" /> </rich:panel> <rich:spacer height="10px"/> <rich:panel id="Roles"> <f:facet name="header"> <h:outputText value="Gruppen" style="font-size: 120%; background-color: transparent;" /> </f:facet> <a4j:form> <rich:spacer height="10" /> <h:panelGrid id="ab01" columns="3" > <rich:scrollableDataTable id="rolesList" rowKeyVar="rkv" frozenColCount="1" height="100px" width="320px" rows="5" value="#{adminGroupBean.allRoles}" var="roles" sortMode="single" binding="#{adminGroupBean.table}" selection="#{adminGroupBean.selection}"> <rich:column id="ident1" width="80px" > <f:facet name="header"><h:outputText value="Bezeichnung" /></f:facet> <h:outputText value="#{roles.ident}" /> </rich:column> <rich:column id="desc1" width="200px" > <f:facet name="header"><h:outputText value="Beschreibung" /></f:facet> <h:outputText value="#{roles.desc}" /> </rich:column> </rich:scrollableDataTable> <h:panelGroup> <rich:spacer width="50px" /> </h:panelGroup> <h:panelGroup> <h:panelGrid id="ab02" columns="1" > <a4j:commandButton value="Gruppe bearbeiten" reRender="table" action="#{adminGroupBean.takeSelection}" oncomplete="javascript:Richfaces.showModalPanel('MPSelRole');" /> <rich:spacer height="10px" /> <a4j:commandButton value="neue Gruppe erstellen" reRender="table" action="#{adminGroupBean.takeSelection}" oncomplete="javascript:Richfaces.showModalPanel('MPSelRole');" /> <rich:spacer height="10px" /> <a4j:commandButton value="Gruppe loeschen" reRender="table" action="#{adminGroupBean.takeSelection}" oncomplete="javascript:Richfaces.showModalPanel('MPSelRole');" /> </h:panelGrid> </h:panelGroup> </h:panelGrid> </a4j:form> <rich:modalPanel id="MPSelRole" autosized="true" zindex="200"> <f:facet name="header"> <h:outputText value="Selected Role" /> </f:facet> <f:facet name="controls"> <span style="cursor:pointer" onclick="javascript:Richfaces.hideModalPanel('MPSelRole')">X</span> </f:facet> <a4j:form> <rich:dataTable value="#{adminGroupBean.selectedRole}" var="sel" id="table" width="320px" > <rich:column id="ident2"> <f:facet name="header"><h:outputText value="Bezeichnung" /></f:facet> <h:outputText value="#{sel.ident}" /> </rich:column> <rich:column id="desc2"> <f:facet name="header"><h:outputText value="Beschreibung" /></f:facet> <h:inputText id="descEdit" value="#{sel.desc}" /> </rich:column> </rich:dataTable> <rich:spacer height="10px" /> <a4j:commandButton value="Speichern" action="#{adminGroupBean.modifyRole}" oncomplete="javascript:Richfaces.hideModalPanel('MPSelRole')" reRender="rolesList" /> <rich:spacer width="30px" /> <a4j:commandButton value="Abbrechen" onclick="javascript:Richfaces.hideModalPanel('MPSelRole')" /> </a4j:form> </rich:modalPanel> </rich:panel> <rich:spacer height="10px" /> <rich:panel id="PrivRoles"> <f:facet name="header"> <h:outputText value="Gruppen-Rechte-Zuordnungen" style="font-size: 120%; background-color: transparent;" /> </f:facet> <h:outputText value="Assignment Roles - Privileges" styleClass="infoMessage" /> </rich:panel> </rich:panel> </div> <rich:spacer height="20px" /> <div class="adminCloseButton"> <h:commandButton value="Schließen" onclick="#{rich:component('administrationMP')}.hide()" /> </div> </rich:modalPanel> </ui:composition> </html>
and following source code:
package com.as.seak.beans; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.classic.Session; import org.richfaces.component.UIScrollableDataTable; import org.richfaces.datatablescroller.Facet; import org.richfaces.model.selection.SimpleSelection; import com.as.seak.model.Role; import com.as.seak.utils.HibernateUtil; import com.as.seak.utils.Util; public class AdminGroupBean { private int infos; private String ident; private String desc; private SimpleSelection selection = new SimpleSelection(); private UIScrollableDataTable table; private ArrayList<Role> selectedRole = new ArrayList<Role>(); private ArrayList<Facet> columns = new ArrayList<Facet>(); private static int DECIMALS = 1; private static int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP; private List<Role> allRoles = null; public String takeSelection() { getSelectedRole().clear(); Iterator<Object> iterator = getSelection().getKeys(); while (iterator.hasNext()) { Object key = iterator.next(); table.setRowKey(key); if (table.isRowAvailable()) { getSelectedRole().add((Role) table.getRowData()); } } return null; } public void modifyRole() { saveRole(selectedRole.get(0)); reloadRoles(); } public static void saveRole(Role role) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = null; Transaction tx = null; try { session = sf.getCurrentSession(); tx = (Transaction) session.getTransaction(); session.update(role); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public void reloadRoles() { allRoles = null; allRoles = (List<Role>) Util.getDbEntries(Role.class); } public List<Role> getAllRoles() { if (null == allRoles) { allRoles = (List<Role>) Util.getDbEntries(Role.class); } return allRoles; } // somre more getters and setters // some methods are still missing }
Context: I have a modal panel where a scrollableDataTable is placed in and some buttons like new, edit... When clicking on a modify button the new modal panel appears with the correct data and I can edit them, when clicking on the save button the data will be saved to the DB, but the scrollableDataTable won't be rerendered.
How can I get this work?
I also have the problem that not always on the first click on a certain button the modal panel appears, but I have to click 2 or 3 times. Any idea for this issue?
I' appreciate Your help!! Thanks in advance.
Cheers, Peter