JSF + Tela não renderiza alguns campos ao salvar, validar campos não preenchidos

Pessoal, boa noite.

Vê se vocês podem me ajudar. Tou com a seguinte situação.
Estou usando Seam + JSF+Hibernate.
Possuo um formulário com alguns campos requeridos (required=true).
E a situação ocorre quando tento “zerar”(Limpar) meu formulário.

Caso eu acesse o primeiro campo requerido e digite alguma informação e deixe os outros em branco, ao clicar em salvar é apresentado na tela a validação dos campos que não foram preenchidos, até aí tudo bem. Porém, se eu clicar em NOVO(limpar o formulario . Meu bean Instancea o objeto novamente new Objeto()) todos os campos voltam a ficar em branco MENOS o campo inicial.

O que fazer para que ele renderize esse campo com o novo valor do Bean?

Formulario

<a4j:form>

<a4j:region id="regiaotitulos" renderRegionOnly="true" >
			<rich:panel id="paneldadostitulo" >
			<f:facet name="header">
				<h:outputText value="Dados do titulo" />
			</f:facet>
			
				<h:panelGrid columns="2" id="gridtitulos">
					<h:panelGrid columns="1" id="panelintDadosmov">
						<a4j:region id="docTst">
						<s:decorate id="docDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Documento" />	
								</ui:define>
						
							<h:inputText id="mov_doc" value="#{movimentacaohandler.movimentacao.doc}" 
								readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"
								style="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm  ? 'color :gray;' : ''  }" 
								required="true" >
	         				</h:inputText>
	         				
						</s:decorate>
						</a4j:region>
						
						<s:decorate id="nomeDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Parcela" />
	                    	</ui:defi
	                    	ne>
							
							<h:inputText id="mov_parcela" value="#{movimentacaohandler.movimentacao.parcela}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" style="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm  ? 'color :gray;' : ''  }">
	         				</h:inputText>
	         			</s:decorate>
						
							<s:decorate id="tipodocDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Tipo" />
								</ui:define>
						
								<h:selectOneMenu id="tipo_doc" value="#{movimentacaohandler.idtipodoc}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" style="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm  ? 'color :gray;' : ''  }" required="true"	>
									<f:selectItem itemValue="0" itemLabel="Selecione" />
					    			<f:selectItems id="choseDoc" value="#{tipodochandler.comboTipoDoc}"  />
					    		</h:selectOneMenu>
				    		</s:decorate>
						
						
						<s:decorate id="dtVencDocDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Data Vencimento Documento" />	
								</ui:define>
						        
						        <rich:calendar id="data_venc_doc" value="#{movimentacaohandler.movimentacao.datavencimentodocumento}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" 
		                        datePattern="dd/MM/yyyy" enableManualInput="true" cellWidth="24px" cellHeight="22px" style="width:200px" required="true" requiredMessage="Data de vencimento requerida.">
		                        <a4j:support event="onkeypress" action="return tabEnter(this, event);" />
		                        <a4j:support reRender="paneldadostitulo" immediate="true"
											event="oninputchange"  limitToList="true" 
											eventsQueue="keypressQueue" />
		                    </rich:calendar>
		                 </s:decorate>
						
						
						<s:decorate id="vloriginalDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Valor original" />	
								</ui:define>
						        
								<h:inputText id="valor_origi_mov" required="true" value="#{movimentacaohandler.movimentacao.valormovimento}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"
								 requiredMessage="Campo obrigatorio">
									<f:converter converterId="MyDoubleConverter" />
		         					<a4j:support event="onblur" reRender="vloriginalDisplay,paneldadostitulojuros"/> 
								</h:inputText>
						</s:decorate>
						
						
						<s:decorate id="dtEscritDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Data Vencimento Escritorio" />	
								</ui:define>
								
							    <rich:calendar id="dt_venc_esc" value="#{movimentacaohandler.movimentacao.datavencimentodocartorio}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"
			                        datePattern="dd/MM/yyyy" enableManualInput="true" cellWidth="24px" cellHeight="22px" style="width:200px" required="true" requiredMessage="Data requerida." >
			                        <a4j:support event="onkeypress" action="return tabEnter(this, event);" />
			                        <a4j:support reRender="paneldadostitulojuros"
												event="onchange" limitToList="true" 
												eventsQueue="keypressQueue" />
		                        </rich:calendar>
						</s:decorate>
												
						
						<s:decorate id="perjurosDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Perc. Juros(%)" />
	                    	</ui:define>
	                    	
							<h:inputText id="perc_juros_def" value="#{movimentacaohandler.movimentacao.percjurosdefault}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}">
								<f:converter converterId="MyDoubleConverter" />
	         					<a4j:support event="onblur"  reRender="paneldadostitulojuros,perc_juros_def" />
							</h:inputText>
						</s:decorate>


						<s:decorate id="perHonorDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Perc. Honorario(%)" />
	                    	</ui:define>
	                    	
							<h:inputText id="perc_honora" value="#{movimentacaohandler.movimentacao.perchonorario}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}">
								<f:converter converterId="MyDoubleConverter" />
	         					<a4j:support event="onblur" reRender="paneldadostitulojuros, perc_honora"/>
							</h:inputText>
						</s:decorate>
						
						<s:decorate id="protestoDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Protesto" />
	                    	</ui:define>

							<h:inputText id="vlprot" value="#{movimentacaohandler.movimentacao.valorprotesto}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}">
								<f:converter converterId="MyDoubleConverter" />
	         					<a4j:support event="onblur" reRender="paneldadostitulojuros, vlprot"/>
							</h:inputText>
						</s:decorate>
					
					
						<h:outputLabel value="Observacao" for="" />
						<h:inputTextarea value="#{movimentacaohandler.movimentacao.obs}" style="width : 268px; height : 107px;" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"/>
						
					</h:panelGrid>

					........

				</h:panelGrid>
			</rich:panel>
		</a4j:region>


