pessoal estou com um problema em usar jsf 2 pois não estou conseguindo acessar as propriedades dos beans nas views
como por exemplo:
<f:view>
<h1><h:outputText value="#{Teste.teste}" /> </h1>
</f:view>
Agradeço se puderem me ajudar!
Abraços!
pessoal estou com um problema em usar jsf 2 pois não estou conseguindo acessar as propriedades dos beans nas views
como por exemplo:
<f:view>
<h1><h:outputText value="#{Teste.teste}" /> </h1>
</f:view>
Agradeço se puderem me ajudar!
Abraços!
posta a sua Bean para nós.
aqui amigo!!!
package managed.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="Teste")
@SessionScoped
public class MyManagedBean {
private String teste = "teste";
public MyManagedBean() {
}
public String getTeste() {
return "testes";
}
public void setTeste(String teste) {
this.teste = teste;
}
}
estou iniciando com o jsf
não o conheço direito ainda
Obrigado!
Sua view:
<f:view>
<h1><h:outputText value="#{Teste.teste}" /> </h1>
</f:view>
Seu Bean deve estar assim:
public class Teste {
private String teste;
public void setTeste(String teste) {
this.teste = teste;
}
public String getTeste() {
return teste;
}
}
Assim você consegue acessar o atributo teste!
xD~~
mais ai ele deve estar mapeado no xml ou posso usar as annotation?
ele estava parecido com isso só que mesmo assim não funcionava por isso tentei mudar para ver se funcionava.
desculpe me, mais é que sou iniciante ainda.
Obrigado!
agora está assim
view:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<f:view>
<h1><h:outputText value="#{MyManagedBean.teste}" /> </h1>
<h:form>
<h:inputText value="#{MyManagedBean.teste}"/>
<h:commandButton action="#{MyManagedBean.testes}" value="testes"/>
</h:form>
</f:view>
</body>
</html>
Bean:
package managed.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class MyManagedBean {
private String teste;
public String getTeste() {
return teste;
}
public void setTeste(String teste) {
this.teste = teste;
}
public String testes(){
return "welcome.faces";
}
}
só que está dando erro
Stack Trace é essa
javax.faces.FacesException: org.apache.jasper.el.JspPropertyNotFoundException: /welcome.jsp(17,3) '#{MyManagedBean.teste}' Target Unreachable, identifier 'MyManagedBean' resolved to null
at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:191)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.myfaces.webapp.MyFacesServlet.service(MyFacesServlet.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.jasper.el.JspPropertyNotFoundException: /welcome.jsp(17,3) '#{MyManagedBean.teste}' Target Unreachable, identifier 'MyManagedBean' resolved to null
at org.apache.jasper.el.JspValueExpression.getType(JspValueExpression.java:63)
at org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.findUIOutputConverter(_SharedRendererUtils.java:77)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.findUIOutputConverter(RendererUtils.java:407)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUIOutputValue(RendererUtils.java:769)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.getConvertedValue(HtmlTextRendererBase.java:274)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:615)
at javax.faces.component.UIInput.validate(UIInput.java:547)
at javax.faces.component.UIInput.processValidators(UIInput.java:244)
at javax.faces.component.UIForm.processValidators(UIForm.java:137)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1218)
at javax.faces.component.UIViewRoot._processValidatorsDefault(UIViewRoot.java:1290)
at javax.faces.component.UIViewRoot.access$500(UIViewRoot.java:73)
at javax.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1337)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1246)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:722)
at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:34)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
... 18 more
Obrigado desde já
agora está assim…
Tenta dar um nome para sua Bean:
@ManagedBean(name="nomeDaBean")
Depois acessa-o com EL:
#{nomeDaBean.atributo}
Tenta usar assim:
action="#{myManagedBean.testes}"
Caso você de um nome para seu ManagedBean…
Ex:
@ManagedBean(name="MyManagedBean")
action="#{MyManagedBean.testes}"
@ManagedBean
action="#{myManagedBean.testes}"
Eu uso sem colocar nomes!!
xD~~
cara pior que ainda estou com problemas
meu bean
package testes;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@SessionScoped
@ManagedBean
public class MyBean {
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String testes(){
return "welcome.faces";
}
}
minha view:
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<f:view>
<h1><h:outputText value="Teste"/></h1>
<h:form>
<h:inputText value="#{myBean.nome}"></h:inputText>
<h:commandButton action="#{myBean.testes}" value="testes"/>
</h:form>
</f:view>
</body>
</html>
Obrigado desde já
Qual o problema agora??
Posta pra gente ver ai!!
xD~~
O mesmo erro cara
não sei se é alguma configuração
exception
javax.servlet.ServletException: /welcome.jsp(18,2) '#{myBean.nome}' Target Unreachable, identifier 'myBean' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
root cause
org.apache.jasper.el.JspPropertyNotFoundException: /welcome.jsp(18,2) '#{myBean.nome}' Target Unreachable, identifier 'myBean' resolved to null
org.apache.jasper.el.JspValueExpression.getType(JspValueExpression.java:63)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1008)
javax.faces.component.UIInput.validate(UIInput.java:934)
javax.faces.component.UIInput.executeValidate(UIInput.java:1189)
javax.faces.component.UIInput.processValidators(UIInput.java:691)
javax.faces.component.UIForm.processValidators(UIForm.java:243)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1180)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
abraços
Tenta colocar assim:
@ManagedBean(name="myBean")
cara você não sabe onde eu posso baixar alguns exemplos para o eclipse?
pois continua com o mesmo problema.
Obrigado!
Infelizmente eu não sei amigo.
Eu uso netbeans!
xD~~
tenta trocar o por <h:body> e por </h:body>
e faz a mesma coisa no head
por e porprovavelmente seja isso
!
vou tentar fazer no netbeans para ver se funciona pois continua com erro
Obrigado desde Já!
cara é incrivel com o netbeans ele funciona!!!
muito estranho!!!
Cara eu tava com o mesmo erro, tentei trocar o @RequestedScope para @SessionScoped e nada, troquei de @Named pra @ManagedBean e nada… só foi rodar depois que de um Clean no projeto e no Tomcat. Tenta ai.
Amigo, estava com o mesmo problema e ví o que era…
Veja se você importou a biblioteca certa:
Como o eclipse vai completando tudo pra gente, às vezes a gente importa coisa errada…
A correta é: import javax.faces.bean.ManagedBean;
Outra coisa, sempre que você tiver uma classe bean, não precisa mudar o nome dela. na hora que você for acessar alguma informação dela pela view, basta chamar o mesmo nome, porém com a primeira letra minúscula.
Por exemplo:
public class TelaBean { (…) }
private int id;
(VIEW)
#{telaBean.id}
Espero que ajude =]
(E desculpe a resposta rápida e porca…)
~Guihen