Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

FAQ Category:

The scenario

JSF runs the converter and loads the entity from the persistence context; JSF runs any validators, and adds it's own - that the selected object must be in the original list; the validation fails as a new object has been loaded from the persistence context.

A more detailed explanation can be found on Drop-down boxes with entities and page scope.

The solution

You've got two options:

  1. Ensure that you are in a long-running conversation that spans the both the select list creation and the submission of the form.
  2. Use key equality rather than object equality (make equals return true if both objects have the same natural or business key). It's important to note that basing equality on surrogate key identity isn't recommended. You can read more here

Which approach should you take? The second solution is the simplest to understand but sometimes it is hard (or not possible) to define a natural key so you'll need to use the first solution.

Alternative solutions

The knowledge base article Drop-down boxes with entities and page scope describes a feasible workaround.

3 comments:
 
28. Jul 2008, 23:59 America/New_York | Link

Would you please post some of the samples with entity bean, stateful session bean action method and xhtml using selectOneMenu and convertEntity

Thanks a lot,

Weiwei Chi

 
14. Oct 2008, 10:20 America/New_York | Link
Michael R.

...some examples would be REALLY helpful :)

 
18. Nov 2009, 02:59 America/New_York | Link

I had this trouble in my case was in my equals method:

@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MyClass other = (MyClass) obj;
		if (codigo == null) {
			if (other.codigo != null)
				return false;
		} else if (!codigo.equals(other.codigo))
			return false;
		return true;
	}

in this line:

if (getClass() != obj.getClass())
      return false;

Cause the obj.getClass() is created via Proxy they don't have same types. If your problem is the same, remove that line and your select will be OK.