JSF panelGrid does not work

Asked

Viewed 110 times

2

The code below should show a simple screen divided between the names and input areas, but the panelGrid is not working, what’s wrong? When executing nothing appears.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Cadastro de Automoveis</title>
    </h:head>
    <h:body>
        <h:form>

                <h:outputLabel value="Marca:"/>
                <h:inputText value="#{automovelBean.automovel.marca}"/><br/>
                <h:outputLabel value="Modelo:"/>
                <h:inputText value="#{automovelBean.automovel.modelo}"/>
                <h:outputLabel value="Ano de Fabricação:"/>
                <h:inputText value="#{automovelBean.automovel.anoFabricacao}"/>
                <h:outputLabel value="Ano do Modelo:"/>
                <h:inputText value="#{automovelBean.automovel.anoModelo}"/>
                <h:outputLabel value="Observações:"/>
                <h:inputTextarea value="#{automovelBean.automovel.observacoes}"/>

                <h:commandButton value="Salvar" action="#{AutomovelBean.salva}"/>

        </h:form>
    </h:body>
</html>

3 answers

2

the elements must be inside the tag and for a better nesting, use the 'for'.

example

<h:outputLabel for="txt" value="texto1"/>
<h:inputText id="txt value="#{seuBeam.texto1}"/>

it is also valid to use empty h:outputLabel to occupy a space in the panelGrid column.

2

The elements inside the panelGrid must be all JSF elements. Plain text is not JSF element, try to put the texts inside the Component outputLabel. Also no need to put the elements br, once panelGrid generates a table (table).

            <h:panelGrid columns="2">
                <h:outputLabel for="marca" value="Marca:" />
                <h:inputText id="marca" value="#{automovelBean.automovel.marca}"/>
                <h:outputLabel for="modelo" value="Modelo:" />
                <h:inputText id="modelo" value="#{automovelBean.automovel.modelo}"/>
                <h:outputLabel for="anoFabricacao" value="Ano de fabricação:" />
                <h:inputText id="anoFabricacao" value="#{automovelBean.automovel.anoFabricacao}"/>
                <h:outputLabel for="anoModelo" value="Ano do modelo:" />
                <h:inputText id="anoModelo" value="#{automovelBean.automovel.anoModelo}"/>
                <h:outputLabel for="obs" value="Observações:" />
                <h:inputTextarea id="obs" value="#{automovelBean.automovel.observacoes}"/>

                <h:commandButton value="Salvar" action="#{AutomovelBean.salva}"/>
            </h:panelGrid>
  • 1

    Now nothing else appears on the screen. I have checked the libraries, it is all right but nothing appears.

  • @Edsonferreira edit your question and post your new code after the suggestion.

0

After I put the "for," it all went away, too:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
  
<h:head></h:head>

<h:body>
    <h:form>
        <h:panelGrid columns="2">       
            <h:outputLabel for="id" Value="Id" />
            <h:inputText id="id" readonly="true"
                value="#{usuarioPessoaManagedBean.usuarioPessoa.id}"/>
        
            <h:outputLabel for="nome" Value="Nome" />
            <h:inputText id="nome" value="#{usuarioPessoaManagedBean.usuarioPessoa.nome}"/>

            <h:outputLabel for="sobrenome" Value="Sobrenome" />
            <h:inputText
                id="sobrenome" value="#{usuarioPessoaManagedBean.usuarioPessoa.sobrenome}"/>

            <h:outputLabel for="email" Value="Email" />
            <h:inputText id="email" value="#{usuarioPessoaManagedBean.usuarioPessoa.email}"/>

            <h:outputLabel for="login" Value="Login" />
            <h:inputText id="login" value="#{usuarioPessoaManagedBean.usuarioPessoa.login}"/> 

            <h:outputLabel for="senha" Value="Senha" />
            <h:inputSecret id="senha" value="#{usuarioPessoaManagedBean.usuarioPessoa.senha}"/>

            <h:outputLabel for="idade" Value="Idade" />
            <h:inputText id="idade" value="#{usuarioPessoaManagedBean.usuarioPessoa.idade}"/>
            
        </h:panelGrid>      
    </h:form>
</h:body>
</html>

I see some people use h:, sometimes p:. The person who introduced me to jsf (I’m developer .net), uses "h:" and worked well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.