Archive for the ‘Struts 2’ Category

Appfuse create a custom page to edit users

Tuesday, January 27th, 2009

I am working on a site based on Appfuse + Struts 2 and I needed to create a custom page allowing the logged in user to change add information to his profile.

I decided to base my extension on the already existent User model object in Appfuse, copy pasted the default editProfile.jsp under a new name. Then I added few new fields there and also to the standard user object.

However I noticed a problem that my new jsp page was not getting the logged in user from the UserAction.edit method which I specified in the struts.xml, as it was also for the editProfile.jsp page. Instead I always got a new empty User object.

Looking into the code for the UserAction.edit method I saw that there is a boolean variable at the top of the method that checks wheter the query string included the editProfile string.

Thus there are two solutions to this problem. Let the name of the new .jsp include the string editProfile or simply copy the method into a new action method and hardcode the boolean value to true there. Also the new copied method can ofcourse been simplified.

The easiest way ofcourse is to have the page include the string editProfile.