You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kam Lung Leung <kl...@wlwa.com> on 2003/11/13 21:28:55 UTC

Can not get error message to display on the same page

Hi,

I am trying to write a logon page as discribed on the struts-example, but finding
some problem with my logon.jsp when  ActionLogon.java trys to return ActionErrors
or ActionMessages back to the original page, the logon.jsp. I am using Struts1.1
+ jboss-3.2.1_tomcat-4.1.24. I tried two ways to display the errors by using the 
<htlm:errors/> tag and without the tag. Can someone tell me what is going on.

Thank you in advance,
Kam Lung Leung


Below is the tested condictions for both situations:
  
The first part which is without the <html:errors/> on the logon page and I only
had the code listed
below in the logon.jsp.

	<logic:messagesPresent>
		There were errors
		<font color='red' >
			<html:messages id="validatorMsgs"  message="true" >
   			 <bean:write name="validatorMsgs"/> 
			</html:messages>
		</font>
	</logic:messagesPresent>

I tested the following conditions:
1) userName == empty string, and password == empty string (invalid format case)
  I got the popup window saying that User Name is required and Password is
required.

2) userName == hohoho and password == empty string (invalid format case)
  I got the popup window saying that Password is required.

3) userName == hohoho, and password == ho (invalid format case)
  I got no popup window, but instead the error massage was on the same logon page
saying "There were errors". I am expecting a popup window with an error message
saying that password can not be less then 6 characters.

4) userName == hohoho, and password == hohoho (valid format case, but wrong
password)
  I got either popup window nor error message on the logon page. I am especting  
an error message as Invalid Password for this user on the logon page.

The second part which is with the <html:errors/> on the logon page and I had the
code listed
below in the logon.jsp.
	<html:errors/>
	<logic:messagesPresent>
		There were errors
		<font color='red' >
			<html:messages id="validatorMsgs"  message="true" >
   			 <bean:write name="validatorMsgs"/> 
			</html:messages>
		</font>
	</logic:messagesPresent>

I tested the following conditions:
1) userName == empty string, and password == empty string (invalid format case)
  I got the popup windown saying that User Name is required and Password is
required.
  
2) userName == hohoho and password == empty string (invalid format case)		
  I got the popup windown saying that Password is required.

3) userName == hohoho, and password == ho (invalid format case)
  I got these messages on the logon page. 
        Password can not be less than 6 characters.
        There were errors
  I am expecting to see the "Password can not be less than 6 characters." on the
popup windown at least.

4) userName == hohoho, and password == hohoho (valid format case, but wrong
password)
   I got either popup windown nor error message on the logon page. I am especting
  an error message as Invalid Password for this user on the logon page.

    <<<< application.property >>>>
adminLogonForm.userName=User Name
adminLogonForm.userName.maskmsg=The First Character Of The User Name Must Be A
Letter.
adminLogonForm.password=Password
adminLogonForm.password.maskmsg=The First Character Of The Password Must Be A
Letter.
adminLogonForm.error.password=Invalid Password for this user.


<<<< Here is the validation.xml file >>>>>
<global>
    <constant>
        <constant-name>passwordMask</constant-name>
        <constant-value>^[a-zA-Z]{1}[a-zA-Z0-9_]*$</constant-value>
    </constant>
</global>
<formset>
 <form	name="adminLogonForm">
       .
       .
   <field property="password"
     depends="required,minlength,maxlength,mask">
         <msg name="mask" key="adminLogonForm.password.maskmsg"/>
         <arg0 key="adminLogonForm.password"/>
         <arg1 name="minlength" key="${var:minlength}" resource="false"/>
         <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
         <var>
              <var-name>minlength</var-name>
              <var-value>6</var-value>
         </var>
         <var>
              <var-name>maxlength</var-name>
              <var-value>12</var-value>
         </var>
         <var>
              <var-name>mask</var-name>
              <var-value>${passwordMask}</var-value>
         </var>
      </field>
    </form>
</formset>


