Olá pessoal, estou tentando aplicar o valor que esta o Enum para o <label>
como é feito na aula, porem ele não esta atribuindo um valor. Podem ajudar? Tem alguns campos diferentes para usar aqui num trabalho pessoal, mas não foge do conteúdo da aula:
Form.JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Product Registration</title>
</head>
<body>
<form action="./" method="POST">
<div>
<label>Name: </label>
<input type="text" name="name">
</div>
<br>
<div>
<label>Description: </label>
<textarea rows="10" cols="20" name="description"></textarea>
</div>
<br>
<c:forEach items="${types}" var="pricingType" varStatus="status">
<div >
<label>${pricingType }</label>
<input type="text" name="prices[${status.index}].pricing">
<input type="hidden" name="prices[${status.index}].pricing_type">
</div>
<br>
</c:forEach>
<button type="submit">Submit</button>
</form>
</body>
</html>
ProductsController.java
package br.ibm.com.loja.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import br.ibm.com.loja.dao.ProductDAO;
import br.ibm.com.loja.model.PricingType;
import br.ibm.com.loja.model.Product;
@Controller
public class ProductsController {
@Autowired
private ProductDAO productDAO;
@RequestMapping("product/form")
public ModelAndView form() {
ModelAndView modelAndView = new ModelAndView("/product/form");
modelAndView.addObject("types", PricingType.values());
return modelAndView;
}
@RequestMapping("product/")
public String save(Product product) {
System.out.println(product.toString());
productDAO.save(product);
return "/product/prod-form-ok";
}
}
Price.java
package br.ibm.com.loja.model;
import java.math.BigDecimal;
import javax.persistence.Embeddable;
@Embeddable
public class Price {
private BigDecimal pricing;
private PricingType pricing_type;
public BigDecimal getPricing() {
return pricing;
}
public void setPricing(BigDecimal pricing) {
this.pricing = pricing;
}
public PricingType getPricing_type() {
return pricing_type;
}
public void setPricing_type(PricingType pricing_type) {
this.pricing_type = pricing_type;
}
}
PricingType
package br.ibm.com.loja.model;
public enum PricingType {
NORTE, NORDESTE, SUL, SUDESTE, CENTROOESTE;
}