rich:modalPannel + validation + DataModelSelection
ivpu Jun 2, 2008 2:40 PMHi, I have rich:modalPannel from dataTable. I'm using DataModelSelection to open modalPannel and in modalPannel I want to edit sample input.
If I have a validation error, I want cancel this form and select other item from table, but in modalPanel is previous item and I don't know, how to rerender this.
My code:
ProjectManager.java
import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.datamodel.DataModel; import org.jboss.seam.annotations.datamodel.DataModelSelection; import org.jboss.seam.ScopeType; import javax.ejb.Stateless; import javax.persistence.PersistenceContext; import javax.persistence.EntityManager; import java.util.List; import sk.bgs.controlling.entity.Project; import sk.bgs.controlling.entity.User; @Stateless @Name(value = "project") @Scope(value = ScopeType.PAGE) public class ProjectManager implements ProjectManagerLocal { @In private User thisUser; @DataModel private List<Project> projectList; @DataModelSelection @Out(required=false) private Project currentProject; private Boolean completed = Boolean.FALSE; @PersistenceContext private EntityManager em; public void setCompleted(Boolean completed) { this.completed = completed; } public Boolean isCompleted() { return completed; } @Factory("projectList") public void projectList() { projectList = em.createQuery("select x from Project x").getResultList(); for (Project proj : projectList) { if (thisUser.getMarkedProjects().contains(proj.getId())) { proj.setMarked(Boolean.TRUE); } } } public void createProject() { currentProject = new Project(); currentProject.setCreator(thisUser.getId()); } public void editProject() { if (currentProject.getId() != null) { em.merge(currentProject); } else { em.persist(currentProject); } projectList(); } public void markProject() { if (currentProject.getMarked()) { thisUser.getMarkedProjects().add(currentProject.getId()); } else { thisUser.getMarkedProjects().remove(currentProject.getId()); } em.merge(thisUser); } public void fake() { } }
list.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition 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:s="http://jboss.com/products/seam/taglib" xmlns:a="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" template="template.xhtml"> <ui:define name="page-title">Projects</ui:define> <ui:define name="content"> <ui:include src="projectEdit.xhtml"/> <div class="section"> <h:form id="projectTable"> <a:commandButton value="Add project" action="#{project.createProject}" reRender="projectEdit" oncomplete="Richfaces.showModalPanel('projectPanel')"/> <h:dataTable var="item" value="#{projectList}"> <h:column> <f:facet name="header">ISO code</f:facet> <h:outputText value="#{item.code}"/> </h:column> <h:column> <f:facet name="header">Name</f:facet> <a:commandLink action="#{project.fake}" oncomplete="Richfaces.showModalPanel('projectPanel')" value="#{item.name}" reRender="projectEdit"/> </h:column> <h:column> <f:facet name="header">Customer</f:facet> <h:outputText value="#{item.customer}"/> </h:column> <h:column> <f:facet name="header">Created</f:facet> <h:outputText value="#{item.created}"/> </h:column> <h:column> <f:facet name="header">Stop date</f:facet> <h:outputText value="#{item.stop}"/> </h:column> <h:column> <f:facet name="header">Marked</f:facet> <h:selectBooleanCheckbox id="marked" value="#{item.marked}"> <a:support event="onclick" action="#{project.markProject}"/> </h:selectBooleanCheckbox> </h:column> </h:dataTable> </h:form> </div> </ui:define> </ui:composition>
projectEdit.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition 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:s="http://jboss.com/products/seam/taglib" xmlns:a="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <a:outputPanel ajaxRendered="true"> <h:form style="display:none" prependId="false"> <h:inputHidden id="maximumSeverity" value="#{facesContext.maximumSeverity.ordinal}"/> </h:form> </a:outputPanel> <script type="text/javascript"> function ajaxRequestContainsErrors() { return document.getElementById("maximumSeverity").value == "2"; } </script> <rich:modalPanel id="projectPanel" autosized="true" width="820"> <f:facet name="header"> <h:outputText value="Editacia projektu"/> </f:facet> <a:form id="projectEdit"> <fieldset> <s:decorate id="codeDecorate" template="edit.xhtml"> <ui:define name="label">ISO code:</ui:define> <h:inputText id="code" value="#{currentProject.code}" maxlength="24" size="30" required="true"/> </s:decorate> <s:decorate id="nameDecorate" template="edit.xhtml"> <ui:define name="label">Name:</ui:define> <h:inputText id="name" value="#{currentProject.name}" maxlength="64" size="68"/> </s:decorate> <s:decorate id="customerDecorate" template="edit.xhtml"> <ui:define name="label">Customer:</ui:define> <h:inputText id="customer" value="#{currentProject.customer}" maxlength="64" size="68"/> </s:decorate> <s:decorate id="startDecorate" template="edit.xhtml"> <ui:define name="label">Start date:</ui:define> <rich:calendar firstWeekDay="1" value="#{currentProject.start}" id="startDate" datePattern="dd.MM.yyyy" locale="#{localeSelector.locale}" showApplyButton="false" showFooter="false" showWeeksBar="false" showWeekDaysBar="false"/> </s:decorate> <s:decorate id="stopDecorate" template="edit.xhtml"> <ui:define name="label">Stop date:</ui:define> <rich:calendar firstWeekDay="1" value="#{currentProject.stop}" id="stopDate" datePattern="dd.MM.yyyy" locale="#{localeSelector.locale}" showApplyButton="false" showFooter="false" showWeeksBar="false" showWeekDaysBar="false"/> </s:decorate> <s:decorate id="estDecorate" template="edit.xhtml" rendered="#{s:hasRole('manager') || s:hasRole('sales')}"> <ui:define name="label">Estimation:</ui:define> <h:inputText id="estimation" value="#{currentProject.estimation}" maxlength="8" size="12"/> </s:decorate> <s:decorate id="descDecorate" template="edit.xhtml"> <ui:define name="label">Description:</ui:define> <h:inputText id="desc" value="#{currentProject.description}" maxlength="512" size="80"/> </s:decorate> <div class="buttonBox"> <s:button id="cancel" action="cancel" value="Storno"> <rich:componentControl for="projectPanel" event="onclick" operation="hide"/> </s:button>   <a:commandButton id="submit" action="#{project.editProject}" reRender="projectEdit" oncomplete="if (!ajaxRequestContainsErrors()) Richfaces.hideModalPanel('projectPanel');" value="Submit"/> </div> </fieldset> </a:form> </rich:modalPanel> </ui:composition>
edit.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition 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:s="http://jboss.com/products/seam/taglib"> <div class="entry"> <s:label styleClass="label #{invalid?'errors':''}"> <ui:insert name="label"/> <s:span styleClass="required" rendered="#{required}">*</s:span> </s:label> <span class="input #{invalid?'errors':''}"> <s:validateAll> <ui:insert/> </s:validateAll> </span> <s:message styleClass="error errors"/> </div> </ui:composition>
Can you help me? Thank's