[
https://jira.jboss.org/jira/browse/RF-8519?page=com.atlassian.jira.plugin...
]
Rodrigo Mesquita commented on RF-8519:
--------------------------------------
Hi Leonid...
Well... i got this working with this:
// Pagina
<rich:comboBox value="#{controleAction.despesaSelecionada}"
suggestionValues="#{controleAction.valoresT}"
converter="conversorEnum" />
//Action.java
private TipoDespesa despesaSelecionada;
public List<TipoDespesa> getValoresT(){
List<TipoDespesa> valores = new ArrayList<TipoDespesa>();
for (TipoDespesa tipo : TipoDespesa.values()){
valores.add(tipo);
}
return valores;
}
//Converter using Seam... if using JSF, remove the notations and reference it on
faces-config.xml
package util;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.faces.Converter;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
/**
* Classe utilitária que realiza a conversão de valores
* Enum do TipoDespesa
* @author Rodrigo
*/
@Name("conversorEnum")
@BypassInterceptors
@Converter
public class ConversorEnum implements javax.faces.convert.Converter{
/**
* Transforma a string em Enum
*/
public Object getAsObject(FacesContext arg0, UIComponent arg1, String valorTela)
throws ConverterException {
if(valorTela == null || valorTela.toString().trim().equals("")){
return null;
}
for (TipoDespesa tipo : TipoDespesa.values()){
if (tipo.getDescricao().compareToIgnoreCase(valorTela) == 0){
return tipo;
}
}
return null;
}
/**
* Converte um TipoDespesa para String
*/
public String getAsString(FacesContext arg0, UIComponent arg1, Object valorTela)
throws ConverterException {
if(valorTela == null || valorTela.toString().trim().equals("")){
return "";
}
TipoDespesa tipo = (TipoDespesa) valorTela;
return tipo.getDescricao();
}
}
// Enum TipoDespesa
public enum TipoDespesa {
ESSENCIAL("Essencial"),
SUPERFLUA("Não essencial");
private String descricao;
TipoDespesa(String descricao){
this.descricao = descricao;
}
public String getDescricao() {
return descricao;
}
}
Can't create combo box with list of enums
-----------------------------------------
Key: RF-8519
URL:
https://jira.jboss.org/jira/browse/RF-8519
Project: RichFaces
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: component
Affects Versions: 3.3.1
Environment: Windows, JBoss 4.2.2.GA
Reporter: Leonid Sokolin
Assignee: Nick Belaevski
Attachments: piQueryToolCommon.xhtml, TrailingPeriods.java
I am trying to use a combo box, which would show the list of objects of the enum class,
but it throws the exception below as I open the page.
I am able to use to the same list for shuttle list though. Could anybody help?
11:47:05,140 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw
exception
java.lang.ClassCastException: com.nb.pi.processor.beans.TrailingPeriods
at
org.richfaces.renderkit.ComboBoxBaseRenderer.encodeItems(ComboBoxBaseRenderer.java:96)
at org.richfaces.renderkit.html.ComboBoxRenderer.doEncodeEnd(ComboBoxRenderer.java:558)
at org.richfaces.renderkit.html.ComboBoxRenderer.doEncodeEnd(ComboBoxRenderer.java:587)
at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:279)
at
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
at
com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:117)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
at
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
at
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
at
com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:117)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
at
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:510)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
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:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira