Announcement Announcement Module
Collapse
No announcement yet.
errors.rejectValue is not displaying any error message in the view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • errors.rejectValue is not displaying any error message in the view

    I have a SimpleFormController. In the onSubmit method, i'm calling errors.rejectValue based on condition. But those messages are not being displayed in my jsp.

    Here is my controller code:

    Code:
    public class JoinSocialGroupController extends SimpleFormController {
        private RegistrationService regService;
        
        public void setRegService(RegistrationService regService) {
            this.regService = regService;
        }
        
        protected void onSubmitAction(ActionRequest request, ActionResponse response,
            Object command, BindException errors) throws Exception {
            
            System.out.println("Entering JoinSocialGroupController -> onSubmitAction");  
            SocialGroup sgObj = (SocialGroup) command;   
            
            String sgId = request.getParameter("sgid");
            System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> sgId -------> "+ sgId);        
            
            Registration regObj = (Registration) request.getPortletSession(false).getAttribute("regObj");
            
            boolean flag = regService.updateSocialGroupMember(sgId, regObj.getRegEmail());
            System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> flag -------> "+ flag);      
            
            if(!flag) {
                //throw new Exception("Invited member has already been deleted from social group!!!");            
                errors.rejectValue("misc", "member.deleted");
                System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> Entered if BLock"); 
            } else {            
                errors.rejectValue("misc", "member.joined");
                System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> Entered Else BLock"); 
            }
                    
            SocialGroupMember[] sgMembers = regService.getSocialGroupMembers(regObj.getRegEmail(), false);      
            request.setAttribute("members", sgMembers);
            
            System.out.println("Leaving JoinSocialGroupController -> onSubmitAction");        
        }
    
        @Override
        protected Map referenceData(PortletRequest request, Object command, Errors errors) throws Exception {
            System.out.println("Entering JoinSocialGroupController -> referenceData");
            SocialGroup sgObj = (SocialGroup) command;           
            
            Registration regObj = (Registration) request.getPortletSession(false).getAttribute("regObj");
            
            SocialGroupMember[] sgMembers = regService.getSocialGroupMembers(regObj.getRegEmail(), false); 
            
            request.setAttribute("members", sgMembers);
            
            Map referenceData = new HashMap();                       
            
            System.out.println("Leaving JoinSocialGroupController -> referenceData");
            return referenceData;
        }  
    }
    Here is my jsp:

    Code:
    <form:form commandName="sgObj" method="post" enctype="application/x-www-form-urlencoded">      
    <!--<form name="sgForm" id="sgForm" method="post" action=""  >-->
        <input type="hidden" name="sgid" value="" />
    <h2>My Invitations</h2><br>
    	<!-- side bar left -->
    	<%@ include file="/WEB-INF/jsp/mosonexSidebarMenu.jsp" %>
    	<!-- side bar left ends -->
    	<!-- start content -->
    	<div id="sidebarmiddle">
    
                
                <h2>Here are the invitations pending.</h2><br><br>
                    <font color="red"><form:errors path="misc" /></font>
                    <br><br>
                        
                 <table align="center" border="2" >
                     <% if((null != sgMemArr)  && sgMemArr.length > 0) { %>
                     <tr>
                         <th>SNo.</th>
                         <th>Social Group Name</th>
                         <th>Invitor</th>
                         <th></th>
                     </tr>
                     <% for(int i=0; i< sgMemArr.length ; i++) { %>
                     <tr>                         
                         <td><%=(i+1) %></td>
                         <td><%=sgMemArr[i].getSgName() %></td>
                         <td><%=sgMemArr[i].getInvitor() %></td>
                         <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href='<portlet:actionURL>
    						<portlet:param name="action" value="joinSocialGroup"/>
                                                     <portlet:param name="sgid" value="<%= sgMemArr[i].getSgid() %>" />
                                                     </portlet:actionURL>' >JoinGroup</a>&nbsp;&nbsp;</td>
                         
                     </tr>
                     <% }  } else {%>
                     <tr><td colspan="5">No invitations found.</td></tr>                 
                     <%} %>
                     
                 </table>
    <br>
    	<br>
    
    	</div>
    	<!-- end content -->
    </form:form>
    Please let me know what i'm doing wrong. Any help is greatly appreciated.

  • #2
    The onSubmit method is not the place to reject values. Try overriding the onBindAndValidateMethod and put your field rejections there. Always works for me.

    HTH

    Comment


    • #3
      I have changed the controller as you suggested. But no luck yet.

      Below is my controller code:

      Code:
      public class JoinSocialGroupController extends SimpleFormController {
          private RegistrationService regService;
          
          public void setRegService(RegistrationService regService) {
              this.regService = regService;
          }
          
          protected void onSubmitAction(ActionRequest request, ActionResponse response,
              Object command, BindException errors) throws Exception {
              
              System.out.println("Entering JoinSocialGroupController -> onSubmitAction");  
              SocialGroup sgObj = (SocialGroup) command;   
              
              Registration regObj = (Registration) request.getPortletSession(false).getAttribute("regObj");
                  
              SocialGroupMember[] sgMembers = regService.getSocialGroupMembers(regObj.getRegEmail(), false);      
              request.setAttribute("members", sgMembers);
              
              System.out.println("Leaving JoinSocialGroupController -> onSubmitAction");        
          }
          
          @Override
          protected Map referenceData(PortletRequest request, Object command, Errors errors) throws Exception {
              System.out.println("Entering JoinSocialGroupController -> referenceData");
              SocialGroup sgObj = (SocialGroup) command;           
              
              Registration regObj = (Registration) request.getPortletSession(false).getAttribute("regObj");
              
              SocialGroupMember[] sgMembers = regService.getSocialGroupMembers(regObj.getRegEmail(), false); 
              
              request.setAttribute("members", sgMembers);
              
              Map referenceData = new HashMap();                       
              
              System.out.println("Leaving JoinSocialGroupController -> referenceData");
              return referenceData;
          }
      
          @Override
          protected void onBindAndValidate(PortletRequest request, Object command, BindException errors) throws Exception {
              
              String sgId = request.getParameter("sgid");
              System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> sgId -------> "+ sgId);        
              
              Registration regObj = (Registration) request.getPortletSession(false).getAttribute("regObj");
              
              boolean flag = regService.updateSocialGroupMember(sgId, regObj.getRegEmail());
              System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> flag -------> "+ flag);      
              
              if(!flag) {
                  //throw new Exception("Invited member has already been deleted from social group!!!");            
                  errors.rejectValue("misc", "member.deleted");
                  System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> Entered if Block"); 
              } else {            
                  errors.rejectValue("misc", "member.joined");
                  System.out.println("Entering JoinSocialGroupController -> onSubmitAction -------> Entered else Block"); 
              }
                    
              
          }    
          
      }
      Is it implementation of referenceData is causing the problem? I implemented that method because i need social group members in the request attribute everytime page is loaded. Below is the configuration of JoinSocialGroupController.

      Code:
       <bean name="joinSocialGroupController" class="com.mosonex.portal.controller.JoinSocialGroupController">
                      <property name="commandClass" value="com.mosonex.portal.sdo.SocialGroup"/>
                      <property name="commandName" value="sgObj"/>
      		<property name="regService" ref="Registration"/> 
                      <property name="formView" value="myInvitations" />
                      <property name="successView" value="myInvitations" /> 
                      <property name="bindOnNewForm" value="true" />
      	</bean>
      I'm unable to figure out what's causing the error. In my other controllers, it works just fine. Only in this case, it's not working.

      PLease throw some pointers to this strange behavior. IT will be great help to us.

      Thanks very much.

      Comment

      Working...
      X