Olá, estou seguindo a apostila da K19 para entener melhor o JSF e estou tendo um problema e não consigo entender o que estou fazendo de errado…
O codigo da minha view abaixo, quando tento abri-lo o erro apresentado é:
/conversor-monetario.xhtml @29,25 value="#{conversorMonetarioBean.taxas.keySet()}": The class ‘br.com.k19.controle.ConversorMonetarioBean’ does not have the property ‘taxas’.
No trecho
<h:commandButton value="Converter"
action="#{conversorMonetarioBean.converte}"></h:commandButton>
O eclipse já aponta que a um erro, e ao usar o mesmo para tentar corrigir ele faz o seguinte:
<element>
<h:commandButton value="Converter"
action="#{conversorMonetarioBean.converte}">
</h:commandButton>
</element>
O que não resolve nada…
O que estou fazendo de errado?
[code]
<h:head>
K19 Treinamentos - Conversor Monetario
</h:head>
<h:body>
<h:form>
<h:commandButton value=“Converter"
action=”#{conversorMonetarioBean.converte}"></h:commandButton>
<h:inputText value="#{conversorMonetarioBean.valor}"></h:inputText>
<h:outputLabel value="de " for="de"></h:outputLabel>
<h:selectOneMenu value="#{conversorMonetarioBean.de}" id="de">
<f:selectItems
value="#{conversorMonetarioBean.taxas.keySet()}"
var="moeda"
itemValue="#{moeda}"
itemLabel="#{moeda}">
</f:selectItems>
</h:selectOneMenu>
<h:outputLabel value="para " for="para"></h:outputLabel>
</h:form>
Resultado: #{conversorMonetarioBean.resultado}
</h:body>
[/code]package br.com.k19.controle;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
@ManagedBean(name="conversorMonetarioBean")
public class ConversorMonetarioBean {
private String de,para;
private Double valor,resultado;
private Map<String,Double> taxas = new LinkedHashMap<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;
}
}