Mensagens com JSF

3 respostas
rafaelrodrigues1607

Pessoal, estava olhando alguns exemplos de como implementar mensagem de sucesso, avisos… enfim, mas não tive sucesso. Não aparece nada.

Um dos exemplos que vi é utilizando o código abaixo.

Já possuo um <h:messages> em minha aplicação. Alguma dica…

3 Respostas

joede.fadel

Poste o seu from. Pelo que me parece você está utilizando o ajax e não está atualizando o seu <h:messages>

rafaelrodrigues1607
Inicia quando eu clico em
<a4j:commandButton action="#{chuvaAction.carregaEstacoesSelecionadas}" image="/img/search.png" title="Inicia operações"
		        	 							reRender="listaChuvasEntity1, listaChuvasEntity2, txtMedia, txtDesvioPadrao, listaChuvasEntity3, listaChuvasEntity4, txtCalculoParcial, txtCoeficienteAssimetria, precipitacaoExtrema, messages">
		      	 							<a4j:status id="loading"  
									            onstart="Richfaces.showModalPanel('panel_loading')"   
									            onstop="Richfaces.hideModalPanel('panel_loading')" >  
						        			</a4j:status>
		       	 			</a4j:commandButton>

Aqui vai o meu form inteiro:

<!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:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
    xmlns:rich="http://richfaces.org/rich">
    
