列表中的Spring MVC句柄按钮事件

时间:2010-05-29 11:35:37

标签: java spring jsp spring-mvc

我创建了一个用户列表

<div class="usersList">           
        <c:forEach items="${users}" var="user">
            <div class="listElementAction">
                <c:out value="${user.id}"/>
            </div>
            <div class="listElement">
                <c:out value="${user.firstName}"/>
            </div>
            <div class="listElement">
                <c:out value="${user.lastName}"/>
            </div>
            <div class="listElement">
                <c:out value="${user.username}"/>
            </div>
            <div class="listElementAction">
                <input type="button" name="Edit" title="Edit" value="Edit" />
            </div>
            <div class="listElementAction">
                <input type="image" src="images/delete.png" name="image" value="${user.id}" alt="Delete" onclick="return confirm('Do you want to delete ${user.username}?')" >
            </div>
            <br />            
            </c:forEach>
        </div>

我的控制器看起来像这样

public class UsersController implements Controller {

    private UserServiceImplementation userServiceImplementation;

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {        

        ModelAndView modelAndView = new ModelAndView("users");                
        modelAndView.addObject("users", this.userServiceImplementation.get());
    return modelAndView;

    }

    public UserServiceImplementation getUserServiceImplementation() {
        return userServiceImplementation;
    }

    public void setUserServiceImplementation(UserServiceImplementation userServiceImplementation) {
        this.userServiceImplementation = userServiceImplementation;
    }


}

如何处理删除和编辑按钮事件?

1 个答案:

答案 0 :(得分:1)

首先,如果您还没有HTML表单,则需要该表单。这导致了下一件事,即在Spring中处理表单时应该使用表单控制器。 SimpleFormController是一个很好的起点。在被困之前,你会想要阅读它们。Spring in Action是一个很好的参考。