I can’t display anything in a JSF view

Asked

Viewed 82 times

1

I’m working on a web application to develop a module, but I can’t display anything in the view, not even a simple message.

The view loads the template, but does not display anything I put in the view. The only thing that is being displayed is the title in the browser tab, through the tag <ui:define>. Follow the code below:

View

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:p="http://primefaces.org/ui"
            xmlns:jsp="http://java.sun.com/JSP/Page"
            template="template.xhtml">

    <ui:define name="titulo">
        Ver Livros de Ordem
    </ui:define>

    <h:outputText value="#{verLivrosOrdemController.msg}" />

</ui:composition>

Managed Bean

package br.org.aplicacao.servicosOnline.controller;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class VerLivrosOrdemController implements Serializable {
    String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg() {
        this.msg = "Em breve!";
    }
}

1 answer

0


You have not entered the code of your template.

If you haven’t set it, you should set a body of your template to be able to display it.

Like you did with your title. Example:

<ui:composition ... template="template.xhtml">

    <ui:define name="titulo">
        Ver Livros de Ordem
    </ui:define>

    <ui:define name="conteudo">
        <h:outputText value="#{verLivrosOrdemController.msg}" />
    </ui:define>

</ui:composition>

Your template should look something like this:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">

  <h:head>
    <title>JSF 2.0 - Exemplo de template</title>
  </h:head>

  <h:body>

    <ui:insert name="titulo">
        <h1>Título da minha pagina</h1>
    </ui:insert>

    <ui:insert name="conteudo">
        Informações do conteúdo
    </ui:insert>

    <ui:insert name="rodape">
        Informações do rodapé
    </ui:insert>

  </h:body>

</html>

Reference:

  • 1

    That’s exactly what it was. Thank you!

Browser other questions tagged

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