美好的一天! 我在JSF遇到困难(必须是这项技术,因为这是我在家里学习的东西) 我很难设置布尔值组件并根据类型呈现显示形式。这两种情况如下:
代码在我的[bitbucket链接] [1]上。我不知道为什么,但编辑无法捕获我的降价代码。我把The code into here
放在了@ anotations上。
[我的双髻链接] [1]
(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{
}
(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();
}
}
(LocalPrivado)
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;
}
}
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();
}
}
我想设置“available(boolean)”的值。这是我在xhtml中的表现。
但是组件h:selectOneRadio没有出现!
<!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>
我想创建一个主页,您可以在其中选择一个组件,用于选择该地点是公共还是私有。如果该网站是公开的,我会提供一个panelGrid,其中包含上面显示的publico.xhtml页面或其内容。如果这个地方是私人的,我会提供一个带有privado.xhtml页面或其内容的panelGrid。我没有完成该页面,但与publico.xhtml非常相似。
我想到了一个很好的LocalBean类。
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;
}
}
和xhtml:
<!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>
我不知道怎么做!!!!
有人可以帮助我吗?
谢谢!!!
答案 0 :(得分:0)
首先, 您可以尝试使用selectItem
的xhtml代码<f:selectItem itemLabel="true" itemValue="true" />
<f:selectItem itemLabel="false" itemValue="false" />