You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "simon.s" <si...@gmx.de> on 2007/03/27 14:07:41 UTC

selectItems alsway throw validation error

Hi!

I already seached this forum but found no answer for my problem that I hope
is simple to fix.
I have a selectOneListBox that displays Employees that should be selected. I
wrote a converter but I always get a "Wert ist keine gültige Auswahl" -
means "value is invalid"

Here is my code:

<t:selectOneListbox id="employees" size="1"
value="#{newScheduleEntryForm.responsibility}">
    <t:selectItems value="#{peopleHandler.allEmployees}" var="thisItem"
itemLabel="#{thisItem.firstName} #{thisItem.lastName}"
itemValue="#{thisItem}" />
</t:selectOneListbox>


In newSheduleEntryForm
public EmployeeVO getResponsibility() {...}

public void setResponsibility(EmployeeVO responsibility) {...}

in peopleHandler
public List<EmployeeVO> getAllEmployees() {...}

the Converter
public EmployeeVO getAsObject(FacesContext context, UIComponent component,
String value) throws ConverterException {
if ( value == null) return null;
for ( EmployeeVO employee : ps.getAllEmployees())
{
	if ( employee.getId().toString().equals(value))
	{
		System.out.println("employee found: " + employee.getLastName()); //this is
put to console so the converter works!
		return employee;
	}
}
throw new ConverterException ("EmployeeConverter.getAsObject: There is no
EmployeeVO for Value " + value + ", type=" + value.getClass().toString());
}

public String getAsString(FacesContext context, UIComponent component,
Object value) throws ConverterException {
	if ( value == null) return null;
	if (value instanceof EmployeeVO)
        {
		EmployeeVO person = (EmployeeVO) value;
                return person.getId().toString();
        }
        throw new ConverterException ("EmployeeConverter.getAsString: This
is no EmployeeVO, value=" + value.toString() + ", type=" +
value.getClass().toString());
}
-- 
View this message in context: http://www.nabble.com/selectItems-alsway-throw-validation-error-tf3472646.html#a9691017
Sent from the MyFaces - Users mailing list archive at Nabble.com.


RE: selectItems alsway throw validation error

Posted by "simon.s" <si...@gmx.de>.


Strittmatter, Stephan wrote:
> 
> probably your Employee-Class is not serializable and do not implement
> equals?
> If it is not implementing equals, every instance is different... 
> 

Ok, I fixed that but had no success. If I do not use a SelectBox but a
simple text-input to type in the ID of the employee it works fine. No
convertions or validation problems...

Simon
-- 
View this message in context: http://www.nabble.com/selectItems-alway-throws-validation-error-tf3472646.html#a9692279
Sent from the MyFaces - Users mailing list archive at Nabble.com.


RE: selectItems alsway throw validation error

Posted by "Strittmatter, Stephan" <St...@sybit.de>.
You are welcome!
Yesterday I not answered because I had no more ideas :)

-----Original Message-----
From: simon.s [mailto:simon.schroeder@gmx.de] 
Sent: Thursday, March 29, 2007 9:59 AM
To: users@myfaces.apache.org
Subject: RE: selectItems alsway throw validation error


Hi Stephan!

There was a typo in my equals method. So your hint (serializable and
equals
method) was perfect! Now it works!

Thanks a lot!
Simon
-- 
View this message in context:
http://www.nabble.com/selectItems-alway-throws-validation-error-tf347264
6.html#a9728653
Sent from the MyFaces - Users mailing list archive at Nabble.com.



RE: selectItems alsway throw validation error

Posted by "simon.s" <si...@gmx.de>.
Hi Stephan!

There was a typo in my equals method. So your hint (serializable and equals
method) was perfect! Now it works!

Thanks a lot!
Simon
-- 
View this message in context: http://www.nabble.com/selectItems-alway-throws-validation-error-tf3472646.html#a9728653
Sent from the MyFaces - Users mailing list archive at Nabble.com.


RE: selectItems alsway throw validation error

Posted by "Strittmatter, Stephan" <St...@sybit.de>.
Hi Simon,

probably your Employee-Class is not serializable and do not implement equals?
If it is not implementing equals, every instance is different... 

Regards,

Stephan

-----Original Message-----
From: simon.s [mailto:simon.schroeder@gmx.de] 
Sent: Tuesday, March 27, 2007 2:08 PM
To: users@myfaces.apache.org
Subject: selectItems alsway throw validation error


Hi!

I already seached this forum but found no answer for my problem that I hope
is simple to fix.
I have a selectOneListBox that displays Employees that should be selected. I
wrote a converter but I always get a "Wert ist keine gültige Auswahl" -
means "value is invalid"

Here is my code:

<t:selectOneListbox id="employees" size="1"
value="#{newScheduleEntryForm.responsibility}">
    <t:selectItems value="#{peopleHandler.allEmployees}" var="thisItem"
itemLabel="#{thisItem.firstName} #{thisItem.lastName}"
itemValue="#{thisItem}" />
</t:selectOneListbox>


In newSheduleEntryForm
public EmployeeVO getResponsibility() {...}

public void setResponsibility(EmployeeVO responsibility) {...}

in peopleHandler
public List<EmployeeVO> getAllEmployees() {...}

the Converter
public EmployeeVO getAsObject(FacesContext context, UIComponent component,
String value) throws ConverterException {
if ( value == null) return null;
for ( EmployeeVO employee : ps.getAllEmployees())
{
	if ( employee.getId().toString().equals(value))
	{
		System.out.println("employee found: " + employee.getLastName()); //this is
put to console so the converter works!
		return employee;
	}
}
throw new ConverterException ("EmployeeConverter.getAsObject: There is no
EmployeeVO for Value " + value + ", type=" + value.getClass().toString());
}

public String getAsString(FacesContext context, UIComponent component,
Object value) throws ConverterException {
	if ( value == null) return null;
	if (value instanceof EmployeeVO)
        {
		EmployeeVO person = (EmployeeVO) value;
                return person.getId().toString();
        }
        throw new ConverterException ("EmployeeConverter.getAsString: This
is no EmployeeVO, value=" + value.toString() + ", type=" +
value.getClass().toString());
}
-- 
View this message in context: http://www.nabble.com/selectItems-alsway-throw-validation-error-tf3472646.html#a9691017
Sent from the MyFaces - Users mailing list archive at Nabble.com.