<<<<<    struts-config.xml >>>>>>>
   <form-bean	name="adminLogonForm"
       type="com.wlwa.Infra.WebComponemt.Dispatcher.Forms.AdminLogonForm" />
   </form-beans>
 
   <global-forwards>
    <forward   name="logoff" path="/adminLogoff.do"/>
    <forward   name="logon" 
               path="/Infra/WebComponemt/Presentation/AdminLogon.jsp"/>
   </global-forwards>
 
   <action   path="/adminLogonSubmit"
      type="com.wlwa.Infra.WebComponemt.Dispatcher.Actions.AdminLogonAction"
      name="adminLogonForm"
      scope="session"
      validate="true"
      input="logon">
      <forward name="success" 
               path="/Infra/WebComponemt/Presentation/index.jsp"> />
    </action>
 
<<<<<   Here is my ActionLogon.java >>>>>
     ActionMessages actionsMsgs = new ActionMessages();
     // Validate the request parameters specified by the user
     String username = (String) PropertyUtils.getSimpleProperty(form,"userName");
     String password = (String) PropertyUtils.getSimpleProperty(form,"password");
 
     try {
       if (lookUpUser(password, username) == false) {
         actionsMsgs.add(ActionMessages.GLOBAL_MESSAGE, 
                   new ActionMessage("adminLogonForm.error.password"));
        }
     } catch (Exception ex) {
       // Report any actionsMsgs we have discovered back to the original form
       actionsMsgs.add(ActionMessages.GLOBAL_MESSAGE, 
           new ActionMessage("adminLogonForm.error.password", ex.toString()));
       saveMessages(request,actionsMsgs);
       if (log.isDebugEnabled()) {
        log.debug("validation of user passwword failed for username:" +username);
        log.debug("End of execute ");
       }
       return (mapping.getInputForward());
     } //end try-catch 
 
     if (log.isDebugEnabled()) {
        	log.debug("execute : password validation ended for user :" + username);
     }
 
     // Report any actionsMsgs we have discovered back to the original form
     if (!actionsMsgs.isEmpty()) {
      saveMessages(request, actionsMsgs);
      if (log.isDebugEnabled()) {
       log.debug("validation of user passwword failed for username:" + username);
       log.debug("End of execute ");
      }
      return (mapping.getInputForward());
     }
 
<<<< server.log >>>>>
DEBUG [org.apache.commons.beanutils.ConvertUtils] Convert string 'kamhoho' to
class 'java.lang.String'
DEBUG [org.apache.commons.beanutils.ConvertUtils]   Using converter
org.apache.commons.beanutils.converters.StringConverter@1712651
DEBUG [org.apache.commons.beanutils.BeanUtils] 
setProperty(com.wlwa.Infra.WebComponemt.Dispatcher.Forms.AdminLogonForm@8aeedc,
userName, [tytyty])
DEBUG [org.apache.commons.beanutils.ConvertUtils] Convert string 'tytyty' to
class 'java.lang.String'
DEBUG [org.apache.commons.beanutils.ConvertUtils]   Using converter
org.apache.commons.beanutils.converters.StringConverter@1712651
DEBUG [org.apache.struts.action.RequestProcessor]  Validating input form
properties
DEBUG [org.apache.struts.action.RequestProcessor]   No errors detected, accepting
input
DEBUG [org.apache.struts.action.RequestProcessor]  Looking for Action instance
for class com.wlwa.Infra.WebComponemt.Dispatcher.Actions.AdminLogonAction 
DEBUG [org.apache.struts.action.RequestProcessor]   Returning existing Action
instance
DEBUG [com.wlwa.Infra.WebComponemt.Dispatcher.Action.AdminLogonAction] Begin of
execute 
DEBUG [com.wlwa.Infra.WebComponemt.Dispatcher.Action.AdminLogonAction] execute :
password validation ended for user : tytyty
DEBUG [com.wlwa.Infra.WebComponemt.Dispatcher.Action.AdminLogonAction] End of
execute 
DEBUG [org.apache.struts.tiles.TilesRequestProcessor]
processForwardConfig(/Infra/WebComponemt/Presentation/index.jsp, false)
DEBUG [org.apache.struts.tiles.TilesRequestProcessor] 
'/Infra/WebComponemt/Presentation/index.jsp' - processed as uri
DEBUG [org.apache.struts.action.RequestProcessor]
processForwardConfig(ForwardConfig[name=success,path=/Infra/WebComponemt/Presentation/index.jsp,redirect=false,contextRelative=false])  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org