JSF - Parameter passing

0

I have a form in JSF and I need to insert the data of it into the database I have already researched in several ways, but it is not working

Could you give me a hand in what I'm doing wrong? JSF

Form

I am not able to pass the parameter of what is being entered for insertion into the database:

@ManagedBean(name="UsuarioJDCBDAO")

public void inserir(Usuario usuario) {

try {

Connection conexao = getConexao();

String value = null; Statement stmt = null; conexao.createStatement().execute("SET IDENTITY_INSERT "+"tbplan"+" ON"); stmt = conexao.createStatement(); ResultSet rs = stmt.executeQuery("select MAX(id) + 1 from tbplan");

while (rs.next()) value = rs.getString(1).toString();

System.out.println(value);

PreparedStatement pstm = conexao .prepareStatement("Insert into tbplan (data, nome, frase, id) values (?,?,?,?)");

//String name = new Usuario().getNome(); //pstm.setDate(1, new java.sql.Date(usuario.getDataCadastro().getTime())); pstm.setString(1, "26 Jun 2017 14:28:00:00");

pstm.setString(2, usuario.getNome());

// pstm.setString(2, n1.getNome()); pstm.setString(3, usuario.getFrase()); pstm.setString(4, value);

pstm.execute(); conexao.createStatement().execute("SET IDENTITY_INSERT "+"tbplan"+" OFF"); pstm.close(); conexao.close(); } catch (Exception e) { e.printStackTrace(); }

}

User Class

import java.io.Serializable; import java.util.Date;

public class Usuario implements Serializable {

private static final long serialVersionUID = -309513637403441998L;

private Long id;

private Date dataCadastro;

private String nome;

private String frase;

public Long getId() { return id; }

public void setId(Long id) { this.id = id; }

public Date getDataCadastro() { return dataCadastro; }

public void setDataCadastro(Date dataCadastro) { this.dataCadastro = dataCadastro; }

public String getNome() { return nome; }

public void setNome(String nome) { this.nome = nome; }

public String getFrase() { return frase; }

public void setFrase(String frase) { this.frase = frase; }

@Override public String toString() { return "Usuario [nome=" + nome + ", frase=" + frase + ", dataCadastro=" + dataCadastro + " id=" + id + "]"; }
}
    
asked by anonymous 05.07.2017 / 18:41

1 answer

-1
<ui:composition 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:p="http://primefaces.org/ui"
    template="/paginas/default/main.xhtml">

    <ui:define name="content">
        <h1 class="page-header ">
            <i class="fa fa-comments"></i> Formulário
        </h1>
                <div class="form-group">
        <div class="col-xs-2">

        <h:form>
            <b><h:outputText value="Nome: " /></b>
            <h:inputText class="form-control" id="nome" value="" />
            <br style="clear: left;" />
        </h:form>
        <h:form>
            <b><h:outputText value="Data: " /></b>
            <h:inputText class="form-control" value="#{now}">  
                <f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="America/Sao_Paulo"/>  
            </h:inputText>
            <br style="clear: left;" />

        </h:form>
        </div>
        <div class="col-md-8">
        <h:form>
            <td valign="top">
            <b><h:outputText title="Ajuda" value="Frase: " /></b>
            </td>
            <h:inputTextarea class="form-control"  cols="80" rows="8" id="frase" value="" />
        </h:form>
            </div>
            </div>
        <br style="clear: left;" />
        <div class="container">
</div>

<div class="col-xs-2">

<h:form>
                        <h:commandButton id="submitBtn"  var="item" value="Incluir" class="btn btn-success" action="#{UsuarioJDCBDAO.inserir(Usuario)}">
                            <f:param name="Nome" value="#{item.nome}" />
                            <f:param name="Data" value="#{item.dataCadastro}" />
                            <f:param name="Frase" value="#{item.frase}" />
                        </h:commandButton>
                    </h:form>
</div>
    </ui:define>
</ui:composition>

                      Form                                   

    <h:form>
        <b><h:outputText value="Nome: " /></b>
        <h:inputText class="form-control" id="nome" value="" />
        <br style="clear: left;" />
    </h:form>
    <h:form>
        <b><h:outputText value="Data: " /></b>
        <h:inputText class="form-control" value="#{now}">  
            <f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="America/Sao_Paulo"/>  
        </h:inputText>
        <br style="clear: left;" />

    </h:form>
    </div>
    <div class="col-md-8">
    <h:form>
        <td valign="top">
        <b><h:outputText title="Ajuda" value="Frase: " /></b>
        </td>
        <h:inputTextarea class="form-control"  cols="80" rows="8" id="frase" value="" />
    </h:form>
        </div>
        </div>
    <br style="clear: left;" />
    <div class="container">

                                                                                                                                                             
</ui:define>
    
05.07.2017 / 19:12