Pessoal,
Estou aprendendo a mexer no Jboss Seam. E logo de cara estou enfrentando um problema.
Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(j_id14). Found null
Meu codigo
package br.com.caelum.aeris.logic;
import java.util.HashMap;
import java.util.Map;
import org.jboss.seam.annotations.Name;
import br.com.caelum.aeris.entities.Localidade;
@Name("localidadesHandler")
public class LocalidadesHandler {
public Map<String, Localidade> getLocalidades() {
System.out.println("Iniciando Localidades");
Map<String, Localidade> opcoes = new HashMap<String, Localidade>();
for (Localidade l : Localidade.values()) {
opcoes.put(l.getNome(), l);
}
return opcoes;
}
}
package br.com.caelum.aeris.entities;
public enum Localidade {
SAO_PAULO("São Paulo"), RIO_DE_JANEIRO("Rio de Janeiro"), NOVA_IORQUE(
"Nova Iorque"), PARIS("Paris"), LONDRES("Londres"), MOSCOU("Moscou");
private final String nome;
private Localidade(String nome) {
this.nome = nome;
}
public String getNome() {
return nome;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:rich="http://richfaces.org/rich">
<ui:composition template="/layout/template.xhtml">
<ui:define name="body">
<h1> Cadastro de Trechos </h1>
<h:form>
Origem:
<h:selectOneMenu>
<f:selectItems value="#{localidadesHandler.localidades}"/>
</h:selectOneMenu>
Destino:
<h:selectOneMenu>
<f:selectItems value="#{localidadesHandler.localidades}"/>
</h:selectOneMenu>
</h:form>
</ui:define>
</ui:composition>
</html>
Tiago,
Não tenho certeza(e estou com preguiça de olhar na doc do SEAM), mas acho que o componente UISelectItems não aceita um Map<String, T> como argumento.
Confirme se aceita. =)
Até mais.
Acho que é algum problema com o binding do seam.
Tentei fazer o binding de uma simples string imprimindo no xhtml. E ele não retorna nada.
Alguem sabe se tem q configurar alguma coisa no Seam pra ativar o binding?
pessoal,
realmente toh precisando de ajuda.
descobri que na verdade, o que está aocntecendo, é que não está sendo feito o bind.
Não sei o que pode ser. Alguem já passou por isso?
Tiago,
quando você coloca um atributo no seu managed-bean e o referencia em seu XHTML qual é o resultado?
Poste aqui o resultado, o código do XHTML, do ManagedBean e também o código fonte gerado no browser.
Abraço.
Removi a parte do SelectItem e coloquei um simples bind de String. Pois descobri que o problema está aí.
Meu XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:rich="http://richfaces.org/rich">
<ui:composition template="/layout/template.xhtml">
<ui:define name="body">
<h1> Cadastro de Trechos </h1>
<h:form>
<h:outputText value="#{localidadesHandler.origem}" />
<!-- <h:selectOneMenu>
<f:selectItems value="#{localidadesHandler.localidades}" />
</h:selectOneMenu>
Destino:
<h:selectOneMenu>
<f:selectItems value="#{localidadesHandler.localidades}"/>
</h:selectOneMenu>
-->
</h:form>
</ui:define>
</ui:composition>
</html>
Codigo fonte da tela apresentada
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>aeris</title>
<link class="component" href="/aeris/a4j/s/3_3_3.Finalorg/richfaces/renderkit/html/css/basic_classes.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__;jsessionid=9E88C6CBEE7FA027DDBD9ACE6C8F0EE6" rel="stylesheet" type="text/css" /><link class="component" href="/aeris/a4j/s/3_3_3.Finalorg/richfaces/renderkit/html/css/extended_classes.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__;jsessionid=9E88C6CBEE7FA027DDBD9ACE6C8F0EE6" media="rich-extended-skinning" rel="stylesheet" type="text/css" /><link class="component" href="/aeris/a4j/s/3_3_3.Finalcss/toolBar.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__;jsessionid=9E88C6CBEE7FA027DDBD9ACE6C8F0EE6" rel="stylesheet" type="text/css" /><script src="/aeris/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript" type="text/javascript"></script><script type="text/javascript">window.RICH_FACES_EXTENDED_SKINNING_ON=true;</script><script src="/aeris/a4j/g/3_3_3.Finalorg/richfaces/renderkit/html/scripts/skinning.js" type="text/javascript"></script><link class="user" href="/aeris/stylesheet/theme.xcss;jsessionid=9E88C6CBEE7FA027DDBD9ACE6C8F0EE6" rel="stylesheet" type="text/css" /><link class="user" href="/aeris/stylesheet/theme.css;jsessionid=9E88C6CBEE7FA027DDBD9ACE6C8F0EE6" rel="stylesheet" type="text/css" /><link rel="shortcut icon" href="/aeris/favicon.ico" />
</head>
<body><table border="0" cellpadding="0" cellspacing="0" class="rich-toolbar " id="j_id5" width="100%"><tr valign="middle"><td class="rich-toolbar-item " style=";">aeris:</td><td class="rich-toolbar-item " style=";"><a >Home</a></td><td class="rich-toolbar-item ">
<!-- @newMenuItem@ --></td><td style="width:100%"></td><td class="rich-toolbar-item " style=";"><a >Login</a></td></tr></table>
<div class="body">
<h1> Cadastro de Trechos </h1>
<form id="j_id12" name="j_id12" method="post" action="/aeris/trechos.seam;jsessionid=9E88C6CBEE7FA027DDBD9ACE6C8F0EE6" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_id12" value="j_id12" />
<!-- <h:selectOneMenu>
<f:selectItems value="" />
</h:selectOneMenu>
Destino:
<h:selectOneMenu>
<f:selectItems value=""/>
</h:selectOneMenu> --><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id1" autocomplete="off" />
</form>
</div>
<div class="footer">
<p>Powered by <a href="http://seamframework.org">Seam</a> 2.2.2.Final and <a href="http://www.jboss.org/jbossrichfaces">RichFaces</a>. Generated by seam-gen.</p><script id="j_id17" type="text/javascript">LOG.registerPopup('D','LogWindow',800,600,LOG.ALL);</script>
<p >
Conversation: id = 1, temporary
-
Ajax4jsf Log (Ctrl+Shift+D)
- <a target="debugConsole">Debug console</a>
- <a >Terminate session</a>
</p>
</div>
</body>
</html>
Meu managed Bean
package br.com.caelum.aeris.logic;
import java.util.HashMap;
import java.util.Map;
import org.jboss.seam.annotations.Name;
import br.com.caelum.aeris.entities.Localidade;
@Name("localidadesHandler")
public class LocalidadesHandler {
public Map<String, Localidade> getLocalidades() {
System.out.println("Iniciando Localidades");
Map<String, Localidade> opcoes = new HashMap<String, Localidade>();
for (Localidade l : Localidade.values()) {
opcoes.put(l.getNome(), l);
}
return opcoes;
}
//atributo de teste
private String origem = "Origem";
public String getOrigem() {return origem;}
public void setOrigem(String origem) {this.origem = origem;}
}
Meu Entity
package br.com.caelum.aeris.entities;
import java.io.Serializable;
public enum Localidade implements Serializable {
SAO_PAULO("São Paulo"), RIO_DE_JANEIRO("Rio de Janeiro"), NOVA_IORQUE(
"Nova Iorque"), PARIS("Paris"), LONDRES("Londres"), MOSCOU("Moscou");
private final String nome;
private Localidade(String nome) {
this.nome = nome;
}
public String getNome() {
return nome;
}
}
Se você colocar um breakpoint no getOrigem ele para?
Coloca um escopo qualquer no seu ManagedBean apenas para não deixar o padrão(“unspecified”).
Coloquei o @Scope para APPLICATION
Coloquei um breakpoint, Ele nem entra no getOrigem
tentei colocar System.out.println ali tambem, e nada…
Como vc acessa sua URL?
Posta o link que você está usando para testes.
O nome do xhtml é trechos.xhtml
A url que eu estou utiliznando é esta aki
http://localhost:8080/aeris/trechos.seam
Aí vai uma copia do meu faces-config
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
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"
version="1.2">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>bg</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>en</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>tr</supported-locale>
</locale-config>
</application>
</faces-config>
e do web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>aeris</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.jboss.jbossfaces.JSF_CONFIG_NAME</param-name>
<param-value>Mojarra-1.2</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
</web-app>
Tiago,
ainda não consegui identificar nenhum problema.
Faça um teste:
Deixe o seu XHTML o mais limpo possível, ou seja, não inclua nenhum template.
Apenas deixe o cabeçalho do XHTML e o outputText.
Mais ou menos assim:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:a4j="http://richfaces.org/a4j"
contentType="text/html">
<html>
<body>
ABC ( <h:outputText value="#{localidadesHandler.origem}"/> ) DEF...
</body>
</html>
</f:view>
Veja o resultado.
Poste o código-fonte gerado aí…
Até mais.
fabio
Muito obrigado pela sua ajuda.
Consegui descobrir o problema.
Ao criar o projeto no eclipse, o seam cria 4 projetos.
aeris
aeris-ear
aeris-ejb
aeris-test
Na apostila que eu estou utilizando, fala para criar a classe LocalidadesHandler dentro do projeto “aeris”
Junto com um amigo aki do trampo, tivemos a ideia de colocar esta classe dentro do “aeris-ejb”, e funcionou. A apostila estava errada.
Fica aí a solução para quem futuramente cair nessa armadilha.
Mais uma vez, obrigado!
Obrigado, colocar a solução tb me ajudou.