Problemas com ActionListener

4 respostas
J

Pessoal estou tentando chamar uma actionListener dentro de um h:commandLink porém não estou tendo sucesso.
Quando mudo para a4j:commandLink o evento é chamado porém o rich:modalPanel abre e fecha rapidamente, já tentei várias soluções aqui do fórum como por exemplo tirar o modalPanel de dentro de form principal e colocar outro form dentro mas o problema continua.
Preciso de um help ja perdi muito tempo tentando resolver esse problema.

Segue o código.

<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<html>
	<f:subview id="Cronograma">
		 <h:form>
			    <h:panelGroup id="cronograma" style="text-align: center">
					
						<table width="80%" align="center" cellspacing="0" style="border-width: 1px; border-style: solid">
						    <tr>
						        <td colspan="4" align="left"><font size="5"><h:outputText value="Cronograma" /></font><br /></td>
						    </tr>			
							<tr>
							    <td><h:outputText value="Filtrar por:"/></td>
								<td>
								    <h:selectOneMenu>
								         <f:selectItem itemLabel="Todos" itemValue=""/>
								         <f:selectItem itemLabel="Nome" itemValue=""/>
								         <f:selectItem itemLabel="Data inclusão" itemValue=""/>
								         <f:selectItem itemLabel="Data término" itemValue=""/>								         			        
								    </h:selectOneMenu> 
								</td>
								
								<td>
									<h:inputText value="" size="40" />
									&nbsp;<h:graphicImage id="imgFil" url="/imagens/btlLupa.png" style="border:0" title="Pesquisar"/>
								</td>
							</tr>	
							<tr>
								<td>									
									<h:graphicImage title="Adicionar Tarefa"  id="imgEnt" url="/imagens/btlAdd.gif" style="border:0" onclick="#{rich:component('mpTarefa')}.show()" />
								</td>
							</tr>	
							<tr>
							    <td colspan="6">
										
								<rich:dataTable value="#{tarefaMB.listaTarefas}" var="tarefa" rows="10"
								onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
		                  		onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
							    columnsWidth="50%,10%,10%,20%,5%,5%" id="lstTarefas"
							    style="align:center">
							    
							    <f:facet name="header">
							      <rich:columnGroup>
							        <rich:column>
							          <h:outputText value="Título"/> 
							        </rich:column>
							        
							        <rich:column>
							            <h:outputText value="Data inicial" />
							        </rich:column>             
							        
							        <rich:column>
							          <h:outputText value="Data término" />
							        </rich:column>    
							        
							        <rich:column>
							          <h:outputText value="Status" />
							        </rich:column>    
							        
							               
							        
							        <rich:column/>
							        <rich:column/>      
							        <rich:column/>   
							       
							                    
							      </rich:columnGroup>           
							    </f:facet>
							      
							    <rich:column  style="background-color:#EEEEE0">
							      <h:outputText value="#{tarefa.tituloTar}" />
							    </rich:column>
							    
							    <rich:column  style="background-color:#EEEEE0">
							      <h:outputText value="#{tarefa.dataInicialTar}">
							      	<f:convertDateTime type="date" pattern="dd/MM/yyyy" dateStyle="medium"/>
							      </h:outputText>	
							    </rich:column>
							    
							    <rich:column  style="background-color:#EEEEE0">
							      <h:outputText value="#{tarefa.dataTerminoTar}">
							      	<f:convertDateTime type="date" pattern="dd/MM/yyyy" dateStyle="medium"/>
							      </h:outputText>		
							    </rich:column>
							    
							    <rich:column  style="background-color:#EEEEE0">
							      <h:outputText value="#{tarefa.statusTar}" />
							    </rich:column>
		
			                    <rich:column  style="background-color:#EEEEE0;align:center" >
									<h:commandLink>
										<h:graphicImage id="imgEdt" url="/imagens/btlEdit.png" 	style="border:0" title="Editar Tarefa"/>									
									</h:commandLink>
								</rich:column>
								
								<rich:column  style="background-color:#EEEEE0;align:center">
									<h:commandLink >
										<h:graphicImage id="imgDel" url="/imagens/btlDelete.png"  style="border:0" title="Excluir Tarefa"/>									
									</h:commandLink>
								</rich:column>
								
								<rich:column  style="background-color:#EEEEE0;align:center">	
									<h:commandLink    actionListener="#{tarefaMB.changeSelectedTerefa}" >
										<h:graphicImage   id="imgNew" url="/imagens/btlAddAtividade.gif" 	style="border:0" title="Incluir Atividade" onclick="#{rich:component('mpAtividade')}.show()" />
									</h:commandLink>															
								</rich:column>


						<rich:subTable value="#{tarefa.listaAtividades}" var="atividade" 
							      onRowMouseOver="this.style.backgroundColor='#E0E0E0'"							      
							      onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
							     
							      
							      <f:facet name="header">
							      <rich:columnGroup>
							        <rich:column width="50%">
							          <h:outputText value="Título"/> 
							        </rich:column>
							        
							        <rich:column width="10%" >
							          <h:outputText value="Data Inicial"/>						          		
							        </rich:column>
							        
							        <rich:column width="10%">
							          <h:outputText value="Data Término"/> 		 		
							        </rich:column>
							        
							        <rich:column width="20%">
							          <h:outputText value="% Concluído"/>
							        </rich:column>   
							        
							        
							        <rich:column  style="align:center"/>
							        <rich:column  style="align:center"/>
							        <rich:column  style="align:center"/>
							       
							                    
							      </rich:columnGroup>           
							    </f:facet>
							
							     <rich:column style="align:center">
							        <h:outputText value="#{atividade.tituloAti}" />
							     </rich:column>
							     
							     <rich:column style="align:center">
							        <h:outputText value="#{atividade.dataInicialAti}">
							        	<f:convertDateTime type="date" pattern="dd/MM/yyyy" dateStyle="medium"/>
							        </h:outputText>	
							        	
							     </rich:column>   
							      
							     <rich:column style="align:center">
							        <h:outputText value="#{atividade.dataConclusaoAti}">
							        	<f:convertDateTime type="date" pattern="dd/MM/yyyy" dateStyle="medium"/>
							        </h:outputText>	
							     </rich:column>      
							     
							     <rich:column>
							        <h:outputText value="#{atividade.percentConcluAti}" />
							     </rich:column>
							      
							     		      							              
							      <rich:column >
							        <h:commandLink>
										<h:graphicImage id="imgEdt" url="/imagens/btlEdit.png" 	style="border:0" />									
									</h:commandLink>
							      </rich:column>
							      
							      <rich:column >
								      <h:commandLink>
											<h:graphicImage id="imgDel" url="/imagens/btlDelete.png" 	style="border:0" />									
									  </h:commandLink>
							      </rich:column>
							      
							      <rich:column></rich:column>
							    </rich:subTable>             
							  </rich:dataTable>
										                 			                
							</td>								
						</tr>
						    <tr>
					    	<td colspan="6" align="center">
					    	    <br/>
					    	    <rich:datascroller  for="lstTarefas"></rich:datascroller>		    		
					    		
					    	</td>
					    </tr>	
			
					</table>
			</h:panelGroup>	
		
      		<!--  Panel tarefa -->
      		
			<rich:modalPanel id="mpTarefa" resizeable="true" height="310" width="600" zindex="1000">		
				
				<table>
					<f:facet  name="header">
						<h:outputText value="Tarefa"/>
					</f:facet>
					
					<tr>
						<td><h:outputText value="Titulo" /></td>
						<td><h:inputText value="#{tarefaMB.tarefa.tituloTar}" size="40" /></td>
					</tr>
					<tr>
						<td><h:outputText value="Data Inicial" /></td>						
						<td><rich:calendar value="#{tarefaMB.tarefa.dataInicialTar}" locale="pt_BR"  datePattern="dd/MM/yyyy"
                        		cellWidth="24px" cellHeight="22px" style="width:200px"/>
               			 </td>
					</tr>
					<tr>
						<td><h:outputText value="Data término" /></td>						
						<td><rich:calendar value="#{tarefaMB.tarefa.dataTerminoTar}" locale="pt_BR"  datePattern="dd/MM/yyyy"
                        		cellWidth="24px" cellHeight="22px" style="width:200px"/>
               			 </td>
					</tr>
					<tr>
						<td><h:outputText value="Descrição" /></td>
						<td>
						    <h:inputTextarea value="#{tarefaMB.tarefa.descricaoTar}" rows="4" cols="40"></h:inputTextarea>
					    </td>
					</tr>					
					<tr>
						<td>
						 	<h:commandButton value="Enviar" action="#{tarefaMB.incluirTarefa}" onclick="#{rich:component('mpTarefa')}.hide()">
						 		<a4j:support event="onsubmit" reRender="lstTarefas" ></a4j:support>
						 	</h:commandButton> 
							<h:commandButton value="Cancelar" onclick="#{rich:component('mpTarefa')}.hide()" />
						</td>
					</tr>
				</table>
			
			</rich:modalPanel>
			
		
		

           <!-- Panel de Atividade -->
     
	
			<rich:modalPanel id="mpAtividade" resizeable="false"  height="250" width="600" zindex="1000"  onshow="#{rich:component('mpAtividade')}.show()">
			
				<table>
					<f:facet  name="header">
						<h:outputText value="Atividade"/>
					</f:facet>
					
				
					
					<tr>
						<td><h:outputText value="Titulo" /></td>
						<td><h:inputText value="#{tarefaMB.atividade.tituloAti}" size="40" /></td>
					</tr>
					<tr>
						<td><h:outputText value="Data Inicial" /></td>
						<td><rich:calendar value="#{tarefaMB.atividade.dataInicialAti}" locale="pt_BR"  datePattern="dd/MM/yyyy"
                        		cellWidth="24px" cellHeight="22px" style="width:200px"/>
               			</td>
					</tr>
					<tr>
						<td><h:outputText value="Data término" /></td>
						<td><rich:calendar value="#{tarefaMB.atividade.dataConclusaoAti}" locale="pt_BR"  datePattern="dd/MM/yyyy"
                        		cellWidth="24px" cellHeight="22px" style="width:200px"/>
               			 </td>
					</tr>
					<tr>
						<td><h:outputText value="Descrição" /></td>
						<td>
						    <h:inputTextarea value="#{tarefaMB.atividade.descricaoAti}" rows="4" cols="40"></h:inputTextarea>
					    </td>
					</tr>					
					<tr>
						<td>
						 	<h:commandButton action="#{tarefaMB.incluirAtividade}"  value="Enviar"  onclick="#{rich:component('mpAtividade')}.hide()">
						 		<a4j:support event="onsubmit" reRender="lstTarefas" ></a4j:support>
						 	</h:commandButton> 
							<h:commandButton value="Cancelar" onclick="#{rich:component('mpAtividade')}.hide()" />
						</td>
					</tr>
					
				
				</table>
			
			</rich:modalPanel>	
		</h:form>
