Spring模型属性不会填充值

时间:2012-02-05 10:52:39

标签: spring spring-mvc spring-annotations

我有一个带有一些方法的模型类,其中大部分是使用ajax(jquery)填充的,我在JSP上有一个model属性作为orderVo,最初当页面加载时,一些值保持空白,当我调用不同的方法时,它们保持不变使用ajax填充。现在的问题是,当在表单设置(第一次GET)之后调用1方法时,我的模型属性没有填充值。

    @Controller
@RequestMapping("/order")
@SessionAttributes("orderViewVO")
public class OrderController {

    private static final Logger LOGGER = Logger
            .getLogger(OrderController.class);

    @Autowired
    OrderService orderService;

//THIS IS THE 1ST METHOD CALLED ON PAGE
    @RequestMapping(value = "{clientId}", method = RequestMethod.GET)
    public String showOrderPage(@PathVariable Long clientId, Model model) {

        model.addAttribute("orderViewVO", new OrderViewVO());
        return "/order/orderView";
    }

    //I want model tp be updated here
    @RequestMapping(value = "/pro", method = RequestMethod.POST)
    public @ResponseBody
    OrderViewVO fetchProduct(
            @RequestParam(value = "brId", required = true) String brId,
            @RequestParam(value = "categoryId", required = true) String categoryId,
            Model model) {
        LOGGER.info("Entry fetchProduct()");
        LOGGER.debug("Branch Id: " + brId + ", Category Id: " + categoryId);

        OrderViewVO orderViewVO = null;
        orderViewVO = orderService.fecthProduct(categoryId, brId);
        //this has no effects on model values
        model.addAttribute("orderViewVO", orderViewVO);
        LOGGER.info("Exit fetchProduct()");
        return orderViewVO;
    }

}

我的JSP的一部分是 -

   <script type="text/javascript">  

function showOptions(categorySelect,defaultRow) 
{
    if(defaultRow=='0') {
        var categoryId = categorySelect;    
    }   else    {
        var categoryId = categorySelect.id;
    }
    var brId = document.getElementById("bId").value;
    $.post("/guru/cloud/order/pro",
             {  
                brId:brId,
                categoryId:categoryId,
             },
              function(subMenu){                     
                        document.getElementById("tax").value = subMenu.tax;
                        //here i can populate any values fetched in fetchProduct()
                        }                     
                      showHtml=showHtml+" </table>";
                      $("#page_content").html(showHtml);
                    }); 
    }

</script>
<body>

<form:form id="orderView" name="orderView" method="post" modelAttribute="orderViewVO" >
<jsp:directive.include file="../common/header.jsp" />
<input type="hidden" id="bId" value=""/>
<input type="hidden" id="tax" value=""/>
<div style="display:none">
    <div id="cartCheckoutHiddenDiv">
    <!-- cart details to be posted to server -->
    <form:input path="orderData" type="text" id="orderData" name="orderData" value=""/>
            <table cellpadding="0" cellspacing="0" width="100%" border="0" class="checkoutTable">
                <tr><td colspan="2" style="text-align:center">Order is placed for
                </td></tr>
                <!--branchAdd1,branchAdd2 ect are updated in fetchProduct() but are NULL here -->
                <tr><td style="text-align:center"><form:label path="branchAdd1" /></td>
                <td><form:label path="branchAdd2" /></td></tr>
                <tr><td colspan="2">Total Bill amount is : <span id="totalBill"></span></td></tr>
                <tr><!-- start of info row -->
    </div>
</div>
</form:form>
</body>
</html>
</jsp:root>

VO

    public class OrderViewVO implements Serializable {

    private static final long serialVersionUID = 5352956022679804562L;

    private String branchId = null;

    private String branchName = null;

    private String branchAdd1 = null;

    private String branchAdd2 = null;
//getter, setter below

有人可以告诉我为什么我无法填充更新的orderVo值吗?是因为AJAX吗?我甚至使用过SessionAttribut

0 个答案:

没有答案