SuggestionBox Richfaces + Seam

14 respostas
R

Olá pessoal,

estou passando por um probleminha… bem lá vai…
tenho um suggestion box e dois dropdownlist.
O suggestion box é o label -> city
e os dois dropdownlist ou combobox são country e state conforme o código abaixo.

<s:decorate id="townDecoration" template="../layout/edit.xhtml">
					<ui:define name="label">City :</ui:define>
					<h:inputText value="#{userBean.town.name}" 
								 id="town"
								 label="town" 
								 required="true"
								 size="25"
				  			   	 maxlength="200"
				  			   	 var="townName"
				  			   	 rendered="true" >
				  			   	 <a4j:support event="onchange"
				  			   	 			  reRender="country,state"
				  			   	 			  ajaxSingle="true"
				  			   	 			  action="#{userBean.emptyValues}"
				  			   	 			  rendered="true"/>
				  	</h:inputText>			  			   	 				  	
					<rich:suggestionbox id="suggestion" 
										for="town"
				               			suggestionAction="#{userBean.suggestionTown}"
               							width="200" 
               							height="100" 
               							var="result"
               							minChars="3" 
               							fetchValue="#{result.name}"
               							ajaxSingle="true"  
               							rendered="true"            							
               							>
               			<h:column>
               				<h:outputText value="#{result.id},#{result.name},#{result.state.id}-#{result.state.name},#{result.country.id}-#{result.country.name}" id="output" rendered="true" >
               				</h:outputText>
        				</h:column>
        				<a4j:support event="onselect" 
        							 reRender="country,state"
        							 ajaxSingle="true" 
        							 action="#{userBean.actionLoadStates}"
        							 rendered="true">        							 
							<f:setPropertyActionListener
									value="#{result.id}"
									target="#{userBean.town.id}"/>
							<f:setPropertyActionListener 	
									value="#{result.country.id}" 
									target="#{userBean.country.id}" />	
							<f:setPropertyActionListener 
									value="#{result.state.id}" 
									target="#{userBean.state.id}" />	
						</a4j:support> 					
        			</rich:suggestionbox>
				</s:decorate>
				
				<s:decorate id="countryDecoration" template="../layout/edit.xhtml">
					<ui:define name="label">Country :</ui:define>
					<h:selectOneMenu value="#{userBean.country.id}"
									 id="country"
									 rendered="true"
									 required="true" 
									 >
							<f:selectItem itemLabel="--Select Country--" 
										  itemValue=""/>
							<f:selectItems  value="#{userBean.allCountries}" />
							<a4j:support event="onchange"   
						                 ajaxSingle="true"  
						                 action="#{userBean.actionLoadStates}"  
						                 reRender="country,state"
						                 rendered="true" >						     	
						     </a4j:support>  
					</h:selectOneMenu>
				</s:decorate>	
								
				<s:decorate id="stateDecoration" template="../layout/edit.xhtml">
					<ui:define name="label">State :</ui:define>
					<h:selectOneMenu value="#{userBean.state.id}"
									 id="state" 
									 rendered="true" 
									 
									 >							
						<f:selectItem itemLabel="--Select a state--" itemValue=""/>			 																
						<f:selectItems  value="#{userBean.states}"  /> 	
						<a4j:support event="onchange"
									 ajaxSingle="true"
									 reRender="state"
									 rendered="true"/>
					</h:selectOneMenu> 
				</s:decorate>

está tudo funcionando uma belezinha mas com um pequeno bug, ao apertar o botão submeter e não preencher todos campos required ele volta marcando o campo de state com a mensagem Value is not valid. Não sei o que fazer nesse caso, alguém já passou por algo parecido?
Obrigado

14 Respostas

vitenho

http://www.rponte.com.br/2008/02/01/selectonemenu-converter-erro-de-validacao/

R

Po cara, valeu vou dar uma lidinha nisso daqui… e vejo se da certo no meu caso. Obrigado

vitenho

de boa :}

R

só uma dúvida, no meu caso teria que implementar um stateConverter ?

R

e como ficaria no caso do equals e hashCode sendo implementados?

R

já to chato aqui, mas tem mais um detalhe, só acontece com state, com country não acontece, o mais interessante é isso… Mas mesmo assim me ajudou cara pelo menos entender o problema… Obrigadão, me salvou… agora preciso tentar implementar, só saber como…

vitenho

acho q no seam tem um tal de s:entityconverter que é um jsf converter q vc pode colocar em qualquer entity tua

flw

R

Sim eu vi, então não precisaria implementar nenhum converter nem sobrescrever método né? Somente aplicar esse s:entityConverter no selectOne do state?

R

Desculpa sou meio novo com isso tudo só tenho um mês… pode parecer dúvidas básicas, mas eu to lendo vários materiais ao mesmo tempo e as vezes posso me passar por alguma coisa… :frowning:

vitenho

ainda tem q sobreescrever o equals da tua entity porque o objeto convertido é a tua entity e o seam nao vai sobreescrever o equals nela

R

Mas seria sobrescrever da entity state, town e country? Pois ele já está sobrescrito no entity.

na minha entitiy Town.java

public boolean equals(Object o) {
		if(this == o) return true;
		if(!(o instanceof Town))
			return false;
		Town p = (Town ) o;
		if(!this.state.equals(p.getState())) return false;
		return super.equals(o);
	}
	
	public int hashCode() {
		int h = 31;
		h = 31*h + super.hashCode();
		h = 31*h + this.getState().hashCode();
		return h;
	}

na minha entitiy State.java

public boolean equals(Object o) {
		if(this == o) return true;
		if(!(o instanceof State))
			return false;
		State p = (State ) o;
		if(!this.country.equals(p.getCountry())) return false;
		return super.equals(o);
	}
	
	public int hashCode() {
		int h = 31;
		h = 31*h + super.hashCode();
		h = 31*h + this.getCountry().hashCode();
		return h;
	}

Country.java não contém.

Agora preciso chamar o s:entity aonde?

R

Segue em anexo meu .java e meu .xhtml

vitenho

cara eu nao tenho experiencia pra te responder isso :frowning: sory

http://docs.jboss.org/seam/2.0.0.GA/reference/en/html/controls.html

http://shrubbery.mynetgear.net/wiki/Select_lists_with_Seam

juniorsatanas

Alguem sabe onde tem um crud em Seam ?

Criado 10 de agosto de 2009
Ultima resposta 9 de mar. de 2010
Respostas 14
Participantes 3