[Resolvido]K19- ConversorMonetario - Ajuda com JSF

8 respostas
bacoco

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?
<!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:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<h:head>
	<title>K19 Treinamentos - Conversor Monetario</title>
</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>
</html>
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;
	}
	
	

}

8 Respostas

marcelo.silva.java

quando vc abre a view da esse erro???

faz um teste…retire o construtor vazio…

[]s

bacoco

marcelo.silva.java:
quando vc abre a view da esse erro???

faz um teste…retire o construtor vazio…

[]s


Perdão, postei o construtor errado, arrumei com o correto.

fredericomaia10

Cadê o get e set do atributo taxas?

bacoco

Obrigado frederico, pulei justamente o get do taxas, obrigado cara.

Só não entendo porque o eclipse continua apontando como erro no trecho:

<h:commandButton value=“Converter” action="[color=red]#{conversorMonetarioBean.converte}[/color]"/>

A parte em vermelho ele acusa como erro, com o mouse em cima ele diz:

Method must have signature "String method(), String method(), String method(String), String method(String, String), String method(String, String, String), String method(String, String, String, String), String method(String, String, String, String, String), String method(String, String, String, String, String, String), String method(String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)" but has signature "void method()"

fredericomaia10

Quanto à esse erro acima não sei dizer. Imagino que seja bug do Eclipse pois não há nada de errado no método.

saulo.bsi

Esse erro do eclipse parece ser um bug. Isto já aconteceu comigo uma vez. Qual a versão do Eclipse?

bacoco

Kleper, dei uma pesquisada e é um bug que já está para ser resolvido mesmo.

Obrigado pessoal.

oitathi

Ignore it. Eclipse is a jerk. You can tone it by setting Window > Preferences > Web > JavaServer Faces Tools > Validation > Type Assignment Problems > Method expression signature incompatibility to Warning or Ignore (it defaults to Error).

Criado 5 de agosto de 2013
Ultima resposta 27 de set. de 2014
Respostas 8
Participantes 5