I've written several forms for a project I'm working on. Up to this point, they all have worked. Now all of sudden, I have one that is not wanting to cooperate. This is what I've got.
Here is my bean referencing my controller. I commented out the validator, just so I can take that out of the picture.
Here is my formBackingObject, which when I step through in debug mode loads the user correctly.Code:<bean id="userProfile" class="com.yum.web.tastepanel.web.UserProfileController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>userProfile</value></property> <property name="commandClass"><value>com.yum.web.tastepanel.bus.objects.User</value></property> <!-- <property name="validator"><ref bean="User_Validator"/></property> --> <property name="tastePanelManager"><ref bean="tastepanelServices" /></property> <property name="formView"><value>viewUser</value></property> <property name="successView"><value>index.htm</value></property> </bean>
Here is my referenceData:Code:protected Object formBackingObject(HttpServletRequest request) throws Exception { User user = (User) request.getSession().getAttribute(Constants.CURRENT_USER); if (user.getLoginId().length() <= 0){ // Attempt to load user by login Id String username = (String) request.getSession().getAttribute(Constants.CURRENT_USERNAME); if (username.length() <= 0){ // Lost username, try to get it back. HttpSession session = request.getSession(true); try{ username = request.getRemoteUser().toLowerCase(); int intSplitter = username.indexOf("\\"); username = username.substring(intSplitter + 1); } catch(Exception e){ username = request.getRemoteUser(); } request.getSession(true).setAttribute(Constants.CURRENT_USERNAME, username); } try{ user = (User) tpManager.getUserByLoginId(username); request.getSession().setAttribute(Constants.CURRENT_USER, user); } catch (Exception e){ // Return empty user. } } return user; }
And finally, here is my jsp code.Code:protected Map referenceData(HttpServletRequest request) throws Exception { Map model = new HashMap(); try { model.put(Constants.CURRENT_RSC, request.getSession(true).getAttribute(Constants.CURRENT_RSC)); if (request.getSession().getAttribute(Constants.CURRENT_USER) != null){ User user = (User) request.getSession().getAttribute(Constants.CURRENT_USER); int totalPoints = 0; if (!user.getPointHistorys().isEmpty()){ for (Iterator item = user.getPointHistorys().iterator(); item.hasNext();) { PointHistory pointHistory = (PointHistory) item.next(); totalPoints = totalPoints + pointHistory.getPoints(); } } model.put("MyPointHistory", user.getPointHistorys()); model.put("TotalPoints", String.valueOf(totalPoints)); } else { model.put("MyPointHistory", null); } } catch (Exception e) { //no rsc id model.put(Constants.CURRENT_RSC, null); model.put("MyPointHistory", null); } return model; }
The odd thing is, on the jsp page, I originally had some code for a menuCode:<table cellpadding="0" cellspacing="0" border="0"> <tr> <td colspan="2" align="center"><h2><c:out value="${CurrentRSC.name}"/></h2></td> </tr> <tr> <td width="5"></td> <td> <!-- Support for Spring errors object --> <spring:bind path="userProfile.*"> <c:forEach var="error" items="${status.errorMessages}"> <span class="error"><b>Error:</b> <c:out value="${error}"/></span><br> </c:forEach> </spring:bind> <form method="post"> <table cellpadding="2" cellspacing="0" border="0"> <tr> <td class="required">Name:</td> <td> <spring:bind path="userProfile.name"> <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"> </spring:bind> </td> </tr> <tr> <td class="optional">Telephone:</td> <td> <spring:bind path="userProfile.telephone"> <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"> </spring:bind> </td> </tr> <tr> <td class="optional">Department:</td> <td> <spring:bind path="userProfile.department"> <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"> </spring:bind> </td> </tr> <tr> <td class="required">Email:</td> <td> <spring:bind path="userProfile.email"> <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"> </spring:bind> </td> </tr> <tr> <td></td> <td> <input type="submit" name="doAction" value="Save"> <input type="submit" name="doAction" value="Cancel"> </td> </tr> <tr> <td colspan="2"> Point History: <table cellpadding="1" cellspacing="0" border="1" width="100%"> <tr> <th>Date:</th> <th>Points:</th> <th>Event:</th> </tr> <c:set var="pointCounter" value="0" scope="page" /> <c:forEach items="${MyPointHistory}" var="points"> <c:set var="pointCounter" value="1" scope="page" /> <tr> <td><fmt:formatDate value="${points.occured}" pattern="M/d/yyyy h:mm aa"/></td> <td align="right"><c:out value="${points.points}"/></td> <td><c:out value="${points.event}"/></td> </tr> </c:forEach> <c:choose> <c:when test='${pointCounter > 0}'> <tr> <td class="required"># of Points:</td> <td align="right"><c:out value="${TotalPoints}"/></td> <td></td> </tr> </c:when> <c:otherwise> <tr> <td colspan="3" align="center">No point history to view.</td> </tr> </c:otherwise> </c:choose> </table> </td> </tr> </table> </form> </td> </tr> </table>
Which worked, but as you can see from my code snippets, I was not passing a CurrentUser model. Before I removed the code, I put a <dt><c:out value="${userProfile.name}"/></dt> after the <dt> tag containing a link for Feedback, and that actually displayed the name. But I am at a loss as to why my fields are not prepopulated on my form. Any and all help would be greatly appreciated.Code:<dl> <c:if test="${CurrentUser.admin}"> <dt><a href="admin/index.htm">Admin</a></dt> </c:if> <c:choose> <c:when test='${CurrentUser.name !=""}'> <dt><a href="viewTastePanels.htm">Taste Panels</a></dt> <dt><a href="viewRewards.htm">Rewards</a></dt> <dt><a href="viewUser.htm">My Profile</a></dt> </c:when> <c:otherwise> <dt><a href="signup.htm">Sign Up</a></dt> </c:otherwise> </c:choose> <dt><a href="feedback.htm">Feedback</a></dt> </dl>
Thanks in advance,
Neo


Reply With Quote