如何防止wicket中的重复代码

如何防止wicket中的重复代码,wicket,dry,Wicket,Dry,对不起,我的英语不好 我有两个班级简介和编辑简介 两个班我都有 protected void addContent(PageParameters pageParameters) { final String email = pageParameters.get(ListUser.USER_EMAIL).toString(); final User loggedUser = getLoggedUser(); if (email == null) {

对不起,我的英语不好

我有两个班级简介和编辑简介

两个班我都有

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........
}
我使用一个定制的挂载页面来隐藏wicket的序列号。 示例?ID&PARAMS以查看?PARAMS并访问另一个配置文件


如何防止重复代码

您可以使用面板。它们像普通页面一样有自己的标记文件,但您可以在任何其他Wicket页面中将它们作为组件使用


请查看如何正确使用面板。

我不必阻塞整个页面或其中的一部分,只需在给定条件下执行操作即可。对不起,我不明白您的意思。。。你能重新表述一下你的问题吗?