Boa tarde.
Estou errando em algum lugar mas não consegui identificar. Quando tento acessar a página do carrinho dá o erro "HTTP Status 500 - javax.el.PropertyNotFoundException: Property 'quantidade' not found on type br.com.casadocodigo.loja.models.CarrinhoCompras"
Minha classe CarrinhoCompras está assim:
package br.com.casadocodigo.loja.models;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.stereotype.Component;
@Component
public class CarrinhoCompras {
private Map<CarrinhoItem, Integer> itens = new LinkedHashMap<CarrinhoItem, Integer>();
public void add(CarrinhoItem item) {
itens.put(item, getQuantidade(item) + 1);
}
private int getQuantidade(CarrinhoItem item) {
if (!itens.containsKey(item)) {
itens.put(item, 0);
}
return itens.get(item);
}
private int getQuantidade() {
return itens.values().stream().reduce(0, (proximo, acumulador) -> proximo + acumulador);
}
}
package br.com.casadocodigo.loja.conf;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.format.datetime.DateFormatterRegistrar;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import br.com.casadocodigo.loja.controllers.HomeController;
import br.com.casadocodigo.loja.daos.ProdutoDAO;
import br.com.casadocodigo.loja.infra.FileSaver;
import br.com.casadocodigo.loja.models.CarrinhoCompras;
@EnableWebMvc
@ComponentScan(basePackageClasses = { HomeController.class, ProdutoDAO.class,
FileSaver.class, CarrinhoCompras.class})
public class AppWebConfiguration {
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposedContextBeanNames("carrinhoCompras");
return resolver;
}
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource =
new ReloadableResourceBundleMessageSource();
messageSource.setBasename("/WEB-INF/messages");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setCacheSeconds(1);
return messageSource;
}
//Esse método abaixo é para não ter que ficar definindo o pattern nos atributos DateTimeFormat
@Bean
public FormattingConversionService mvcConversionService() {
DefaultFormattingConversionService conversionService =
new DefaultFormattingConversionService();
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
registrar.setFormatter(new DateFormatter("dd/MM/yyyy"));
registrar.registerFormatters(conversionService);
return conversionService;
}
@Bean
public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}
}