<a4j:region>
	            <a4j:commandButton id="btn_novo" action="#{movimentacaohandler.novoMovimentacao}" 
	            	value="Novo" immediate="true" ajaxSingle="true" limitToList="true"  
	            	reRender="formMovimentacao, docTst, mov_doc" />
            </a4j:region>
            
       		<a4j:commandButton id="botao_salvar" actionListener="#{movimentacaohandler.salvar(event,credentials.username)}" value="Salvar"
       			reRender="formMovimentacao,panel_atalhos,paneldadostitulo,form_atalhos"  
       			rendered="#{(not movimentacaohandler.tituloCarregado or  movimentacaohandler.editForm) 
       			and identity.hasRole('TITULOS/NOVO') }">
       		</a4j:commandButton>



</a4j:form>

Bean

public void novoMovimentacao(){
       this.movimentacao = new Movimentacao();
}

Obs.: Quando todos os campo estão Preenchidos, ou seja, a validação está ok ao clicar em NOVO é executadao normalmente limpando todos os campos.

Quem poder dar uma força… vlww!!!

Por favor, não crie tópicos somente com letras maiúsculas. Não tem pq tentar chamar mais atenção do que seus outros colegas de GUJ. Fora que ia ficar horrivel ler a lista de tópicos do fórum se todos fizessem isso.

Opa amigo.
Foi mal, não foi a intenção.
o/

bem vamos lá se vc tem um botao novo, vc pode colocar no seu action o seguinte:

<a jsfc="h:commandLink" action="#{controlerUs.novo}" >Cadastrar </a>

link ou botao o resultado eh o mesmo.

e no seu Controler:

public String novo(){ usuario = new Usuario(); return "caduser"; }
Nao esqueça de no seu bean vc ter os gets/sets para cada atributo. um exemplo basico:

