Discussion:
struts: prepare in UserAction
Josep García
2011-12-14 09:45:50 UTC
Permalink
I have been debugging some code lately and I don't see the need for the
method:

/**
* Grab the entity from the database before populating with request
parameters
*/
public void prepare() {
// prevent failures on new
if (getRequest().getMethod().equalsIgnoreCase("post") &&
(!"".equals(getRequest().getParameter("user.id")))) {
user = userManager.getUser(getRequest().getParameter("user.id
"));
}
}

If I comment out the implementation, everything works fine and all the
tests pass.

Cheers,
Josep
Matt Raible
2011-12-14 15:36:31 UTC
Permalink
Are you sure it's not needed when editing a user?
/**
* Grab the entity from the database before populating with request parameters
*/
public void prepare() {
// prevent failures on new
if (getRequest().getMethod().equalsIgnoreCase("post") && (!"".equals(getRequest().getParameter("user.id")))) {
user = userManager.getUser(getRequest().getParameter("user.id"));
}
}
If I comment out the implementation, everything works fine and all the tests pass.
Cheers,
Josep
Ebrahim Pasbani
2011-12-14 16:23:19 UTC
Permalink
Sorry if I disturb.
I think it shoud be moved to edit(0 method, not prepare()
Post by Matt Raible
Are you sure it's not needed when editing a user?
/**
* Grab the entity from the database before populating with request parameters
*/
public void prepare() {
// prevent failures on new
if (getRequest().getMethod().equalsIgnoreCase("post") &&
(!"".equals(getRequest().getParameter("user.id")))) {
user = userManager.getUser(getRequest().getParameter("user.id
"));
}
}
If I comment out the implementation, everything works fine and all the tests pass.
Cheers,
Josep
Josep García
2011-12-14 16:59:16 UTC
Permalink
Sorry, my mistake.
It is necessary indeed.
Post by Matt Raible
Are you sure it's not needed when editing a user?
/**
* Grab the entity from the database before populating with request parameters
*/
public void prepare() {
// prevent failures on new
if (getRequest().getMethod().equalsIgnoreCase("post") &&
(!"".equals(getRequest().getParameter("user.id")))) {
user = userManager.getUser(getRequest().getParameter("user.id
"));
}
}
If I comment out the implementation, everything works fine and all the tests pass.
Cheers,
Josep
Loading...