Boolean component and rendered components do not appear on my page

Asked

Viewed 76 times

1

You guys! Good morning! I’m having a hard time here with JSF (it has to be this technology, because it’s the one I’m currently studying at home) I’m having trouble setting boolean component values and rendering 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{    
}

(Private locale.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();
    }
}

(Localprivadobean)

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)". See how I did 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) The Location type rendering: 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 Google panelGrid with the public.xhtml page that I presented above or its content. If the site is private, I want to present a panelGrid with the private.xhtml page or its contents. I have not yet made the page, but it will be very similar to the public.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 don’t know how to do this!!!!

Could someone help me?

Thank you!!!

  • I’ll play favorites to take a look, I’m no ambience here

No answers

Browser other questions tagged

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