Here is the UserAction class
public class UserAction extends AbstractCRUDAction<User> implements
ServletRequestAware{
private User user = null;
private String password2 = null;
private HttpServletRequest request = null;
private Logger log = Logger.getLogger(UserAction.class);
private UserService service = null;
public User getUser(){
return this.user;
}
public void setUser(User user){
this.user = user;
}
public String getPassword2(){
return this.password2;
}
public void setPassword2(String password2){
this.password2 = password2;
}
public String execute() {
log.info("In execute");
printParams();
UserService us = DaoServiceFactory.getUserService();
us.beginTransaction();
try{
us.save(this.user);
}catch(Exception e){
log.error("Error ", e);
}
us.commitTransaction();
return SUCCESS;
}
public String delete(){
log.info("in delete");
printParams();
UserService us = DaoServiceFactory.getUserService();
us.beginTransaction();
us.delete(user);
HibernateUtil.getSession().flush();
us.commitTransaction();
return SUCCESS;
}
public String prepare(){
printParams();
try{
Long userId =
Long.parseLong(request.getParameter("user_id"));
if (log.isDebugEnabled()){
log.debug("Finding user with id of " + userId);
}
UserService us = DaoServiceFactory.getUserService();
us.beginTransaction();
user = (User)us.findByPrimaryKey(userId);
log.info("user.getPassword() = " + user.getPassword());
for (int i = 0; i < user.getRoles().size(); i++){
System.out.println("role id = " +
((Role)user.getRoles().get(i)).getId());
}
HibernateUtil.getSession().flush();
us.commitTransaction();
request.setAttribute("actionType", "edit");
return SUCCESS;
}catch(NumberFormatException npe){
user = new User();
request.setAttribute("actionType", "add");
return SUCCESS;
}catch(Exception e){
return ERROR;
}
}
@Override
protected DaoService<User, Long> getDaoService() {
if (service == null){
service = DaoServiceFactory.getUserService();
}
return this.service;
}
@Override
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
private void printParams(){
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()){
String name = (String)names.nextElement();
System.out.println(name + " = " +
request.getParameter(name));
}
}
}
newton.dave wrote:
>
> Note that chaining is generally considered a bad practice for a variety of
> reasons;
>
Per your suggestion I removed the chaining and am now using the
redirect/redirect-action types
newton.dave wrote:
>
> Answering the question, however, will require a bit more information: I'm
> not convinced that UserAction just "displays information" since there
> looks to be a form in it.
>
The UserAction class extends a class that returns a list of object (Users)
for the display. I am calling that in the jsp with this tag <s:action
id="userAction" namespace="/user" name="ListUsers" />.
As you can see the UserAction class also add/edit or deletes users from a
form on a different tile.
Thanks,
lathjer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
View this message in context:
http://www.nabble.com/Validation-causing-me-problems-tp20471257p20475228.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]