ipaddimm-75
ipaddimm-75

Reputation: 21

how prevent duplicate code in wicket

Sorry my english is bad

I have two class profile and EditProfile

in both class i have

protected void addContent(PageParameters pageParameters) {
        final String email = pageParameters.get(ListUser.USER_EMAIL).toString();
        final User loggedUser = getLoggedUser();

        if (email == null) {
            redirectToInterceptPage(new ErrorPage404(null));
            return;
        }

        User userByEmail = userService.findByEmail(email);

        if (userByEmail == null) {
            redirectToInterceptPage(new ForbiddenPage403(null));
            return;
        }

        final UserDetachableModel user = new UserDetachableModel(userByEmail);

        // If the user is not active, there is no need to edit your profile.
        if (!user.getObject().isActive()) {
            redirectToInterceptPage(new ErrorPage404(null));
            return;
        }

        // Only admins can see the profile of other users.
        if (!loggedUser.getUserRole().equals(UserRole.ADMIN) && !loggedUser.getEmail().equalsIgnoreCase(email)) {
            redirectToInterceptPage(new ForbiddenPage403(null));
            return;
        }

    ......PROCESS TO SEE PROFILE OR EDIT PROFILE........
}

I use a CustomMountedPage that i use to hide the serial number of wicket. Example http://HOST/Page/subPage?ID&PARAMS to see http://HOST/Page/subPage?PARAMS and access to another profile

How prevent duplicate code!!

Upvotes: 0

Views: 135

Answers (1)

rotsch
rotsch

Reputation: 1939

You can use Panels. They have their own markup file like a normal page but you can use them in any other Wicket-Page as a component.

Have a look at this page to see how to use panels correctly.

Upvotes: 1

Related Questions