I just want use jstl:core with SpringMVC.
My controller contain something like :
private Map<UUID, ProductBean> products = new ConcurrentHashMap<UUID, ProductBean>();
…
…
…
@RequestMapping(value="/createproduct/{pbid}", method=RequestMethod.GET)
public String getProduct(HttpServletRequest req, Model model, @PathVariable("pbid") UUID pbid) {
if(!products.containsKey(pbid)){
ProductBean tmp=new ProductBean();
products.put(pbid, tmp);
//model.addAttribute("product",tmp);
System.err.println("============empty now===============\n");
}else{
ProductBean tmp=products.get(pbid);
System.err.println(pbid.toString());
System.err.println(tmp.getMpf().printFileNameList());
}
req.getSession().setAttribute("pbId", pbid);
model.addAttribute("pbId", pbid);
return "production/createproduct";
}
I want simple using jstl like:
<c:choose>
<c:when test="${products.get(pbId).getMpf().size()==0}">
<p>No pictures uploaded</p>
</c:when>
<c:otherwise>
<ul id="products">
......
</ul>
</c:otherwise>
</c:choose>
But the program never go to the first branch
I added <%@ page import=”java.util.*” language=”java” %> package in my jsp, but it seems does not work. I follow the examples from http://www.springbyexample.org/examples/spring-web-flow-subflow-webapp-jsp-example.html. It seems they also have variable not declare in jsp like ${persons}. I want the products variable can work both controller and jsp view part. what I need to do? where I should declare it? Do I need to include other packetage in my jsp?
It looks like your controller has the following line commented out:
The JSP is looking for an object in the model named
products. This is the default scope when referencing something via${products}. Since your controller is never adding an object with this name, it fails thec:when.Additionally, for accessing list elements in JSTL, use the following notation:
See How to select the first element of a set with JSTL? for more detail on this.
Furthermore, you should not be using
.getXxx()either. Assuming your object conforms to the Javabean spec, you reference items with just the name like follows: