Hi, I am trying to write a component that will handle my login into my secure
pages in my application. When I am logged in the component will display that
name of the logged in user and some other information. I will also have a
for where the user can change password. The form contains Old Password, New
Password and Confirmnew Password label and input box and a button connected
to a listener. I have validation on the input boxes for required valie and a
min length. but I the validation pass this step I want to add some more
validation in my onChangePassword() metod. I want to check the old Password
agains the db, and also that new password and confirm password are the same
before I update the db. So My question is this: how do I add my own errors
in the onChangePassword() listener method to the delegate that the allready
done the basic validation. My .page file for these  (labels and input boxes)
look like this:

 <!-- CHANGE PASSWORD FORM  --> 
                <component id="changePasswordForm" type="Form" >
                        <binding name="listener" 
value="listener:onChangePassword" />
                        <binding name="delegate" value="beans.delegate" />
                </component>
        
                <!-- INPUT BOXES -->
                <component id="inputOldPassword" type="TextField" >
                <binding name="value" value="oldPassword" />
                <binding name="hidden" value="true" />    
                <binding name="displayName" value="literal:Old Password"/>
                <binding name="validators" 
value="validators:required,minLength=5" />
            </component>
            
            <component id="inputNewPassword" type="TextField">
                        <binding name="value" value="newPassword" /> 
                        <binding name="hidden" value="true" />
                <binding name="displayName" value="literal:New Password"/>
                <binding name="validators" 
value="validators:required,minLength=5"
/>
            </component>
            
            <component id="inputConfirmNewPassword" type="TextField">
                        <binding name="value" value="confirmNewPassword" /> 
                        <binding name="hidden" value="true" />
                <binding name="displayName" value="literal:Confirm New 
Password"/>
                <binding name="validators" 
value="validators:required,minLength=5"
/>
            </component>
            
            <!-- LABELS -->
            <component id="oldPasswordLabel" type="FieldLabel" >
                <binding name="field" value="component:inputOldPassword" />
            </component>
            
            <component id="newPasswordLabel" type="FieldLabel" >
                <binding name="field" value="component:inputNewPassword" />
            </component>
            
            <component id="confirmNewPasswordLabel" type="FieldLabel" >
                <binding name="field" value="component:inputConfirmNewPassword" 
/>
            </component>
        
                <!-- VALIDATION -->
                <property name="changePasswordCurrentFieldTracking" />
                
                <component id="changePasswordErrors" type="For" >
                        <binding name="source" 
value="beans.delegate.fieldTracking" />
                        <binding name="value" 
value="changePasswordCurrentFieldTracking" />
                </component>
                
                <component id="changePasswordError" type="Delegator" >
                        <binding name="delegate"
value="changePasswordCurrentFieldTracking.errorRenderer" />
                </component>
                
                <component id="changepasswordIsInError" type="If">
                        <binding name="condition"
value="changePasswordCurrentFieldTracking.inError" />
                </component>


and my onchangePassword() look like this:

        public String onChangePassword() {
                ValidationDelegate delegate = getDelegate();

                if (delegate.getHasErrors()) {
                        return null;
                } else {
                        /* check if oldPassword  match password from db */
                        AppUserService appUserService =
(AppUserService)getServiceLocator().locate("appUserService");
                        AppUser currentUser =
appUserService.getUserByPrimaryKey(getSessionUserInfo().getUserName());
                        if 
(!currentUser.getUserPassword().equals(getOldPassword())) {
                                //TODO : Add error message
                                System.out.println("Login: onChangePassword - 
Old Password is not equals
with password from db");
                        }                       
                        /* check that newPassword and confirmNewPassword are 
the same */
                        if 
(!getNewPassword().equals(getConfirmedNewPassword())) {
                                //TODO : add error message
                                System.out.println("Login: onChangePassword - 
New Password is not equal
with confirm new Password");
                        }                       
                        /* check if there is any new errors before updating 
AppUser */
                        if (delegate.getHasErrors()) {
                                return null;
                        } else {
                                /* set the new username to appUser and then 
Update */
                                currentUser.setUserPassword(getNewPassword());
                                appUserService.saveOrUpdateAppUser(currentUser);
                                /* add update message */
                                setUpdateMessage("Your password has been 
changed!");
                        }                       
                }               
                return null;
        }

Thanks
Jacob
-- 
View this message in context: 
http://www.nabble.com/Login-Change-Pasword-Component-tf2333791.html#a6493456
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to