One of the frequently asked questions is how to prevent modal panel from closure if the validation inside fails. Here is a very simple code to provide such behaviour.
<ui:define name="body">
<f:verbatim>
<a href="javascript:Richfaces.showModalPanel('_panel',{left:'auto', top:'auto'})">
Show Modal Panel
</a>
</f:verbatim>
<rich:modalPanel id="_panel">
<f:facet name="header">
<h:outputText value="test"></h:outputText>
</f:facet>
<h:form id="mpform">
<a4j:outputPanel ajaxRendered="true">
<h:messages id="error"></h:messages>
</a4j:outputPanel>
<h:inputText value="#{bean.property}" required="true"></h:inputText>
<a4j:commandLink value="click" oncomplete="windowclose();"
reRender="test" />
</h:form>
</rich:modalPanel>
<script type="text/javascript">
//<![CDATA[
function windowclose(){
if (document.getElementById('mpform:error')==null){
Richfaces.hideModalPanel('_panel');
};
};
//]]>
</script>
</ui:define>
All that we perform inside the panel - we check whether the messages are created on a page. And if the messages don't appear, just close the window. In the other case nothing is done, so the window stays with the messages inside.
See also solution #2
Other languages:
Log in to make links between pages