</f:subview>
</html>

Obs: o problema ocorre apenas no modalPanel atividade quando é usado o a4j:commandLink.

4 Respostas

Luiz_Gustavo

Estou com o mesmo problema. Você conseguiu solicionar?

Abraços!

J

Quando uso a4j:commandLink o evento é chamado porém o rich:modalPanel abre e fecha rapidamente, como tinha pouco tempo pra entregar o trabalho desisti de usar o rich:modalPanel, mas tive amigos que não tiveram esse problema usando facelets.

Ta aí uma possível solução, tentar usar com facelets.

Abraços

Luiz_Gustavo

Opa, tudo bem?

acabei de postar e consegui fazer funcionar. Também estou usando Facelets.
Meu problema era que o actionListener do a4j:commandLink dentro do dataTable não era chamado. Acabei deixando como action mesmo. Eis o código, para consulta:

<ui:define name="body">
	<h:form id="index">

		<a4j:jsFunction name="ajaxSubmit" oncomplete="#{rich:component('panelCadCidade')}.show()" reRender="editContent" />
	<table width="100%" align="center">            						
			<tr align="left">
		<td>
					<fieldset>
						<legend>
							<h:outputText value="#{msg.lblVisaoCidade}" styleClass="labelStyle"/>
						</legend>


						<table width="100%" border="0">
							<tr>
								<td align="right" width="20%">
									<h:outputLabel value="#{msg.lblPais}" for="cboPaisL" styleClass="textBold"/>														
								</td>
								<td align="left" colspan="2">
									<h:selectOneMenu id="cboPaisL" value="#{cidadeFace.selAtPaisL}" styleClass="combo">
										<a4j:support event="onchange" action="#{cidadeFace.comboPaisLChange}" reRender="cboEstadoL, grdCidades"/>
										<f:selectItems value="#{cidadeFace.itensCboPais}"/>
									</h:selectOneMenu>
								</td>										
							</tr>
							<tr>
								<td align="right">
									<h:outputLabel value="#{msg.lblEstado}" for="cboEstadoL" styleClass="textBold"/>														
								</td>
								<td align="left" colspan="2">
									<h:selectOneMenu id="cboEstadoL" value="#{cidadeFace.selAtEstadoL}" styleClass="combo">
										<a4j:support event="onchange" action="#{cidadeFace.comboEstadoLChange}" reRender="grdCidades"/>
										<f:selectItems value="#{cidadeFace.itensCboEstado}"/>
									</h:selectOneMenu>
								</td>										
							</tr>
							<tr>
								<td align="right">
									<h:outputLabel value="#{msg.lblCidade}" for="txtCidadeL" styleClass="textBold"/>
								</td>
								<td align="left">
									<h:inputText id="txtCidadeL" value="#{cidadeFace.citNameL}" styleClass="text" size="60"/>
								</td>
								<td align="left">											
									<a4j:commandButton value="#{msg.lblBtnPesquisar}" action="#{cidadeFace.listarPesquisa}" reRender="grdCidades, scrollerGrdCidades"/>
								</td>										
							</tr>
						</table>								
					</fieldset>
		</td>
	</tr>            						
		<tr>
		<td>
			<rich:dataTable width="100%" id="grdCidades" var="city" value="#{cidadeFace.cidades}" 
						rowClasses="grid1,grid2" rows="#{cidadeFace.paginacao}">

							<f:facet name="header">									            		
								<rich:columnGroup>		

									<rich:column>
										<h:outputText value="#{msg.lblColumnSelecao}"/>
									</rich:column>

									<rich:column>
										<h:outputText value="#{msg.lblColumnCidades}"/>
									</rich:column>

								</rich:columnGroup>
							</f:facet>

							<rich:column>
								<h:selectBooleanCheckbox value="#{city.marked}" id="citCheck"/>
							</rich:column>

							<rich:column>          	
								<a4j:commandLink value="#{city.citName}" 
									action="#{cidadeFace.alterar}"
									oncomplete="ajaxSubmit();">
							<f:param value="#{city.citId}" name="citID"/>
							<f:param value="#{city.citName}" name="citNAME"/>
						</a4j:commandLink>
							</rich:column>

					</rich:dataTable>



					<rich:spacer height="15"/>

					<rich:datascroller id="scrollerGrdCidades" for="grdCidades" maxPages="10" 
					renderIfSinglePage="false" rendered="true"/>

		    </td>
		</tr>  

		<tr>
		<td align="center">
			<h:messages layout="table" showDetail="true" showSummary="false" styleClass="error"/>
		</td>
	</tr>
		<tr>
			<td align="right">
				<a4j:commandButton value="#{msg.lblBtnIncluir}" 
					oncomplete="ajaxSubmit();" 
					actionListener="#{cidadeFace.cadastrar}" 
					reRender="editContent"/>

				<h:commandButton value="#{msg.lblBtnExcluir}" 
					onclick="#{msg.lblMensagemConfirmacao}" 
					action="#{cidadeFace.excluir}" 
					reRender="grdCidades"/>	       					
			</td>
		</tr>
		</table>	
	</h:form>


	<rich:modalPanel id="panelCadCidade" resizeable="false" height="150" width="500" moveable="false" >
		<f:facet name="header">
			<h:outputText value="#{msg.lblDetalheCidade}" styleClass="labelStyle"/>
		</f:facet>
		<h:form>
		    <h:panelGrid id="editContent" columns="3" width="100%">


					<h:outputLabel value="#{msg.lblCidade}" for="txtCidadeD" styleClass="textBold"/>
					<h:inputText id="txtCidadeD" value="#{cidadeFace.citNameD}" styleClass="required" maxlength="50" size="60">
						<f:attribute name="nomeCampo" value="#{bundleFace.lblCidade}"/>
					</h:inputText>							
					<h:graphicImage url="/images/campo_obrigatorio.png" title="#{msg.lblCampoObrigatorio}" border="0"/>				

					<h:outputLabel value="#{msg.lblPais}" for="cboPaisD" styleClass="textBold"/>														
					<h:selectOneMenu id="cboPaisD" value="#{cidadeFace.selAtPaisD}" styleClass="required">
						<a4j:support event="onchange" action="#{cidadeFace.comboPaisDChange}" reRender="cboEstadoD"/>
						<f:selectItems value="#{cidadeFace.itensCboPais}"/>
					</h:selectOneMenu>							
					<h:graphicImage url="/images/campo_obrigatorio.png" title="#{msg.lblCampoObrigatorio}" border="0"/>				

					<h:outputLabel value="#{msg.lblEstado}" for="cboEstadoD" styleClass="textBold"/>														
					<h:selectOneMenu id="cboEstadoD" value="#{cidadeFace.selAtEstadoD}" styleClass="required">
						<a4j:support event="onchange" action="#{cidadeFace.comboEstadoDChange}" />
						<f:selectItems value="#{cidadeFace.itensCboEstado}"/>
					</h:selectOneMenu>							
					<h:graphicImage url="/images/campo_obrigatorio.png" title="#{msg.lblCampoObrigatorio}" border="0"/>				


		    </h:panelGrid>		            

			<table width="100%" cellspacing="2"  cellpadding="2">
				<tr>
					<td align="right">
						<a4j:commandButton 
							value="#{msg.lblBtnConfirmarContinuar}" 
							action="#{cidadeFace.confirmarContinuar}" 
							reRender="editContent, grdCidades"/>	            		
					</td>
					<td align="right">
						<a4j:commandButton 
							value="#{msg.lblBtnCancelar}" 
							actionListener="#{cidadeFace.cancelar}" 
							oncomplete="#{rich:component('panelCadCidade')}.hide()"
							reRender="grdCidades"/>
					</td>
					<td align="right">
						<a4j:commandButton 
							value="#{msg.lblBtnConfirmarVoltar}" 
							action="#{cidadeFace.confirmar}" 
							oncomplete="#{rich:component('panelCadCidade')}.hide()"
							reRender="grdCidades"/>
					</td>		            	
				</tr>
			</table>

		    <h:panelGrid id="editMessages" columns="1" width="100%">
				<h:messages layout="table" showDetail="true" showSummary="false" styleClass="error"/>
		    </h:panelGrid>       
		</h:form>
	</rich:modalPanel>

</ui:define>

Abraço!

B

Bom dia.

no seu <a4j:commandButton utilize
status=“commonstatus”>

Criado 15 de novembro de 2008
Ultima resposta 23 de mar. de 2011
Respostas 4
Participantes 3