Multiple paths for one class in Apache Wicket

1ac0

I have Wicket app, in WebApplication I do:

public class AppStart extends WebApplication{

    public AppStart(){
    }

    @Override
    protected void init(){
        super.init();
        mountPage("/index.html", StandardPage.class);
        mountPage("/another.html", StandardPage.class);
    }
}

but when I access /index.html then I'm redirected to /another.html page. Has been thinking that at the moment of creating page StandardPage.class will be instantiated so these two pages will be handled by two separate objects of StandardPage.class?

Martin Strejc

yes, it is true. Wicket has its own complex mechanism of handling URLs and how to redirect browser to a specific target. In Wicket using two or more different paths to mount the same page class has no idea (by default).

SOLUTION 1

If you really want to get the same functionality on different URLs, use a simple descendant

public class StandardPage2 extends StandardPage {
    //... define the same constructors from StandardPage
}

Your code

@Override
protected void init(){
    super.init();
    mountPage("/index.html", StandardPage.class);
    mountPage("/another.html", StandardPage2.class);
}

Do not forget to use correctly

setResposonsePage(StandardPage.class); 

or

setResposonsePage(StandardPage2.class);

SOLUTION 2

The following example shows how you can use a page parameter as a part of URL. Let's there are users in a databases and each user has its own page that is accessible on a unique URL. Also each user can do some optional operations and the operation name is ever included in URL and there are some other pages mounted to their own URIs. So URIs should look like

/home 
/login 
/logout 
/martin 
/martin/edit 
/martin/detail 
/petr
/petr/edit 
/petr/detail
/
/texts/my-super-article-1
/texts/my-super-article-2
/events/actual
/fotos/from-my-first-holiday
/fotos/from-my-second-holiday

In this case it is possible to use the default MontedMapper, that is ever implemented in Wicket. The mapping is

mountPage("/home", HomePage.class);
mountPage("/login", LoginPage.class);
mountPage("/logout", LogoutPage.class);
mountPage("/${nick}/${action}", UserProfilePage.class);
mountPage("/texts/${page}", TextPages.class);
mountPage("/events/${page}", EventPages.class);
mountPage("/fotos/${page}", FotoPages.class);

and you have to implement the UserProfilePage and its constructor with PageParameters

public class UserProfilePage extends WebPage {

     public UserProfilePage(PageParameters pageParameters) {
         super(pageParameters);
         StringValue nick = pageParameters.get("nick");
         StringValue action = pageParameters.get("action");
         // any code
         String nickName = nick.toString();
         boolean defaultAction = action.isEmpty(); // default action
     }

}

SOLUTION 3

Also you can override IRequestMapper and some other classes, but I think it is too much complicated and it is not necessary in your case.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple paths for one class in Apache Wicket

From Dev

Multiple classes for one markup in apache wicket

From Dev

How to select multiple options in dropdown in Apache Wicket?

From Dev

Charts with multiple axes in Apache Wicket with ShieldUI

From Dev

Matching one of multiple paths (ACL)

From Dev

emberjs using multiple paths / urls for one route

From Dev

Multiple files with one identifier in RequireJS paths

From Dev

Multiple FlowLayouts in one class?

From Dev

Multiple models in one class?

From Dev

EJB Injection Apache Wicket

From Dev

Populating table with apache wicket

From Dev

Apache Wicket textfield onUpdate

From Dev

Apache Wicket DateTextField clear

From Dev

Jacoco support for apache wicket?

From Dev

Multiple task as one - Apache Spark

From Dev

How to get at Apache Wicket PropertyColumn data to dynamically change CSS class based on content?

From Dev

How can i use Apache Wicket to process multiple model instances on a single form?

From Dev

One Servlet per path or handle multiple paths in a Servlet?

From Dev

iscsiadm discovery gives multiple paths. Want to specify one

From Dev

Paper.js draw multiple parallel paths from one path

From Dev

iscsiadm discovery gives multiple paths. Want to specify one

From Dev

Merging multiple paths into one D3(SVG)

From Dev

Paper.js draw multiple parallel paths from one path

From Dev

tag jq how to combine multiple paths into one object

From Dev

Flask SQL Alchemy Multiple join paths and one to many relationships

From Dev

html multiple class in one label

From Dev

Transclude HTML in Apache Wicket component

From Dev

How to edit LoadableDetachableModel in Apache Wicket

From Dev

Apache VirtualHost, multiple ServerName in one line

Related Related

  1. 1

    Multiple paths for one class in Apache Wicket

  2. 2

    Multiple classes for one markup in apache wicket

  3. 3

    How to select multiple options in dropdown in Apache Wicket?

  4. 4

    Charts with multiple axes in Apache Wicket with ShieldUI

  5. 5

    Matching one of multiple paths (ACL)

  6. 6

    emberjs using multiple paths / urls for one route

  7. 7

    Multiple files with one identifier in RequireJS paths

  8. 8

    Multiple FlowLayouts in one class?

  9. 9

    Multiple models in one class?

  10. 10

    EJB Injection Apache Wicket

  11. 11

    Populating table with apache wicket

  12. 12

    Apache Wicket textfield onUpdate

  13. 13

    Apache Wicket DateTextField clear

  14. 14

    Jacoco support for apache wicket?

  15. 15

    Multiple task as one - Apache Spark

  16. 16

    How to get at Apache Wicket PropertyColumn data to dynamically change CSS class based on content?

  17. 17

    How can i use Apache Wicket to process multiple model instances on a single form?

  18. 18

    One Servlet per path or handle multiple paths in a Servlet?

  19. 19

    iscsiadm discovery gives multiple paths. Want to specify one

  20. 20

    Paper.js draw multiple parallel paths from one path

  21. 21

    iscsiadm discovery gives multiple paths. Want to specify one

  22. 22

    Merging multiple paths into one D3(SVG)

  23. 23

    Paper.js draw multiple parallel paths from one path

  24. 24

    tag jq how to combine multiple paths into one object

  25. 25

    Flask SQL Alchemy Multiple join paths and one to many relationships

  26. 26

    html multiple class in one label

  27. 27

    Transclude HTML in Apache Wicket component

  28. 28

    How to edit LoadableDetachableModel in Apache Wicket

  29. 29

    Apache VirtualHost, multiple ServerName in one line

HotTag

Archive