# RichFaces converter in orderingList wirft exception



## whutmach (17. Jul 2009)

Moin, moin,

habe mit untigen Code versucht eine orderingList mit einem Converter zu versorgen.
Klappt ganz gut beim Event "onorderedchanged", aber leider nur einmal. 

Beim 2.ten Mal krachts:

java.lang.IllegalStateException: sevenwonder.Wonder
	javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:109)
	javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1441)
	org.richfaces.component.UIOrderingList$ValueHolder.restoreState(UIOrderingList.java:196)
	org.richfaces.component.UIOrderingList.restoreState(UIOrderingList.java:730)
	org.richfaces.component.html.HtmlOrderingList.restoreState(HtmlOrderingList.java:1397)
	javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1166)
	javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
	javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
	javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
	javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
	org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:439)
	com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:316)
	org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:107)
	com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:176)
	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
	com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
	com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
	org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
	org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
	org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
	org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Kann mir da jemand weiter helfen??????????????????????????????????

****************************************************
Hier die faces-config.xml:
****************************************************
  <?xml version="1.0" encoding="UTF-8" ?> 
- <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
- <managed-bean>
  <managed-bean-name>wonderbean</managed-bean-name> 
  <managed-bean-class>sevenwonder.WonderBean</managed-bean-class> 
  <managed-bean-scope>session</managed-bean-scope> 
  </managed-bean>
- <converter>
  <converter-id>wonderconverter</converter-id> 
  <converter-class>sevenwonder.WonderConverter</converter-class> 
  </converter>
  </faces-config>

****************************************************
Hier die index.jsp:
****************************************************
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>

<html>
  <head>
        <title>PRF39</title>
  </head>
  <body>
    <f:view>
    	<h:form>

				<richanel>
					<f:facet name="header">
						<hutputText value="Using richrderingList"/>
					</f:facet>

	      	<hanelGrid columns="3">

						<richrderingList id="myList" value="#{wonderbean.ancientWonders}" var="wonder" converter="wonderconverter" listWidth="350">
							<a4j:support event="onorderchanged" reRender="wonderList"/>
							<f:facet name="caption">
								<hutputText value="Wonders in the ancient world"/>
							</f:facet>
							<h:column>
								<f:facet name="header">
									<hutputText value="Name:"/>
								</f:facet>
								<hutputText value="#{wonder.name}"/>
							</h:column>
							<h:column>
								<f:facet name="header">
									<hutputText value="Location:"/>
								</f:facet>
								<hutputText value="#{wonder.location}"/>
							</h:column>
						</richrderingList>

	      		<rich:dataOrderedList id="wonderList" value="#{wonderbean.ancientWonders}" var="wonder">
							<hutputText value="#{wonder.name}, #{wonder.location}"/>
	      		</rich:dataOrderedList>
	      	</hanelGrid>

				</richanel>

    	</h:form>
    </f:view>
  </body>
</html>

****************************************************
Hier die Wonder.java:
****************************************************

```
package sevenwonder;
 
import javax.annotation.*;

public class Wonder { 
  
   private String name; // setter and getter
   private String location; // setter and getter
 
   public Wonder(String name, String location) 
   {
  	super();
		this.name = name;
		this.location = location;
   } 

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}
	
	public String toString() {
		return name+":"+location;
	}
	
	@Override 
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((location == null) ? 0 : location.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) 
	{
		if (this == obj) return true;
		if (this == null) return false;
		if (getClass() != obj.getClass()) return false;
		
		final Wonder other = (Wonder) obj;

		if (location == null) 
		{
			if (other.location != null) return false;
		}
		else if (!location.equals(other.location)) return false;
		
		if (name == null) 
		{
			if (other.name != null) return false;
		}
		else if (!name.equals(other.name)) return false;
		
		return true;
	}
	
}
```

****************************************************
Hier die WonderBean.java:
****************************************************

