ComboBox Jboss Seam

7 respostas
R

Estou fazendo um combobox só que tive a infelicidade de que só o valor de noSelectionLabel está trazendo… se eu tiro o noSelectionLabele a lista de paises vem sem problema, mas a partir do momento que coloco d evolta ele só traz o Select a country e mais nada preenchido, alguem pode me dar uma ajuda?

<h:selectOneMenu value="#{userBean.user.address}" converter="#{countryList.converter}" required="true" id="srchCountry" >																
							<s:selectItems  value="#{countryList.allCountries}" id="country"  noSelectionLabel="-- Select a country --" />	
							<s:convertEntity/>					
						</h:selectOneMenu>

7 Respostas

G

Bah brother, tu teve mais felicidade que eu. Eu não consegui nem usar este componente que da um erro de converter.

R

como ta o seu codigo, provavelmente tu precisara implementar uma classe do tipo Converter

tipo classeConversora implements Converter… pois precisa para funcionar …

como ta o seu codigo?

G

Cara, no fim acabei fazendo de outra maneira como não consegui encontrar a situação. Mas pelo que me lembro da documentação do seam (não estou encontrando agora) não seria necessário a implementação do converter. Estou procurando a documentação e não acho esse ponto.

R

estou com akele livro projetos praticos com jboss seam… to tentando copiar o exemplo mas adequando pra minha situacao, mas o foda que o noselectionlabel se eu colocar nao traz a lista de paises, a nao ser q eu faca armengue…

G

Brother, tipo assim. Talvez não seja a solucao mais limpa mas pq tu nao inclui um:

<h:selectOneMenu value="#{userBean.user.address}" converter="#{countryList.converter}" required="true" id="srchCountry">                                                          <s:selectItem  valueLabel="-- Select a country --" />
   <s:selectItems  value="#{countryList.allCountries}"  id="country"  />      
    <s:convertEntity/>                      
</h:selectOneMenu>
R

cara tu sabe como posso usar o ajax para a minha situacao? quero colocar o state desabilitado até o cara selecionar um pais … como faria isso?

<h:outputLabel value="Country * :" for="country" />
						<h:selectOneMenu value="#{countryList.country}" converter="#{countryList.converter}" required="true" id="srchCountry"  >																							
							<s:selectItems noSelectionLabel="-- Select a country --" />
							<s:selectItems  value="#{countryList.allCountries}" id="country" var="country" />								
						</h:selectOneMenu>
					<h:outputLabel value="State * :" for="state" />
						<h:selectOneMenu value="#{stateList.state}" converter="#{stateList.converter}" required="true" id="srchState" >																							
							<s:selectItems noSelectionLabel="-- Select a state --" />
							<s:selectItems  value="#{stateList.allStates}" id="state"  /> 	
						</h:selectOneMenu>
package com.citespace.bean.list;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.convert.Converter;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.citespace.bean.list.interfaces.IStateList;
import com.citespace.cms.model.State;
import com.citespace.converter.StateConverter;

@Stateful
@Name("stateList")
@Scope(ScopeType.EVENT)
public class StateList implements IStateList, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1901355293311882031L;

	private List<State> mState;
	
	private Map<String, State> mStateMap;
	
	private Integer countryId;
	
    private State state;
    
	@PersistenceContext(unitName="citespace-jpa")
    private EntityManager em;

	@Create
	@SuppressWarnings("unchecked")
	public void loadState(){
		
		Query q = 
			em.createQuery("select s from State s Join s.country c Where c.id = :countryId");
		q.setParameter("countryId", countryId);
		mState = q.getResultList();
		Map<String, State> results = new TreeMap<String, State>();
		for(State s:mState){
			results.put(s.getName(), s);
		}
		
		mStateMap = results;
	}
	
	public Map<String, State> getAllStates(){
		return mStateMap;
	}
	
	public Map<String, State> getStatesByCountry(Integer countryId){
		return mStateMap;
	}
	
	public Converter getConverter(){
		return new StateConverter(mState);
	}
	
	
	public Integer getCountryId() {
		return countryId;
	}

	public void setCountryId(Integer countryId) {
		this.countryId = countryId;
	}
	
	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	@Remove @Destroy
	public void destroy(){}	
}
package com.citespace.bean.list;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.convert.Converter;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;


import com.citespace.bean.list.interfaces.ICountryList;
import com.citespace.cms.model.Country;
import com.citespace.converter.CountryConverter;

@Stateful
@Name("countryList")
@Scope(ScopeType.EVENT)
public class CountryList implements ICountryList, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4824589054075219364L;

	private List<Country> mCountry;
	
	private Map<String, Country> mCountryMap;
		
	private Country country = null;
	
	@PersistenceContext(unitName="citespace-jpa")
    private EntityManager em;

	@Create
	@SuppressWarnings("unchecked")
	public void loadCountry(){
		mCountry = 
			em.createQuery("select c from Country c ").getResultList();
		Map<String, Country> results = new TreeMap<String, Country>();
		for(Country c:mCountry){
			results.put(c.getName(), c);
		}
		
		mCountryMap = results;
	}
	
	public Map<String, Country> getAllCountries(){
		return mCountryMap;
	}
	
	
	public Converter getConverter(){
		return new CountryConverter(mCountry);
	}
	
	
	@Remove @Destroy
	public void destroy(){}

	
	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}
	
}
G

Tu terá que usar um a4j no change do Country. Se o cara selecionou um Country diferente de vázio tu faz um select no bean que monta o combo de Estate. E Combo Estate esta com o um disabled="#{empty teuBean.estates}".

Acho que é isso. Eu já fiz esses lazy loads de interface como SuggestionBox do richfaces. Mas este componente ainda tem uns bugzinhos, acho que ta em beta ainda.

Criado 20 de julho de 2009
Ultima resposta 21 de jul. de 2009
Respostas 7
Participantes 2