JSF panelGrid does not work

2

The code below should show a simple screen split between names and input areas, but panelGrid is not working, what's wrong? When running, 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>
    
asked by anonymous 06.11.2016 / 05:32

2 answers

2

Elements should be inside the tag and for better nesting, use 'for'.

example

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

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

    
07.11.2016 / 14:50
2

The elements inside the panelGrid should be all JSF elements. Plain text is not a JSF element, try putting the texts within the outputLabel component. You also do not need to put the elements br , since panelGrid generates a 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>
    
06.11.2016 / 10:54