views:

95

answers:

1

Hi,

i created a list of Users

<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>

and my controler looks like this

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;
    }


}

How can i handle the delete and edit button event?

A: 

To start with, you need a form in your HTML if you don't already have one. That leads neatly on to the next thing, which is that when handling a form in Spring you should use a form controller. The SimpleFormController is a good starting point. You'll want to read up on them a bit before getting stuck in. Spring in Action is an excellent reference.

Mark Chorley