Dindi
Agosto 31, 2010, 10:56am
#1
Bom dia!
Estou com uma dúvida em JSF.
Quando coloco o codigo abaixo:
JSP:
<tr>
<td>
<h:outputLabel id="name">Nome</h:outputLabel> <br />
<h:inputText maxlength="50" id="nomeFrutaLocalizar" value="#{frutaMB.fruta.nome}" />
</td>
</tr>
-> Ele renderiza, a caixa do inputText mas com o valor #{frutaMB.fruta.nome} dentro dela;
-> Ele também não lê o valor da tag, quando passo para meu ManagedBean.(Através de commandButton)
Grata
Oi…!
O seu manageg bean está corretamente registrado no Facesconfig.xml?
Manda o Facesconfig pra gente dar uma olhada.
[]s
lpalma
Agosto 31, 2010, 1:05pm
#3
Parece ser problema mesmo de configuração… manda o faces-config igual o grau.soares disse para podermos tentar te ajudar…
Verifique também o cabeçalho do jsp e se o h:inputText está devidamente dentro de um h:form .
Dindi
Setembro 1, 2010, 9:00am
#4
Oi Meninos…
Segue o faces-config, importante ressaltar que as action dos commandButton funcionam
<?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>frutaMB</managed-bean-name>
<managed-bean-class>com.br.sicf.controler.mb.FrutaMB</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>sicfMB</managed-bean-name>
<managed-bean-class>com.br.sicf.controler.mb.SICFMB</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<!-- Navegação Servico -->
<navigation-rule>
<display-name>home</display-name>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>servico</from-outcome>
<to-view-id>/html/Pages/servico.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>sobre</from-outcome>
<to-view-id>/html/Pages/sobre.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<!-- Fim - Navegação Servico -->
</faces-config>
Vlw :roll:
mrbbm
Setembro 1, 2010, 10:59am
#5
Oi mocinha…
Tente mudar seu facesconfig para:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>frutaMB</managed-bean-name>
<managed-bean-class>com.br.sicf.controler.mb.FrutaMB</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>sicfMB</managed-bean-name>
<managed-bean-class>com.br.sicf.controler.mb.SICFMB</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<!-- Navegação Servico -->
<navigation-rule>
<display-name>home</display-name>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>servico</from-outcome>
<to-view-id>/html/Pages/servico.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>sobre</from-outcome>
<to-view-id>/html/Pages/sobre.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<!-- Fim - Navegação Servico -->
</faces-config>
Certifique-se também que fruta.nome, no seu MB, está com o valor zerado ou o valor que você está esperando!
Reinicie e faça os testes!
Olá eu sou novo no aprendizado do JSF e estou tendo a mesma dificuldade, já configurei o managed-bean, estou usando o JSF 1.2, meu web.xml também esta configurado corretamente, meu bean aparentemente também esta ok, só que não consigo receber ou passar para o bean o valor do inputText segue abaixo os codes…
web.xml
[code]<?xml version="1.0"?>
javax.faces.STATE_SAVING_METHOD
client
javax.faces.CONFIG_FILES
/WEB-INF/faces-config.xml
com.sun.faces.config.ConfigureListener
Faces Servlet
javax.faces.webapp.FacesServlet
1
Faces Servlet
*.jsf
[/code]
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
<navigation-rule>
<from-view-id>/buscar.jsp</from-view-id>
<navigation-case>
<from-outcome>sucess</from-outcome>
<to-view-id>/sucesso_busca.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/falha_busca.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/inserir.jsp</from-view-id>
<navigation-case>
<from-outcome>sucess</from-outcome>
<to-view-id>/sucesso_insercao.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/falha_insercao.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>agenda</managed-bean-name>
<managed-bean-class>AgendaDB</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
meu bean
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class AgendaDB {
private String nome = blank;
private String endereco = blank;
private String cidade = blank;
private String telefone = blank;
private String result_busca = blank;
private String result_inserir = blank;
public static final String BUSCA_INVALIDA = "failure";
public static final String BUSCA_VALIDA = "success";
public static final String SUCESSO_INSERCAO = "success";
public static final String FALHA_INSERCAO = "failure";
static Connection conn = null;
static PreparedStatement stm = null;
static ResultSet rs;
static private String blank = "";
public AgendaDB() {
if (conn == null) {
try {
AcessoBD bd = new AcessoBD();
conn = bd.obtemConexao();
} catch (Exception evento) {
System.out.print(evento.getStackTrace());
}
}
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getTelefone() {
return telefone;
}
public String inserir() {
String result_inserir = FALHA_INSERCAO;
String sqlInsert = "INSERT INTO pessoa(nome,endereco,cidade,telefone) values('"
+ nome
+ "','"
+ endereco
+ "','"
+ cidade
+ "','"
+ telefone
+ "')";
try {
stm = conn.prepareStatement(sqlInsert);
stm.executeQuery();
stm.close();
result_inserir = SUCESSO_INSERCAO;
} catch (SQLException eventoInsert) {
System.err.println("Erro: " + eventoInsert);
result_inserir = FALHA_INSERCAO;
}
return result_inserir;
}
public String buscar() throws SQLException {
String result_busca = BUSCA_INVALIDA;
String sqlSelect = "SELECT * FROM pessoa WHERE nome = '" + nome + "'";
try {
stm = conn.prepareStatement(sqlSelect);
rs = stm.executeQuery();
if (rs.next()) {
nome = rs.getString(1);
endereco = rs.getString(2);
cidade = rs.getString(3);
telefone = rs.getString(4);
result_busca = BUSCA_VALIDA;
} else {
result_busca = BUSCA_INVALIDA;
}
rs.close();
stm.close();
} catch (SQLException eventoSelect) {
System.err.println("Erro: " + eventoSelect);
}
return result_busca;
}
}
parte do cod da página de busca
<h:form>
<h:inputText id="nome" value="#{agenda.nome}" />
<h:commandButton value="OK" action="#{agenda.buscar}" />
</h:form>
<br>
<h:outputLink value="index.jsf">
<f:verbatim>voltar</f:verbatim>
</h:outputLink>