Primefaces tabView immediate=true nao funciona

3 respostas
R

Bom dia!
Tenho esse simples exemplo

<p:tabView  id="tabViewCadComplemento" activeIndex="#{complementoMB.indexTabCadComplemento}"  >		
        	<p:ajax  immediate="true" global="false" update="@this" listener="#{complementoMB.onTabChange}"  event="tabChange"/>
         
            <p:tab title="Complementos">	
             	<p:inputText></p:inputText>
            </p:tab>

            <p:tab title="Detalhes do Complemento">	
				<p:inputText required="true" requiredMessage=" bla bla bla"></p:inputText>
            </p:tab>

            <p:tab title="Tipo de Complemento">
   					   <p:inputText></p:inputText>
            </p:tab>
        </p:tabView>

Mesmo com o ajax immediate=“true” a menssagem do campo required e mostrada. Aparentemente esta passando pela faze de validacao.
Existe algum macete para usar o evento tabChange sem verificar os campo required ?

3 Respostas

L

Este componente possui a propriedade onTabChange por padrão.

Tente utilizá-la ao invés de adicionar um ajax event dentro da mesma.

R

o onTabChange ja tentei, ele chama apenas uma funcao javascript na tela. estou tentando contornar dessa forma.

<script type="text/javascript">
		var indexTab  =   0 ;
		function handleChange(index) {
			 indexTab =  index;
			 remoteCom();
		}	
		</script>
		<p:remoteCommand name="remoteCom" actionListener="#{complementoMB.onTabChange}" immediate="true" process="@this" >
			<f:setPropertyActionListener  target="#{complementoMB.indexTabCadComplemento}" value="#{indexTab}"/>
		</p:remoteCommand>
				
        <p:tabView  id="tabViewCadComplemento" widgetVar="tabViewCadComplemento" activeIndex="#{complementoMB.indexTabCadComplemento}" onTabChange="handleChange(index)"  >		
      // chamo o Js pego o index selecionado e chamo um remmote command

Blz, o metodo e chamado. porem a propiedade #{complementoMB.indexTabCadComplemento}" nao e setada.
tentei passar como <f:attribute name=“index” value=#{indexTab}/>
so que no backbean

public void onTabChange(ActionEvent evt) { System.out.println(evt.getComponent().getAttributes().containsKey("index")); // retorna FALSE!... System.out.println(evt.getComponent().getAttributes().get("indexT")); }

L

Tente usar o proprio evento tabChange do ajax então, como no exemplo do primefaces.
O fato de vc estar usando o immediate, está impedindo com que a propriedade seja setada.

Não teria como você usar o required somente quando o o usuario fosse postar o conteudo da aba?
Tipo, colocar o required como um booleano que fosse alterado em cada caso.

Se o usuário apenas trocasse de aba, sem modificar seu conteudo, o required seria falso.

<h:form id=form>  
  
    <p:growl id="growl" showDetail="true" />  
      
    <p:tabView id="tabView" dynamic="true">  
  
        <p:ajax event="tabChange" listener="#{tabBean.onTabChange}" update=":form:growl"/>  
  
        <p:tab title="Godfather Part I" id="Godfather1">  
            <h:panelGrid columns="2" cellpadding="10">  
                <p:graphicImage value="/images/godfather/godfather1.jpg" />  
                <h:outputText  
                    value="The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.  
                    His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. T  
                    hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect,  
                    but given to ruthless violence whenever anything stands against the good of the family." />  
            </h:panelGrid>  
        </p:tab>  
  
        <p:tab title="Godfather Part II" id="Godfather2">  
            <h:panelGrid columns="2" cellpadding="10">  
                <p:graphicImage value="/images/godfather/godfather2.jpg" />  
                <h:outputText value="Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, The_Godfather, parallels the young Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfather's depiction of the dark side of the American dream.  
                In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy,  
                killing the local Black Hand Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows."/>  
            </h:panelGrid>  
        </p:tab>  
  
        <p:tab title="Godfather Part III" id="Godfather3">  
            <h:panelGrid columns="2" cellpadding="10">  
                <p:graphicImage value="/images/godfather/godfather3.jpg" />  
                <h:outputText value="After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family.  
                    Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate."/>  
            </h:panelGrid>  
        </p:tab>  
  
    </p:tabView>  
  
</h:form>
Criado 26 de julho de 2012
Ultima resposta 26 de jul. de 2012
Respostas 3
Participantes 2