Boolean component and rendered components do not appear on my page

1

Galera! Good Morning! I'm having a hard time here with JSF (it has to be this technology as it's the one I'm currently studying at home) I am having problem to set boolean component values and render form view according to type. The two situations are as follows:

1) Boolean components.

The codes:

(Local.java)

package model;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

@Entity
@Table(name="local")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "Local_Type", discriminatorType = DiscriminatorType.STRING)
public abstract class Local {

    @Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
    private long id;

    private String nome;
    private String zona;
    private String bairro;
    private String rua;
    private String numero;
    private String cep;
    private boolean disponivel;

    public long getId() {
        return id;
    }

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

    public String getZona() {
        return zona;
    }

    public void setZona(String zona) {
        this.zona = zona;
    }

    public String getBairro() {
        return bairro;
    }

    public void setBairro(String bairro) {
        this.bairro = bairro;
    }

    public String getRua() {
        return rua;
    }

    public void setRua(String rua) {
        this.rua = rua;
    }

    public String getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }

    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }

    public boolean isDisponivel() {
        return disponivel;
    }

    public void setDisponivel(boolean disponivel) {
        this.disponivel = disponivel;
    }

    public String getNome() {
        return nome;
    }

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

package model;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;


@Entity
@DiscriminatorValue("local_publico")
public class LocalPublico extends Local{    
}

(LocalPrivate.java)

package model;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue("local_privado")
public class LocalPrivado extends Local{

    private double preco;

    public double getPreco() {
        return preco;
    }

    public void setPreco(double preco) {
        this.preco = preco;
    }

}

(LocalPublicoBean)

package controller;

import javax.faces.bean.ManagedBean;

import model.LocalPublico;
import dao.DAO;

@ManagedBean
public class LocalPublicoBean {
    private LocalPublico localPublico = new LocalPublico();

    public LocalPublico getLocalPublico() {
        return this.localPublico;
    }

    public void gravar() {
        System.out.println("Gravando evento " + localPublico.getNome()
                + " no banco de dados.");
        new DAO<LocalPublico>(LocalPublico.class).adiciona(this.localPublico);
        System.out.println("Evento " + localPublico.getNome()
                + " gravado no banco.");

        LocalPublico cid = new LocalPublico();
    }
}

(LocalPrivateBean)

package controller;

import javax.faces.bean.ManagedBean;

import model.LocalPrivado;
import dao.DAO;

@ManagedBean
public class LocalPrivadoBean {
    private LocalPrivado localPrivado = new LocalPrivado();

    public LocalPrivado getLocalPublico() {
        return this.localPrivado;
    }

    public void gravar() {
        System.out.println("Gravando evento " + localPrivado.getNome()
                + " no banco de dados.");
        new DAO<LocalPrivado>(LocalPrivado.class).adiciona(this.localPrivado);
        System.out.println("Evento " + localPrivado.getNome()
                + " gravado no banco.");

        LocalPrivado cid = new LocalPrivado();
    }
}

Doubt: I want to set the value of "available (boolean)". Here's how I did it in xhtml.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/model.core"
    xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Local</title>
</head>
<body>
    <h:form>
        <h:panelGrid>
            <fieldset>
                <legend>Cadastro de Local Público</legend>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Nome: " for="nome" />
                    <h:inputText id="nome"
                        value="#{localPublicoBean.localPublico.nome}" />
                    <h:outputLabel value="C.E.P.:" for="cep" />
                    <h:inputText id="cep" value="#{localPublicoBean.localPublico.cep}" />
                    <h:outputLabel value="Disponível: " for="is_disponivel" />
                    <h:selectOneRadio id="is_disponivel"
                        value="#{localPublicoBean.localPublico.disponivel}">
                        <f:selectItem itemLabel="true" itemValue="#{true}" />
                        <f:selectItem itemLabel="false" itemValue="#{false}" />
                    </h:selectOneRadio>

                </h:panelGrid>
            </fieldset>


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

However the h: selectOneRadio component does not appear!

2) Rendering the Location Type: I would like to create a local page, where I have a component where I select whether the location is public or private. If the site is public, I want to present a panelGrid with the public.xhtml page that I presented above or its contents. If the site is private, I want to present a panelGrid with the private page.xhtml or its contents. I have not yet made the page, but it will be very similar to the publico.xhtml.

I thought of a LocalBean class like this:

package controller;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class LocalBean {
    private String tipo = new String();


    public String getPublico(){
        return "publico";
    }

    public String getPrivado(){
        return "privado";
    }

    public String getTipo(){
        return this.tipo;
    }


}

And the xhtml something like:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:my="http://java.sun.com/jsf/composite/my">

<f:view>
    <!-- colocar aqui código para saber se página é pública ou privada -->
    <my:if condition="#{localBean.privado.equalsIgnoreCase(localBean.publico)}">
        <f:facet name="then">
            <!-- INCORPORAR PÁGINA publico.xhtml aqui -->
        </f:facet>
        <f:facet name="else">
            <!-- INCORPORAR PÁGINA privado.xhtml aqui -->
        </f:facet>
    </my:if>
</f:view>
</html>

I do not know how to do this !!!!

Could anyone help me?

Thank you !!!

    
asked by anonymous 17.11.2015 / 15:25

0 answers