Announcement Announcement Module
Collapse
No announcement yet.
form:hidden doesn't populate value attribute on render/ Spring Portlet 2.5 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • form:hidden doesn't populate value attribute on render/ Spring Portlet 2.5

    Code:
    @Controller
    @RequestMapping("VIEW")
    public class ForgetPasswordController{
    	
    	
    	private static final String DEFAULT_SITEMAP = "en_US";
    	
    	@Autowired(required=true)
    	@Qualifier("cimsCredentialMgmService")
    	private CredentialManagementService credentialManagementService;
    	
    	private ModelAndView andView;
    
    	private UserProfile userProfile;
    	
    	private UserOperations userOperations;
    	
    	private Response cimsResponse;
    	
    	@Autowired(required=true)
    	@Qualifier("userValidator")
    	private UserValidator userBeanValidator;
    	@RequestMapping(params = "action=getChallengeQuestions")
    	public ModelAndView renderChallengeQuestion() {
    		if (LOG.isInfoEnabled()) {
    			LOG.info("IN renderChallengeQuestion ForgetPasswordController");
    		}
    		return andView;
    	}
    	
    	@RequestMapping(params = "action=getChallengeQuestions")
    	public void getChallengeQuestion(@ModelAttribute("userBean")UserBean userBean, BindingResult result, ActionRequest request, ActionResponse response){
    		if (LOG.isInfoEnabled()) {
    			LOG.info("IN getChallengeQuestions ForgetPasswordController");
    		}
    		
    		userBeanValidator.validateUsername(userBean, result);
    		if(result.hasErrors()){
    			andView.addObject("errors", result.getAllErrors());
    			return;
    		}
    		
    		userProfile = new UserProfile();
    		userProfile.setUserName(userBean.getUserName());
    		/*cimsResponse = performCimsOperation(userProfile, request.getLocale().toString(), GET_CHALLENGE_QUESTIONS, result);
    		if(result.hasErrors()){
    			userBean.setUserName("");
    			andView.addObject("errors", result.getAllErrors());
    			return;
    		}
    		
    		andView.addObject("errors", new ArrayList<String>());
    		CredentialManagementResponse credentialManagementResponse = (CredentialManagementResponse)cimsResponse;
    		Map<String,String> challengeQuestions = credentialManagementResponse.getChalengeQuestions();
    		if(challengeQuestions != null && challengeQuestions.size() == 1){
    			
    			Set<String> questionNoKeys = challengeQuestions.keySet();
    			Object arr[] = questionNoKeys.toArray();
    			String questionKeyOne = arr[0].toString();
    			LOG.info(challengeQuestions.get(questionKeyOne));
    			userBean = new UserBean();
    			userBean.setChallengeQuestion(challengeQuestions.get(questionKeyOne));
    			userBean.setChallengeQuestionNo(questionKeyOne);
    			andView.setViewName("forgotPasswordStep2");
    			andView.addObject("userBean", userBean);
    			response.setRenderParameter("action", "submitNewPassword");
    		} else{
    			result.addError(new ObjectError("userBean","CIMS Error. Kindly contact suport"));
    			return;
    		}*/
    		userBean = new UserBean();
    		userBean.setChallengeQuestion("City of Birth?");
    		userBean.setChallengeQuestionNo("0");
    		andView.setViewName("forgotPasswordStep2");
    		andView.addObject("userBean", userBean);
    		response.setRenderParameter("action", "submitNewPassword");
    		
    		if (LOG.isInfoEnabled()) {
    			LOG.info("Exiting getChallengeQuestions ForgetPasswordController");
    		}
    	}
    	
    	@RequestMapping(params = "action=submitNewPassword")
    	public ModelAndView renderChallengeAnswerAndNewPassword() {
    		if (LOG.isInfoEnabled()) {
    			LOG.info("IN renderChallengeAnswerAndNewPassword ForgetPasswordController");
    			LOG.info("renderChallengeAnswerAndNewPassword : View Name is : " + andView.getViewName());
    		}
    		return andView;
    	}
    	
    	@RequestMapping(params = "action=submitNewPassword")
    	public void submitChallengeAnswerAndNewPassword(@ModelAttribute("userBean")UserBean userBean, BindingResult result, ActionRequest request, ActionResponse response){
    		if (LOG.isInfoEnabled()) {
    			LOG.info("IN submitChallengeAnswerAndNewPassword ForgetPasswordController");
    		}
    		userBeanValidator.validateChallengeAnswer(userBean, result);
    		userBeanValidator.validatePassword(userBean, result);
    		userBeanValidator.validateConfirmPassword(userBean, result);
    		if(result.hasErrors()){
    			andView.addObject("errors", result.getAllErrors());
    			return;
    		}
    		
    		userProfile = new UserProfile();
    		userProfile.setChallengeAnswer(userBean.getChallengeAnswer());
    		userProfile.setChallengeQuestion(userBean.getChallengeQuestion());
    		userProfile.setChallengeQuestionNo(userBean.getChallengeQuestionNo());
    		userProfile.setPassword(userBean.getPassword());
    		userProfile.setConfirmPassword(userBean.getConfirmPassword());
    		
    		performCimsOperation(userProfile, request.getLocale().toString(), FORGOT_PASSWORD, result);
    		if(result.hasErrors()){
    			userBean.setChallengeAnswer("");
    			userBean.setPassword("");
    			userBean.setConfirmPassword("");
    			andView.addObject("errors", result.getAllErrors());
    			return;
    		}
    		
    		andView.setViewName("forgotPasswordSuccess");
    		response.setRenderParameter("action", "submitNewPassword");
    		
    		if (LOG.isInfoEnabled()) {
    			LOG.info("Exiting submitChallengeAnswerAndNewPassword ForgetPasswordController");
    		}
    	}
    	
    	private boolean populateLabels(PortletRequest request, UserCredentialManagementLabelBean userCredentialManagementLabels, MyJDButtonLabelsBean myJDButtonLabels){
    		
    		// Get the site name for the using request locale.
    		String siteName = MyJDUtil.getSitemappedToLocale(request.getLocale());
    		
    		if (siteName == null || siteName.length() == 0) {
    			siteName = DEFAULT_SITEMAP;
    		}
    		
    		boolean success = false;
    		boolean buttonSuccess = false;
    		
    		try{
    			success = MyJDGetLabelsUtil.populateUserCredentialManagementLabels(siteName,userCredentialManagementLabels);
    			buttonSuccess = MyJDGetLabelsUtil.populateMyJDCommonButtonLabels(siteName, myJDButtonLabels);
    		} catch (ApplicationException e) {
    			LOG.error( "ApplicationException Exception encountered returning error page", e);
    		} catch (SystemException e) {
    			LOG.error( "SystemException Exception encountered returning error page", e);
    		}
    		
    		return success && buttonSuccess;
    	}
    	
    	private Response performCimsOperation(UserProfile userProfile, String locale, WebServiceOperation operationType, BindingResult result){
    		userOperations = new UserOperations();
    		userOperations.setUserProfile(userProfile);
    		userOperations.setOperationType(operationType);
    		userOperations.setUserLocale(locale);
    		cimsResponse = credentialManagementService.execute(userOperations);
    		if ( cimsResponse instanceof CredentialManagementResponse){
    			CredentialManagementResponse umr = (CredentialManagementResponse)cimsResponse;
    			if(!umr.isSucceeded()){
    				ErrorMessageObject err = umr.getErrorObject();
    				result.addError(new ObjectError("userBean","MY ERROR"));
    				result.addError(new ObjectError("userBean",err.getErrorMessage()));
    			}
    		}
    		return cimsResponse;
    	}
    }
    HTML Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"	pageEncoding="ISO-8859-1" session="false"%>
    <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
    <portlet:defineObjects />
    
    <portlet:actionURL var="submitNewPasswordUrl">
    	<portlet:param name="action" value="submitNewPassword"/>
    </portlet:actionURL>
    
    <div class="MOD_GC_35">
    	<div class="MOD_GC_1a">
    		${userCredsMgmtLabels.forgotPasswordPageHeader}
    	</div>
    	<div class="enterPass">
    		${userCredsMgmtLabels.challengeQuestionLabelText}
    	</div>
    	<div class="MOD_FO_28">
    		<form:form modelAttribute="userBean" name="forgot_passQuestion" method="POST" id="forgot_passQuestion" cssClass="margin_top19" action="${submitNewPasswordUrl}" autocomplete="false">
    			<c:forEach items="${errors}" var="error">
    				 <div class="error"><c:out value="${error.defaultMessage}"/></div>
    			</c:forEach>
    			<div class="form_reg_uname">
    				<div class="label_userReg">
    					<form:label path="challengeQuestion" for="currPass" >${userBean.challengeQuestion}</form:label>
    					<form:hidden path="challengeQuestion"/>
    					<input id="challengeQuestion" type="hidden" value="${userBean.challengeQuestion}" name="challengeQuestion">
    					<input id="challengeQuestionNo" type="hidden" value="${userBean.challengeQuestionNo}" name="challengeQuestionNo">
    				</div>
    				<div class="input_col">
    					<span class="input_col">
    						<form:password cssClass="input_text width210 tabindex1" path="challengeAnswer" id="currPass" tabindex="1" />
    					</span>
    				</div>
    			</div>
    			<div class="form_reg_uname">
    				<div class="label_userReg">
    					<label for="nPass">${userCredsMgmtLabels.newPasswordLabel}</label>
    				</div>
    				<div class="input_col">
    					<form:password path="password" id="nPass" cssClass="input_text width210 error_input" tabindex="2"/>
    				</div>
    			</div>
    			<div class="form_reg_uname">
    				<div class="label_userReg">
    					<label for="nPass">${userCredsMgmtLabels.confirmPasswordLabel}</label>
    				</div>
    				<div class="input_col">
    					<form:password path="confirmPassword" id="confPass" cssClass="input_text width210" tabindex="3"/>
    				</div>
    			</div>
    			<div class="btn">
    				<a href="/wps/portal/dcom/login" class="grey_btn" tabindex="4">
    					<span>${myJDButtonLabels.cancelButtonLabel}</span>
    				</a>
    				<a href="#" onclick="javascript: document.forgot_passQuestion.submit();" class="btn_primary" tabindex="5">
    					<span>${myJDButtonLabels.submitButtonLabel}</span>
    				</a>
    			</div>
    		</form:form>
    	</div>
    </div>
    Though this works fine

    HTML Code:
    <input id="challengeQuestion" type="hidden" value="${userBean.challengeQuestion}" name="challengeQuestion">
    this doesn't work

    HTML Code:
    <form:hidden path="challengeQuestion"/>
    the value attribute of the rendered input hidden tag is always empty string.

    Any help is appreciated.
Working...
X