public class Usuario {
	private int id; 
	private String nome=null; 
	private String email=null; 
	private String senha=null;
	private String tipo=null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
//... outros gets/sets

coloque immediate=true no campo do seu form.

flw!

[quote=LPJava]bem vamos lá se vc tem um botao novo, vc pode colocar no seu action o seguinte:

<a jsfc="h:commandLink" action="#{controlerUs.novo}" >Cadastrar </a>

link ou botao o resultado eh o mesmo.

e no seu Controler:

public String novo(){ usuario = new Usuario(); return "caduser"; }
Nao esqueça de no seu bean vc ter os gets/sets para cada atributo. um exemplo basico:

public class Usuario {
	private int id; 
	private String nome=null; 
	private String email=null; 
	private String senha=null;
	private String tipo=null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
//... outros gets/sets

coloque immediate=true no campo do seu form.

flw! [/quote]

Vlw pelas dicas.
Mas, o negócio é que estou usando renderização via ajax , se eu atualizar a pagina o “Novo” funciona corretamente.
Na execução do butão abaixo a ação novo é disparada , “passa” por cima das validação .

Passo a passao , pra ser mais claro
Formulario com 3 campos com required = true
Digito no primeiro campo um valor qualquer e deixo os outros em branco.
Clico em Salvar.
É alertado os outros dois campos que são obrigatórios
Clico em NOVO

Entãaao, o primeiro campo fica com o valor digitado inicialmente(não realizando a renderização) do novo objeto/atributo e os demais campos são zerados normalmente.

Alguém tem alguma sugestão?

VLWW!

<a4j:commandButton id="btn_novo" action="#{movimentacaohandler.novoMovimentacao}" value="Novo" immediate="true" ajaxSingle="true" limitToList="true" reRender="formMovimentacao, docTst, mov_doc" />

Olá. Na linha linha 141 você está dando um reRender em “formMovimentacao”, mas eu não achei esse id na sua página. Ele se refere a uma outra página?

[quote=henriquejhc]Olá. Na linha linha 141 você está dando um reRender em “formMovimentacao”, mas eu não achei esse id na sua página. Ele se refere a uma outra página?

[/quote]

eh o ID do form(a4j:form) que engloba todos esses campos.

Então a linha 1 não deveria ficar assim :

&lt;a4j:form id="formMovimentacao"&gt;

?

[quote=henriquejhc]Então a linha 1 não deveria ficar assim :

&lt;a4j:form id="formMovimentacao"&gt;

?[/quote]

e tá , é pq essa linha eu digitei pq tinha outras coisas entre o inicio da tag e o formulario…

O código que você postou não tem. Acho que dessa forma ficará dificil ajudar, você posta um código que está diferente do código original.

só essa linha ta diferente… :wink:

Alguma dica ?
=T

[quote=samukce]Pessoal, boa noite.

Vê se vocês podem me ajudar. Tou com a seguinte situação.
Estou usando Seam + JSF+Hibernate.
Possuo um formulário com alguns campos requeridos (required=true).
E a situação ocorre quando tento “zerar”(Limpar) meu formulário.

Caso eu acesse o primeiro campo requerido e digite alguma informação e deixe os outros em branco, ao clicar em salvar é apresentado na tela a validação dos campos que não foram preenchidos, até aí tudo bem. Porém, se eu clicar em NOVO(limpar o formulario . Meu bean Instancea o objeto novamente new Objeto()) todos os campos voltam a ficar em branco MENOS o campo inicial.

O que fazer para que ele renderize esse campo com o novo valor do Bean?

Formulario

<a4j:form>

<a4j:region id="regiaotitulos" renderRegionOnly="true" >
			<rich:panel id="paneldadostitulo" >
			<f:facet name="header">
				<h:outputText value="Dados do titulo" />
			</f:facet>
			
				<h:panelGrid columns="2" id="gridtitulos">
					<h:panelGrid columns="1" id="panelintDadosmov">
						<a4j:region id="docTst">
						<s:decorate id="docDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Documento" />	
								</ui:define>
						
							<h:inputText id="mov_doc" value="#{movimentacaohandler.movimentacao.doc}" 
								readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"
								style="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm  ? 'color :gray;' : ''  }" 
								required="true" >
	         				</h:inputText>
	         				
						</s:decorate>
						</a4j:region>
						
						<s:decorate id="nomeDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Parcela" />
	                    	</ui:defi
	                    	ne>
							
							<h:inputText id="mov_parcela" value="#{movimentacaohandler.movimentacao.parcela}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" style="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm  ? 'color :gray;' : ''  }">
	         				</h:inputText>
	         			</s:decorate>
						
							<s:decorate id="tipodocDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Tipo" />
								</ui:define>
						
								<h:selectOneMenu id="tipo_doc" value="#{movimentacaohandler.idtipodoc}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" style="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm  ? 'color :gray;' : ''  }" required="true"	>
									<f:selectItem itemValue="0" itemLabel="Selecione" />
					    			<f:selectItems id="choseDoc" value="#{tipodochandler.comboTipoDoc}"  />
					    		</h:selectOneMenu>
				    		</s:decorate>
						
						
						<s:decorate id="dtVencDocDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Data Vencimento Documento" />	
								</ui:define>
						        
						        <rich:calendar id="data_venc_doc" value="#{movimentacaohandler.movimentacao.datavencimentodocumento}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" 
		                        datePattern="dd/MM/yyyy" enableManualInput="true" cellWidth="24px" cellHeight="22px" style="width:200px" required="true" requiredMessage="Data de vencimento requerida.">
		                        <a4j:support event="onkeypress" action="return tabEnter(this, event);" />
		                        <a4j:support reRender="paneldadostitulo" immediate="true"
											event="oninputchange"  limitToList="true" 
											eventsQueue="keypressQueue" />
		                    </rich:calendar>
		                 </s:decorate>
						
						
						<s:decorate id="vloriginalDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Valor original" />	
								</ui:define>
						        
								<h:inputText id="valor_origi_mov" required="true" value="#{movimentacaohandler.movimentacao.valormovimento}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"
								 requiredMessage="Campo obrigatorio">
									<f:converter converterId="MyDoubleConverter" />
		         					<a4j:support event="onblur" reRender="vloriginalDisplay,paneldadostitulojuros"/> 
								</h:inputText>
						</s:decorate>
						
						
						<s:decorate id="dtEscritDisplay" template="/layout/edit.xhtml" >
								<ui:define name="label">
									<h:outputText value="Data Vencimento Escritorio" />	
								</ui:define>
								
