Salve galera do Portal Java, estou com problema, eu tenho a seguinte URL:
http://localhost:8080/Teste/cadastro.faces?identificador=78
Na pagina onde estao as minhas tags em JSF como que eu faço para pegar o valor do identificador da URL e passar ele para uma classe. Eu estou tentando usar Expression Language mas esta dando erro.
Valeu mais uma vez galera!!!
por favor cole o scream da sua tela pra gente.
Na sua classe vc deve ter um atributo “identificador” com o gets e sets , caso queira esse valor para uma acao posterior coloque ele como um hidden na sua jsp.
<h:inputHidden value="#{identificacao}"></h:inputHidden>
att
jVander
De cara, JSF não trabalha bem com dados do tipo GET, mas vamos relevar:
Se você não tratar este parâmetro no teu bean você terá que pegar o valor dele usando JSTL da seguinte forma: {param.identificacao}
:okok:
Galera,
Eu tentei fazer igual vcs falaram, so que nao funcionou. Segue os jsp’s e a classe de teste. EU NAO SEI MAS O QUE FAZER.
index.jsp
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page</h1>
<br/>
<f:view>
<h:form id="form1">
<h:outputLink value="TesteJSF.jsf?identificador=45">
<h:outputText value="Teste" />
</h:outputLink>
</h:form>
</f:view>
</body>
</html>
TesteJSF.jsp
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<f:view>
<h:form id="form">
<h1><h:outputText value="JavaServer Faces" /></h1>
<h:commandButton id="teste" action="#{Teste.teste}" />
<h:inputHidden id="identificador" value="#{Teste.identificador}" />
</h:form>
</f:view>
</body>
</html>
Teste.java
package com.teste;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
public class Teste {
private String identificador;
/** Creates a new instance of Teste */
public Teste() {
}
public String getIdentificador() {
return identificador;
}
public void setIdentificador(String identificador) {
this.identificador = identificador;
}
public void teste(){
try {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest)context.getRequest();
String teste = request.getParameter("identificador");
System.out.println("Teste");
} catch (Exception e) {
e.printStackTrace();
}
}
}
O getParameter so me retona null; o getRequestParameterMap() me retorna null tambem. onde estou errando?
Obrigado mais uma vez