Question

I have simple form with SpringMVC, I want retrieve my already had bean by pbid. the problem is the server side I can get the already setting bean, but the jsp side it always get new bean. Can I use the @ModelAttribute("productbean") to received some parameters to get the bean store in my server-side? how to do it? The jstl|form seem always get new form

<form:form method="post" modelAttribute="productbean" action="">
<table>

    </tr>

    <tr>
        <td width="118"><form:label for="name" path="name" > Production Name:</form:label></td>
        <td colspan="2"><form:hidden path="pbid"/><form:input path="name" type="text" size="50" /></td>
    </tr>
...

My controler is like:

@RequestMapping(value="/createproduct", method=RequestMethod.GET)
public  String getProduct(HttpServletRequest req, Model model, 
        @RequestParam(value = "pbid", required = false, defaultValue = "") String spbid) throws MalformedURLException {
    UUID pbid;
    if(spbid.isEmpty())pbid=UUID.randomUUID();
    else pbid=UUID.fromString(spbid);
    ProductBean tmp;
    if(!products.containsKey(pbid)){
        tmp=createbean();
        pbid=tmp.getPbid(); 
        System.err.println("============new productbean===============\n");
    }else{
        tmp=products.get(pbid);
        System.err.println(tmp.getMpf().size());
        System.err.println(tmp.getMpf().printFileNameList());
    }
 .....

@ModelAttribute("productbean")
public ProductBean createbean(){
    ProductBean productbean=new ProductBean(context.getRealPath(filepath));
    products.put(productbean.assignID(), productbean);
    return productbean;
}
Était-ce utile?

La solution

Add session attribute annotation over class

@SessionAttributes("productbean")
@controller
public class test() {
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top