<h:form>
    	<rich:panel styleClass="rich-panel-filtro">
        	 <rich:panel style="border-color: white;">
	        	 <table>
	        	 	    <tr>
					       	<h:commandButton  image="/img/logoAna.png"/>
	        	 	    </tr>
		        	 	<tr>
			        	 	<td><h:outputText value="Porcentagem do Período Chuvoso:" /></td>
			        	 	<td>
			        	 		<h:inputText value="#{restricoes.porcentagemPeriodoChuvoso}" id="periodoChuvoso" size="1" maxlength="3" required="true"/>%
			        	 		<rich:message for="periodoChuvoso">
			                        <f:facet name="errorMarker">
			                            <h:graphicImage value="/img/error.gif" />   
			                        </f:facet>
			                    </rich:message>
			        	 	</td>
		        	 	</tr>
		        	 	
		        	 	<tr>
			        		<td><h:outputText value="Quantidade de dias Acumulados:" /></td>
			        	 	<td>
			        	 		<h:inputText value="#{restricoes.qtDiasAcumulados}" id="diasAcumulados" size="1" required="true"/>dias
			        	 		<rich:message for="diasAcumulados">
			                        <f:facet name="errorMarker">
			                            <h:graphicImage value="/img/error.gif" />   
			                        </f:facet>
			                    </rich:message>
			        	 	</td>
		        	 	</tr>
		        	 	
						<tr>
			        	 	<td><h:outputText value="Quantidade de Anos do Historico:" /></td>
			        	 	<td>
			        	 		<h:inputText value="#{restricoes.numeroAnosHistorico}" id="anosHistorico" size="1" required="true"/>anos
			        	 		<rich:message for="anosHistorico">
			                        <f:facet name="errorMarker">
			                            <h:graphicImage value="/img/error.gif" />   
			                        </f:facet>
			                    </rich:message>
			                </td>
						</tr>

	        	 		<tr>
		        	 		<td><h:outputText value="Informe o Número da Estação:" /></td>
		        	 		<td>
		        	 			<h:inputText value="#{chuvaAction.filtraEstacao}">
				        	 		<a4j:support event="onblur" action="#{chuvaAction.carregafiltroEstacao}" reRender="pickEstacao"></a4j:support>
				        	 	</h:inputText>
		        	 		</td>
		        	 	</tr>
		        	 	<!--tr>
			        	 	<td>
			        	 		<a4j:commandButton image="/img/search.png" title="Carregar Chuvas"
			        	 							reRender="listaChuvasEntity1, listaChuvasEntity2, txtMedia, txtDesvioPadrao, listaChuvasEntity3, listaChuvasEntity4, txtCalculoParcial, txtCoeficienteAssimetria, precipitacaoExtrema">
				        	 	</a4j:commandButton>
			        	 	</td>
			        	</tr-->
	        	 
		        	 <rich:pickList id="pickEstacao" value="#{chuvaAction.estacaoResultadoList}" copyAllControlLabel="Copiar todos" copyControlLabel="Copiar" removeAllControlLabel="Remover tudo" removeControlLabel="Remover">
			            <s:selectItems value="#{chuvaAction.estacoes}" var="estacao" label="#{estacao.codigoEstacao} - #{estacao.nome}" itemValue="#{estacao.codigoEstacao}"></s:selectItems>
			        </rich:pickList>
			        <tr>
       	 				<td>
			        		<a4j:commandButton action="#{chuvaAction.recuperaTodasEstacoes}" image="/img/refresh.png" title="Carregar todas as estações"
			        					reRender="pickEstacao, tableListaEstacoes, tableListaEstacoes1"></a4j:commandButton>
			        	</td>
			        	<td>
					        <a4j:commandButton action="#{chuvaAction.carregaEstacoesSelecionadas}" image="/img/search.png" title="Inicia operações"
		        	 							reRender="listaChuvasEntity1, listaChuvasEntity2, txtMedia, txtDesvioPadrao, listaChuvasEntity3, listaChuvasEntity4, txtCalculoParcial, txtCoeficienteAssimetria, precipitacaoExtrema, messages">
		      	 							<a4j:status id="loading"  
									            onstart="Richfaces.showModalPanel('panel_loading')"   
									            onstop="Richfaces.hideModalPanel('panel_loading')" >  
						        			</a4j:status>
		       	 			</a4j:commandButton> 
       	 				</td>
			       </tr>
	        	 </table>	
        	 </rich:panel>
        </rich:panel>
        
        <div style="float:right">
   			<ui:include src="/TabPanel.xhtml" />
   		</div>
   		
        <rich:panel styleClass="rich-panel-filtro">
        	 <rich:panel style="border-color: white;">
	        	 <table>
	        	 	<tr>
	        	 		<td><h:outputText value="Resultados:" style="font-weight: bold;font-size:18px;text-decoration: underline;"/></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<td><h:outputText value="Média das Chuvas:" style="font-weight: bold;"/></td>
	        	 		<td>
	        	 			<h:outputText id="txtMedia" value="#{chuvaAction.media}">
	        	 				<f:convertNumber maxFractionDigits="1" />
	        	 			</h:outputText>
	        	 		</td>
	        	 	</tr>
	        	 	
	        	 	<tr>
	        	 		<td><h:outputText value="Desvio Padrão:" style="font-weight: bold;"/></td>
	        	 		<td>
	        	 			<h:outputText id="txtDesvioPadrao" value="#{chuvaAction.desvioPadrao}">
	        	 				<f:convertNumber maxFractionDigits="1" />
	        	 			</h:outputText>
	        	 		</td>
	        	 	</tr>
	        	 	
	        	 	<!--tr>
	        	 		<td><h:outputText value="Cálculo Parcial:" style="font-weight: bold;"/></td>
	        	 		<td>
	        	 			<h:outputText id="txtCalculoParcial" value="#{resultados.calculoParcial}">
	        	 				<f:convertNumber maxFractionDigits="5" />
	        	 			</h:outputText>
	        	 		</td>
	        	 	</tr-->
	        	 	
	        	 	<tr>
	        	 		<td><h:outputText value="Coeficiente de Assimetria:" style="font-weight: bold;"/></td>
	        	 		<td>
	        	 			<h:outputText id="txtCoeficienteAssimetria" value="#{resultados.coeficienteAssimetria}" style="color:red;font-weight: bold;">
	        	 				<f:convertNumber maxFractionDigits="4" />
	        	 			</h:outputText>
	        	 		</td>
	        	 	</tr>
	        	 	<!-- tr>
	        	 		<td></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<td><h:outputText value="Legenda:" style="font-weight: bold;font-size:15px;text-decoration: underline;"/></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<td><h:outputText value="Xi = Dado amostral"/></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<td><h:outputText value="Xmed = Média aritmética da amostra"/></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<td><h:outputText value="DP = Desvio padrão da amostra"/></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<td><h:outputText value="N = nº de elementos da amostra"/></td>
	        	 	</tr-->
	        	 </table>	
        	 </rich:panel>
        </rich:panel>
        
        <rich:panel style="border-color: white;">
        	<h:commandButton  image="/img/mapa_periodo.png" />
        </rich:panel>
   		
   		<rich:modalPanel id="panel_loading" autosized="true">
			<h:graphicImage url="/img/loading.gif" style="border:0px; vertical-align: middle;" />
				<rich:spacer width="20" /><br/>
				<h:outputText value="Carregando... Aguarde!" />
		</rich:modalPanel>
		
		<rich:modalPanel id="msgsErros" autosized="true" showWhenRendered="#{facesContext.maximumSeverity !=null}">  
		     <f:facet name="header">  
		            <h:outputText value="Mensagem" />  
		     </f:facet>  
		     <f:facet name="controls">  
		           <h:panelGroup>  
		               <h:graphicImage url="/imagens/icones/close.png" style="cursor: pointer; margin-top: 5px;" id="mensagens" width="20"/>  
		                <rich:componentControl for="msgsErros" attachTo="mensagens" operation="hide" event="onclick" />  
		           </h:panelGroup>  
		     </f:facet>  
		     <table class="blank" style="font-size: 10pt; white-space: nowrap">  
		           <rich:messages>  
		               <f:facet name="errorMarker">  
		                     <h:graphicImage url="/imagens/icones/excluir.png" width="20" height="20"/>  
		               </f:facet>  
		               <f:facet name="warnMarker">  
		                     <h:graphicImage url="/imagens/icones/atencao.png" width="20" height="20"/>  
		               </f:facet>  
		               <f:facet name="infoMarker">  
		                     <h:graphicImage url="/imagens/icones/apply.png" width="20" height="20"/>  
		               </f:facet>  
		           </rich:messages>  
		      </table>  
		</rich:modalPanel>
		
		<f:subview id="modalErrorAssUser">  
            <a4j:include viewId="modalError.xhtml" />  
        </f:subview>
        
</h:form>        
		
</ui:composition>
joede.fadel

Tente colocar um id no messages, eu não trabalho com RichFaces, e sim com PrimeFaces, e para eu exibir atualizar o messages eu tenho que definir um id para ele e não somente colocar a tag.

Criado 26 de junho de 2012
Ultima resposta 26 de jun. de 2012
Respostas 3
Participantes 2