```
package sevenwonder;

import java.util.*;  
import javax.annotation.PostConstruct;

public class WonderBean {
   private List <Wonder> ancientWonders=null;
   private int wonderIndex;
    
   public WonderBean() {
		super();
   }
   
   @PostConstruct
   public void init() {
		ancientWonders = new ArrayList <Wonder>(); 
		ancientWonders.add(new Wonder("Chichen Itza", "Mexico"));
		ancientWonders.add(new Wonder("Christ the Redeemer", "Brazil"));
		ancientWonders.add(new Wonder("Colosseum", "Italy"));
		ancientWonders.add(new Wonder("Great Wall of China", "China"));
		ancientWonders.add(new Wonder("Machu Picchu", "Peru"));
		ancientWonders.add(new Wonder("Taj Mahal", "India"));	
   } 
   
   public String getInit() {
 		return "";
 	}
   
   public int getWonderIndex() { 
		return wonderIndex; 
	}

	public void setWonderIndex(int wonderIndex) {
		this.wonderIndex = wonderIndex;
	}
 
   public List<Wonder> getAncientWonders() {
		return ancientWonders;
	}

	public void setAncientWonders(List<Wonder> ancientWonders) {
		this.ancientWonders = ancientWonders;
		for(int i=0; i<ancientWonders.size(); i++) {
			System.out.println("ancientWonders Name ("+i+")="+ancientWonders.get(i).getName());
		} 
	}
}
```

****************************************************
Und last nit Least hier die WonderConverter.java:
****************************************************

```
package sevenwonder;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
 
public class WonderConverter implements Converter 
{ 
	public Object getAsObject(FacesContext context, UIComponent component, String value) 
	{
		String[] words = value.split(":");
		String name = words[0];
		String location = words[1];
		
		Wonder wonder = new Wonder(name, location);
		
		return (Object)wonder;
	}
	
	public String getAsString(FacesContext context, UIComponent component, Object value)
	{
		return value.toString();
	}
}
```

Vielen Dank im Voraus!

Grüße, Werner


----------



## nocturn (17. Jul 2009)

Jaha! Das ist ein besonderes Problem mit Richfaces.

Es betrifft nicht den Converter sondern den Hash-Wert der Liste!

JSF erwartet einen anderen Hash-Wert beim Getter- als beim Setter.
Das soll bewirken das du gezwungen bist die Liste neu zu erstellen.
Gott weiß warum.


----------



## whutmach (29. Jul 2009)

Habe die Liste neu erstellt via: 

   public List<Wonder> getAncientWonders() {
        return new ArrayList<Wonder>(ancientWonders);
    }

Aber leider:
============================================================
10:05:23,501 ERROR [lifecycle] JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.L

10:05:23,504 ERROR [BaseXMLFilter] Exception in the filter chain
javax.servlet.ServletException: sevenwonder.Wonder
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
        at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
        at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:91)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:92)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalStateException: sevenwonder.Wonder
        at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:109)
        at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1441)
        at org.richfaces.component.UIOrderingList$ValueHolder.restoreState(UIOrderingList.java:196)
        at org.richfaces.component.UIOrderingList.restoreState(UIOrderingList.java:730)
        at org.richfaces.component.html.HtmlOrderingList.restoreState(HtmlOrderingList.java:1397)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1166)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:439)
        at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:316)
        at org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:107)
        at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:176)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
        ... 25 more
10:05:23,544 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: sevenwonder.Wonder
        at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:109)
        at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1441)
        at org.richfaces.component.UIOrderingList$ValueHolder.restoreState(UIOrderingList.java:196)
        at org.richfaces.component.UIOrderingList.restoreState(UIOrderingList.java:730)
        at org.richfaces.component.html.HtmlOrderingList.restoreState(HtmlOrderingList.java:1397)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1166)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
        at org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:439)
        at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:316)
        at org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:107)
        at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:176)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
        at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
        at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:91)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:92)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
============================================================

Hat irgendjemand 'ne Idee dazu?

LG, Werner


----------



## whutmach (7. Aug 2009)

Schade, scheint sich wohl um nen Bug zu handeln, oder?


----------



## whutmach (7. Aug 2009)

Rome wasn't built in one day:
The class that will be displayed in the list must implement the <code>java.io.Serializable</code> interface.


----------



## nocturn (7. Aug 2009)

Verdammt, deine Antworten nicht mitbekommen.
Da wäre ich aber auch nicht drauf gekommen!


----------