							    <rich:calendar id="dt_venc_esc" value="#{movimentacaohandler.movimentacao.datavencimentodocartorio}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}" disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"
			                        datePattern="dd/MM/yyyy" enableManualInput="true" cellWidth="24px" cellHeight="22px" style="width:200px" required="true" requiredMessage="Data requerida." >
			                        <a4j:support event="onkeypress" action="return tabEnter(this, event);" />
			                        <a4j:support reRender="paneldadostitulojuros"
												event="onchange" limitToList="true" 
												eventsQueue="keypressQueue" />
		                        </rich:calendar>
						</s:decorate>
												
						
						<s:decorate id="perjurosDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Perc. Juros(%)" />
	                    	</ui:define>
	                    	
							<h:inputText id="perc_juros_def" value="#{movimentacaohandler.movimentacao.percjurosdefault}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}">
								<f:converter converterId="MyDoubleConverter" />
	         					<a4j:support event="onblur"  reRender="paneldadostitulojuros,perc_juros_def" />
							</h:inputText>
						</s:decorate>


						<s:decorate id="perHonorDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Perc. Honorario(%)" />
	                    	</ui:define>
	                    	
							<h:inputText id="perc_honora" value="#{movimentacaohandler.movimentacao.perchonorario}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}">
								<f:converter converterId="MyDoubleConverter" />
	         					<a4j:support event="onblur" reRender="paneldadostitulojuros, perc_honora"/>
							</h:inputText>
						</s:decorate>
						
						<s:decorate id="protestoDisplay" template="/layout/display.xhtml">
							<ui:define name="label">
	                        	<h:outputText value="Protesto" />
	                    	</ui:define>

							<h:inputText id="vlprot" value="#{movimentacaohandler.movimentacao.valorprotesto}" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}">
								<f:converter converterId="MyDoubleConverter" />
	         					<a4j:support event="onblur" reRender="paneldadostitulojuros, vlprot"/>
							</h:inputText>
						</s:decorate>
					
					
						<h:outputLabel value="Observacao" for="" />
						<h:inputTextarea value="#{movimentacaohandler.movimentacao.obs}" style="width : 268px; height : 107px;" readonly="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"  disabled="#{movimentacaohandler.tituloCarregado and not movimentacaohandler.editForm}"/>
						
					</h:panelGrid>

					........

				</h:panelGrid>
			</rich:panel>
		</a4j:region>


<a4j:region>
	            <a4j:commandButton id="btn_novo" action="#{movimentacaohandler.novoMovimentacao}" 
	            	value="Novo" immediate="true" ajaxSingle="true" limitToList="true"  
	            	reRender="formMovimentacao, docTst, mov_doc" />
            </a4j:region>
            
       		<a4j:commandButton id="botao_salvar" actionListener="#{movimentacaohandler.salvar(event,credentials.username)}" value="Salvar"
       			reRender="formMovimentacao,panel_atalhos,paneldadostitulo,form_atalhos"  
       			rendered="#{(not movimentacaohandler.tituloCarregado or  movimentacaohandler.editForm) 
       			and identity.hasRole('TITULOS/NOVO') }">
       		</a4j:commandButton>



</a4j:form>

Bean

public void novoMovimentacao(){
       this.movimentacao = new Movimentacao();
}

Obs.: Quando todos os campo estão Preenchidos, ou seja, a validação está ok ao clicar em NOVO é executadao normalmente limpando todos os campos.

Quem poder dar uma força… vlww!!![/quote]

Cara, eu estou com o mesmo problema. Tu conseguiu resolver?!/

[quote=braian]

Cara, eu estou com o mesmo problema. Tu conseguiu resolver?!/[/quote]

Braian consegui achar uma solução não muito elegante. Eu "forcei"a limpeza dos componentes manualmente. Isso resolveu mas acredito que exista alguma outra solução para isso.

Vou colocar aqui a solução que consegui. Recomendo pesquisar pra ver se encontra uma outra …

[code]
public void limparComponentesTru(){
FacesContext context = FacesContext.getCurrentInstance();

	UIViewRoot viewRoot = context.getViewRoot();

	List<UIComponent> iter= viewRoot.getChildren();
	resetarCampo (iter);

	context.renderResponse();
}

private void resetarCampo( List<UIComponent> no1  ){

	for(UIComponent no : no1){

		if ( no instanceof HtmlInputText ){  
			
			HtmlInputText html = (HtmlInputText) no;
			html.resetValue();
		}
		
		if ( no.getChildren().size() > 0 ){  
			resetarCampo( no.getChildren() );  
		}  
	}

}  [/code]

Espero que lhe ajude aew…
flws

Algum moderador, por favor, exclui minha msg q foi colocada por engano.