Boa noite pessoal!!
Estou tendo problemas para carregar dados em um selectOneMenu, estou fazendo um exercício da apostila da K19, segui os passo certinhos mas não consigo fazer com que os dados sejam exibidos.
Meu ManagedBean
import java.util.HashMap;
import javax.annotation.ManagedBean;
@ManagedBean
public class ConversorMonetarioBean {
private String de;
private String para;
private double valor;
private double resultado;
public HashMap<String, Double> taxas = new HashMap<String, Double>();
public ConversorMonetarioBean(){
this.taxas.put("Real", 1.0);
this.taxas.put("Euro", 2.33);
this.taxas.put("Peso argentino", 0.42);
this.taxas.put("Dolar Americano", 1.84);
}
public void converte(){
this.resultado = this.valor * this.taxas.get(this.de) / this.taxas.get(this.para);
}
public String getDe() {
return de;
}
public void setDe(String de) {
this.de = de;
}
public String getPara() {
return para;
}
public void setPara(String para) {
this.para = para;
}
public double getValor() {
return valor;
}
public void setValor(double valor) {
this.valor = valor;
}
public double getResultado() {
return resultado;
}
public void setResultado(double resultado) {
this.resultado = resultado;
}
public HashMap<String, Double> getTaxas() {
return taxas;
}
public void setTaxas(HashMap<String, Double> taxas) {
this.taxas = taxas;
}
}
Meu arquivo 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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>K19 Treinamentos</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Converter" action="#{conversorMonetarioBean.converte}" />
<h:inputText value="#{conversorMonetarioBean.valor}"/>
<h:outputLabel value="De:" for="de"/>
<h:selectOneMenu value="#{conversorMonetarioBean.de}" id="de">
<f:selectItems
value="#{ConversorMonetarioBean.taxas.KeySet()}"
var="moeda"
itemValue="#{moeda}"
itemLabel="#{moeda}"/>
</h:selectOneMenu>
<h:outputLabel value="Para: " for="para"/>
<h:selectOneMenu value="#{conversorMonetarioBean.para}" id="para">
<f:selectItems
value="#{ConversorMonetarioBean.taxas.KeySet()}"
var="moeda"
itemValue="#{moeda}"
itemLabel="#{moeda}"/>
</h:selectOneMenu>
</h:form>
Resultado: #{conversorMonetarioBean.resultado}
</h:body>
</html>
Na apostila não é mencionado se é preciso realizar alguma implementação no método getTaxas!!
Já pesquisei em outros posts aqui do fórum e em outros sites, mas nenhum diz se há a necessidade de criar uma função a qual seria vinculada ao selectOneMenu.
Agradeço à todos pelo ajuda!