[jboss-user] [JBoss Seam] - Another h:selectOneMenu and valueChangeListener problem...

ElNino do-not-reply at jboss.com
Sun Nov 4 08:57:17 EST 2007


Hello,

 I am relatively new with JBoss technologies; I spent a lot of time reading books and posts but I spent several days on a very simple thing; others people have already explain the same problem on the forum but the proposed solutions are not working for me.

My post is quite long cause I prefer giving you a complete presentation of my problem.

I'am using

jBoss Seam 2.0.0.CR2
with jboss-4.2.1.GA

I will take a simple example :

I have:

- a continent entity
- a country entity

Of course, continent contains serveral countries and a country is attached to a continent :


  | @Entity
  | @Name("continent")
  | @Table(name = "Continents")
  | public class Continent extends PersistentEntity implements Serializable {
  | 
  | 	private static final long serialVersionUID = 1L;
  | 	private long id;
  | 	private Set<Country> countries;
  | 	private String name;
  | 
  | 	public Continent() {	}
  | 
  | 	public Continent(String name) {
  | 		this.name = name;
  | 	}
  | 
  | 	@Id
  | 	@GeneratedValue
  | 	public long getId() {
  | 		return id;
  | 	}
  | 
  | 	public void setId(long id) {
  | 		this.id = id;
  | 	}
  | 
  | 	public String getName() {
  | 		return name;
  | 	}
  | 
  | 	public void setName(String name) {
  | 		this.name = name;
  | 	}
  | 
  | 	@OneToMany
  | 	public Set<Country> getCountries() {
  | 		return countries;
  | 	}
  | 
  | 	public void setCountries(Set<Country> countries) {
  | 		this.countries = countries;
  | 	}
  | 


  | @Entity
  | @Name("country")
  | @Table(name="Countries")
  | public class Country extends Location implements Serializable {
  | 	
  | 	private static final long serialVersionUID = 1L;
  | 	private long id;
  | 	private Continent continent;
  | 	private Set<Region> regions;
  | 
  | 	@Id
  | 	@GeneratedValue
  | 	public long getId() {
  | 		return id;
  | 	}
  | 
  | 	public void setId(long id) {
  | 		this.id = id;
  | 	}
  | 
  | 	@OneToMany
  | 	public Set<Region> getRegions() {
  | 		return regions;
  | 	}
  | 
  | 	public void setRegions(Set<Region> regions) {
  | 		this.regions = regions;
  | 	}
  | 
  | 	@ManyToOne
  | 	public Continent getContinent() {
  | 		return continent;
  | 	}
  | 
  | 	public void setContinent(Continent continent) {
  | 		this.continent = continent;
  | 	}
  | 

Now I have a XHTML page with <h:selectOneMenu items.

The first list all the continents, and on the selection of a continent, I would like to enable the country select box and refreshing it with the countries located in the selected continent.

I read a lot of documents but I can't manage to get a response on value selection.

I have the xHTML form :

  | <h:form id="creationForm">
  | 					<h:outputText value="Continent: " />
  | 					<h:outputText value="No continent"
  | 						rendered="#{creationAction.getNumberOfPossibleContinents()==0}" />
  | 
  | 					<h:selectOneMenu value="#{creationAction.selectedContinent}"
  | 						valueChangeListener="#{creationAction.continentChangeEvent}"
  | 						onchange="this.form.submit()"
  | 						rendered="#{creationAction.getNumberOfPossibleContinents()>0}">
  | 
  | 						<s:selectItems
  | 							value="#{creationAction.getPossibleContinentsList()}"
  | 							var="selectedContinent" noSelectionLabel="Please Select..." />
  | 						<s:convertEntity />
  | 					</h:selectOneMenu>
  | 				</h:form>
  | 

creationAction is defines like this


  | @Stateful
  | @Name("creationAction")
  | @Scope(ScopeType.SESSION)
  | public class creationAction implements ICreation {
  | 
  | 	private Continent selectedContinent;
  | 	private List<Continent> possibleContinentsList;
  | 
  | 	@PersistenceContext(type = EXTENDED)
  | 	private EntityManager entityManager;
  | 
  | 	public void cancelCreation() {
  | 	}
  | 
  | 	@Remove
  | 	@End
  | 	public void confirmCreation() {
  | 		System.out.println("CONFIRM");
  | 	}
  | 
  | 	@SuppressWarnings("unchecked")
  | 	public List<Continent> getPossibleContinentsList() {
  | 		possibleContinentsList = entityManager
  | 				.createQuery("from Continent row").getResultList();
  | 
  | 		return possibleContinentsList;
  | 	}
  | 
  | 	public void addContinent(Continent continent) {
  | 	}
  | 
  | 	public Continent getSelectedContinent() {
  | 		return null;
  | 	}
  | 
  | 	public void setSelectedContinent(Continent continent) {
  | 		System.out.println("Set...");
  | 	}
  | 
  | 	public int getNumberOfPossibleContinents() {
  | 		int result = 0;
  | 
  | 		if (possibleContinentsList != null) {
  | 			result = possibleContinentsList.size();
  | 		} else {
  | 			result = getPossibleContinentsList().size();
  | 		}
  | 
  | 		return result;
  | 	}
  | 
  | 	public void continentChangeEvent(ValueChangeEvent event) {
  | 		System.out.println("Event : " + event);
  | 		System.out.println("New value : " + event.getNewValue());
  | 	}
  | 

With the interface :


  | @Local
  | public interface ICreation {
  | 
  | 	public void confirmCreation();
  | 
  | 	public void cancelCreation();
  | 
  | 	public List<Continent> getPossibleContinentsList();
  | 
  | 	public void addContinent(Continent continent);
  | 
  | 	public Continent getSelectedContinent();
  | 
  | 	public void setSelectedContinent(Continent continent);
  | 
  | 	public int getNumberOfPossibleContinents();
  | 
  | 	public void continentChangeEvent(ValueChangeEvent event);
  | 

The continent list is displayed but continentChangeEvent method is never called !

In the debug console (when I select a continent ...) : 

13:52:22,098 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=creationForm:j_id19[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]

Any ideas ?

I'am of course free for answer to all your questions ?

Thanks for your help !









View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101576#4101576

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101576



More information about the jboss-user mailing list