no atributo required coloque bean.nome != ‘’
abrassss
no atributo required coloque bean.nome != ‘’
abrassss
Opa, talvez você tenha que renderizar todos os campos, assim você garante que o valor do campo nome seja passado para o bean.
<h:panelGroup id="formulario">
<h:inputText id="nome" value="#{bean.nome}">
<a4j:support event="onchange" ajaxSingle="true" reRender="formulario"/>
</h:inputText>
<h:inputText id="sobrenome" value="#{bean.sobrenome}" required="#{not empty bean.nome}"/>
</h:panelGroup>
[]´s
Daniel
amigo, como seu caso eh mto interessante achei que fosse util pra mim tb, entao resolvi gastar um super tempo para achar a solucao, creio que funcione pra vc tb. rs
vou fazer uma analogia com suas variaveis para ficar mais claro.
no construtor do bean setei a propriedade nome como vazia
public Bean() {
this.nome = "";
}
no campo nome fiz:
<h:inputText value="#{bean.nome}">
<a4j:support event="onchange" reRender="sobrenome" ajaxSingle="true" />
</h:inputText>
<h:inputText value="#{bean.sobrenome}" required="#{not empty bean.nome}" />
<a4j:keepAlive beanName="boasVindas" />
coloquei um support para que assim que o nome seja alterado o campo sobrenome seja renderizado e seu atributo required alterado.
no atributo required verifico se o nome nao é vazio para que seja realmente obrigatorio
e adicionei um keepAlive para manter o estado do bean entre os requests
caso tenha alguma duvida poste ai.
abrasssssssssss
Olá gente!
Estou usando o keepAlive pra manter o estato de um bean de uma página pra outra, mas n estou obtendo êxito!
Já procurei em vários lugares e n consigo descobrir o q estou fazendo de errado ou o q estou deixando de fazer para que ele funcione.
Alguém pode m ajudar?
Meu bean é de request.
pagina:
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.ajax4jsf.org/rich"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html" version="2.1">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Busca por CEP</title>
</head>
<body>
<f:view>
<center><br />
<br />
<br />
<br />
<br />
<br />
<h:outputLabel value="Pesquisar CEP"></h:outputLabel> <br />
<br />
<h:form>
<h:panelGrid columns="2" style="text-align:center;">
<h:outputText value="Logradouro:" />
<h:inputText id="logradouroBuscaCep"
value="#{buscarCepBean.nomeLogradouro}" />
</h:panelGrid>
<a4j:keepAlive beanName="buscarCepBean" />
<br />
<h:commandButton value="Pesquisar"
action="#{buscarCepBean.buscaCepbyLogradouro}">
<a4j:support reRender="logList"></a4j:support>
</h:commandButton>
</h:form></center>
</f:view>
</body>
</html>
</jsp:root>
A segunda é esta onde devo retornar o resultado da busca; já fiz com bean de sessão e vi q minha busca funciona perfeitamente, mas no escopo de request eu não consigo exibir nada na tabela.
Outra dúvida: em ql dos jsp preciso colcoa ro keep? Eu entendi q deveria ser o primeiro bean. ?????<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.ajax4jsf.org/rich"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html" version="2.1">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Busca por CEP</title>
</head>
<body>
<f:view>
<h:form>
<rich:datascroller align="left" for="logList" maxPages="20"
reRender="sc2" id="sc1" page="#{buscarCepBean.scrollerPage}" />
<rich:spacer height="30" />
<rich:dataTable width="483" id="logList" rows="10"
columnClasses="col" value="#{buscarCepBean.listaLogradouro}"
var="varLogradouro">
<f:facet name="header">
<rich:columnGroup>
<h:column>
<h:outputText styleClass="headerText" value="CEP" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Tipo" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Logradouro" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="UF" />
</h:column>
</rich:columnGroup>
</f:facet>
<h:column>
<h:outputText value="#{varLogradouro.cepLogradouro}" />
</h:column>
<h:column>
<h:outputText value="#{varLogradouro.tipoLogradouro}" />
</h:column>
<h:column>
<h:outputText value="#{varLogradouro.nomeLogradouro}" />
</h:column>
<h:column>
<h:outputText value="#{varLogradouro.siglaUf}" />
</h:column>
</rich:dataTable>
<rich:datascroller align="left" for="logList" maxPages="20" id="sc2"
reRender="sc1" page="#{buscarCepBean.scrollerPage}" />
<br />
<h:commandButton value="Voltar" action="buscarCep"></h:commandButton>
</h:form>
</f:view>
</body>
</html>
</jsp:root>
Grata, :D
Galera, o problema é o seguinte:
Em um formulário preciso aplicar uma regra de obrigatoriedade dos campos. Quando o campo 'nome' for preenchido, o campo 'sobrenome' deve se tornar obrigatório (required).
Tentei fazer simplesmente<h:inputText id="nome" value="#{bean.nome}"/>
<h:inputText id="sobrenome" value="#{bean.sobrenome}" required="#{not empty bean.nome}"/>
<h:inputText id="nome" value="#{bean.nome}">
<a4j:support event="onchange" ajaxSingle="true" reRender="sobrenome"/>
</h:inputText>
<h:inputText id="sobrenome" value="#{bean.sobrenome}" required="#{not empty bean.nome}"/>
OBS 1: Este é apenas um exemplo, na verdade tenho mais campos e mais regras.
OBS 2: Estou utilizando JSF 1.1 RI, Richfaces 3.1.6.
Agradeço desde já!
Funcionou com o a4j:keepAlive, já que meu bean tem escopo REQUEST. Acredito que estava aí o problema.
Testei com escopo SESSION sem o a4j:keepAlive e também funcionou.
Obrigado por responderem. 