Announcement Announcement Module
Collapse
No announcement yet.
No data on jsp page using spring:bind Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No data on jsp page using spring:bind

    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.
    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 formBackingObject, which when I step through in debug mode loads the user correctly.
    Code:
    	protected Object formBackingObject&#40;HttpServletRequest request&#41; throws Exception &#123;
    			
    		User user = &#40;User&#41; request.getSession&#40;&#41;.getAttribute&#40;Constants.CURRENT_USER&#41;;
    		if &#40;user.getLoginId&#40;&#41;.length&#40;&#41; <= 0&#41;&#123;
    			//	Attempt to load user by login Id
    			String username = &#40;String&#41; request.getSession&#40;&#41;.getAttribute&#40;Constants.CURRENT_USERNAME&#41;;
    			if &#40;username.length&#40;&#41; <= 0&#41;&#123;
    				//	Lost username, try to get it back.
    				HttpSession session = request.getSession&#40;true&#41;;
    				try&#123;
    					username = request.getRemoteUser&#40;&#41;.toLowerCase&#40;&#41;;
    					int intSplitter = username.indexOf&#40;"\\"&#41;;
    					username = username.substring&#40;intSplitter + 1&#41;;
    				&#125;	catch&#40;Exception e&#41;&#123;
    					username = request.getRemoteUser&#40;&#41;;
    				&#125;
    				request.getSession&#40;true&#41;.setAttribute&#40;Constants.CURRENT_USERNAME, username&#41;;
    			&#125;
    			try&#123;
    				user = &#40;User&#41; tpManager.getUserByLoginId&#40;username&#41;;
    				request.getSession&#40;&#41;.setAttribute&#40;Constants.CURRENT_USER, user&#41;;
    			&#125; catch &#40;Exception e&#41;&#123;
    				//	Return empty user.
    			&#125;
    		&#125;
    		return user;
    	&#125;
    Here is my referenceData:
    Code:
    	protected Map referenceData&#40;HttpServletRequest request&#41; throws Exception &#123;
    		Map model = new HashMap&#40;&#41;;
    		try &#123;
    			model.put&#40;Constants.CURRENT_RSC, request.getSession&#40;true&#41;.getAttribute&#40;Constants.CURRENT_RSC&#41;&#41;;
    			if &#40;request.getSession&#40;&#41;.getAttribute&#40;Constants.CURRENT_USER&#41; != null&#41;&#123;
    				User user = &#40;User&#41; request.getSession&#40;&#41;.getAttribute&#40;Constants.CURRENT_USER&#41;;
    				int totalPoints = 0;
    				if &#40;!user.getPointHistorys&#40;&#41;.isEmpty&#40;&#41;&#41;&#123;
    					for &#40;Iterator item = user.getPointHistorys&#40;&#41;.iterator&#40;&#41;; item.hasNext&#40;&#41;;&#41;
    					&#123;
    						PointHistory pointHistory = &#40;PointHistory&#41; item.next&#40;&#41;;
    						totalPoints = totalPoints + pointHistory.getPoints&#40;&#41;;
    					&#125;
    				&#125;
    				model.put&#40;"MyPointHistory", user.getPointHistorys&#40;&#41;&#41;;
    				model.put&#40;"TotalPoints", String.valueOf&#40;totalPoints&#41;&#41;;
    			&#125;
    			else &#123;
    				model.put&#40;"MyPointHistory", null&#41;;
    			&#125;
    		&#125; 
    		catch &#40;Exception e&#41; &#123;
    			//no rsc id
    			model.put&#40;Constants.CURRENT_RSC, null&#41;;
    			model.put&#40;"MyPointHistory", null&#41;;
    		&#125;
    		return model;
    	&#125;
    And finally, here is my jsp code.
    Code:
    				<table cellpadding="0" cellspacing="0" border="0">
    					<tr>
    						<td colspan="2" align="center"><h2><c&#58;out value="$&#123;CurrentRSC.name&#125;"/></h2></td>
    					</tr>
    					<tr>
    						<td width="5"></td>
    						<td>
    							<!-- Support for Spring errors object -->
    							<spring&#58;bind path="userProfile.*">
    								<c&#58;forEach var="error" items="$&#123;status.errorMessages&#125;">
    									<span class="error"><b>Error&#58;</b> <c&#58;out value="$&#123;error&#125;"/></span><br>
    							  </c&#58;forEach>
    							</spring&#58;bind>
    							<form method="post">
    								<table cellpadding="2" cellspacing="0" border="0">
    									<tr>
    										<td class="required">Name&#58;</td>
    										<td>
    											<spring&#58;bind path="userProfile.name">
    												<input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>">
    											</spring&#58;bind>
    										</td>
    									</tr>
    									<tr>
    										<td class="optional">Telephone&#58;</td>
    										<td>
    											<spring&#58;bind path="userProfile.telephone">
    												<input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>">
    											</spring&#58;bind>
    										</td>
    									</tr>
    									<tr>
    										<td class="optional">Department&#58;</td>
    										<td>
    											<spring&#58;bind path="userProfile.department">
    												<input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>">
    											</spring&#58;bind>
    										</td>
    									</tr>
    									<tr>
    										<td class="required">Email&#58;</td>
    										<td>
    											<spring&#58;bind path="userProfile.email">
    												<input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>">
    											</spring&#58;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&#58;
    											<table cellpadding="1" cellspacing="0" border="1" width="100%">
    												<tr>
    													<th>Date&#58;</th>
    													<th>Points&#58;</th>
    													<th>Event&#58;</th>
    												</tr>
    												<c&#58;set var="pointCounter" value="0" scope="page" />
    												<c&#58;forEach items="$&#123;MyPointHistory&#125;" var="points">
    													<c&#58;set var="pointCounter" value="1" scope="page" />
    													<tr>
    														<td><fmt&#58;formatDate value="$&#123;points.occured&#125;" pattern="M/d/yyyy h&#58;mm aa"/></td>
    														<td align="right"><c&#58;out value="$&#123;points.points&#125;"/></td>
    														<td><c&#58;out value="$&#123;points.event&#125;"/></td>
    													</tr>
    												</c&#58;forEach>
    											    <c&#58;choose>
    													<c&#58;when test='$&#123;pointCounter > 0&#125;'>
    														<tr>
    															<td class="required"># of Points&#58;</td>
    															<td align="right"><c&#58;out value="$&#123;TotalPoints&#125;"/></td>
    															<td></td>
    														</tr>
    													</c&#58;when>
    													<c&#58;otherwise>
    														<tr>
    															<td colspan="3" align="center">No point history to view.</td>
    														</tr>
    													</c&#58;otherwise>
    												</c&#58;choose>
    											</table>
    										</td>
    									</tr>
    								</table>
    							</form>
    						</td>
    					</tr>
    				</table>
    The odd thing is, on the jsp page, I originally had some code for a menu
    Code:
    <dl>
    	<c&#58;if test="$&#123;CurrentUser.admin&#125;">
    		<dt><a href="admin/index.htm">Admin</a></dt>
    	</c&#58;if>
        <c&#58;choose>
    		<c&#58;when test='$&#123;CurrentUser.name !=""&#125;'>
    			<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&#58;when>
    		<c&#58;otherwise>
    			<dt><a href="signup.htm">Sign Up</a></dt>
    		</c&#58;otherwise>
    	</c&#58;choose>
    	<dt><a href="feedback.htm">Feedback</a></dt>
    </dl>
    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.

    Thanks in advance,
    Neo
Working...
X