public void updateProfile()

in tapestry-examples/Vlib/src/org/apache/tapestry/vlib/pages/EditProfile.java [102:176]


    public void updateProfile(IRequestCycle cycle)
    {
        String password1 = getPassword1();
        String password2 = getPassword2();

        setPassword1(null);
        setPassword2(null);

        IValidationDelegate delegate = getValidationDelegate();

        delegate.setFormComponent((IFormComponent) getComponent("inputPassword1"));
        delegate.recordFieldInputValue(null);

        delegate.setFormComponent((IFormComponent) getComponent("inputPassword2"));
        delegate.recordFieldInputValue(null);

        if (delegate.getHasErrors())
            return;

        Map attributes = getAttributes();

        if (Tapestry.isBlank(password1) != Tapestry.isBlank(password2))
        {
            setErrorField("inputPassword1", getMessage("enter-password-twice"));

            return;
        }

        if (Tapestry.isNonBlank(password1))
        {
            if (!password1.equals(password2))
            {
                setErrorField("inputPassword1", getMessage("password-must-match"));
                return;
            }

            attributes.put("password", password1);
        }

        Visit visit = (Visit) getVisit();
        VirtualLibraryEngine vengine = (VirtualLibraryEngine) cycle.getEngine();
        Integer userId = visit.getUserId();

        int i = 0;
        while (true)
        {
            try
            {
                /**
                 *  Note:  this allows the user to change thier e-mail
                 *  such that it conflicts with another user!  Need yet-another
                 *  IOperations method to perform the update!
                 *
                 **/

                IOperations operations = vengine.getOperations();

                operations.updatePerson(userId, attributes);
                break;
            }
            catch (FinderException ex)
            {
                throw new ApplicationRuntimeException(ex);
            }
            catch (RemoteException ex)
            {
                vengine.rmiFailure("Remote exception updating user attributes.", ex, i++);
            }
        }

        vengine.clearCache();

        MyLibrary myLibrary = (MyLibrary) cycle.getPage("MyLibrary");
        myLibrary.activate(cycle);
    }