0

i know there are many similar questions on this (an other) site but none of them helped me with my problem. i have 2 wicket stateful pages. the pages are mounted as follows:

mountPage(firstPath, firstPage.class);
mountPage(secondPath, secondPage.class);

when loading the page firstPage for the first time, it loads with the default constructor and url looks as desired. once the form in the firstPage gets submitted, i forward to the stateful page secondPage as follows:

Page secondPage = new secondPage(arg1, arg2);
RequestCycle().setResponsePage(secondPage);

although the second page is mounted, the resulting page (secondPage) renders with the following url:

context?21-1.IFormSubmitListener-componentName-childComponentName-childComponentName-someForm

what i want is the secondPage to be rendered with the mounted path i defined. i know that this is a stateful page and in order for wicket to load the exact instance of it the url must be stateful. i don't mind having a page version and id in the url, i just don't want to have this long ugly component path in the url. also, i don't understand why do i need the path to the form from the firstPage in the secondPage's url.

as far as i understand the wicket 1.4 HybridUrlCodingStrategy could do something similar, but i can't find any way to do it in wicket 1.5. is this even a possible thing to do with wicket?

any help would be much appreciated, as this really blocks me, and i have already spent too much time trying to solve it with no luck.

zuckermanori
  • 1,675
  • 5
  • 22
  • 31

1 Answers1

0

Try replacing:

Page secondPage = new secondPage(arg1, arg2);
RequestCycle().setResponsePage(secondPage);

with:

RequestCycle().setResponsePage(secondPage.class);

Should work off the top of my head...

EDIT: Just noticed you are passing parameters, in which case you will need to change secondPage to be something like:

class secondPage extends WebPage
{
    public secondPage(PageParameters params) //Instead of secondPage(Type1 arg1, Type2 arg2)
    {
        arg1Type arg1 = params.get(0).to*{arg1Type}*();
        arg2Type arg2 = params.get(1).to*{arg2Type}*();
    }
}

and then call:

PageParameters params = new PageParameters();
params.set(0, arg1);
params.set(1, arg1);
RequestCycle().setResponsePage(secondPage.class, params);
Jamey
  • 813
  • 1
  • 12
  • 27
  • the problem with your suggestion is that arg1 and arg2 are complex java objects, while PageParameters handles only StringValue, so whenever i try to add/get my args to the PageParameters i get a ClassCastException. – zuckermanori Jul 26 '12 at 14:12
  • Fair enough, I found this: http://apache-wicket.1842946.n4.nabble.com/Object-in-PageParameters-td1870381.html It basically suggests passing a unique ID which can be used to reconstruct the parameter. If you can't persist the object to a database and retrieve it, try Serializing it... Not ideal, you might also try something like here: http://stackoverflow.com/questions/8602489/delete-version-number-in-url – Jamey Jul 26 '12 at 15:06
  • First you can have both constructor, the one with parmas calling the 2nd one. – Kazaag Jul 26 '12 at 18:35
  • You would still need a way to convert the Java Object to a primitive type so that you can pass it to the second constructor though... I've just had another thought, you could store the Object in the Session between requests. Try adapting the following: https://cwiki.apache.org/WICKET/custom-websession-storing-objects-in-session.html. Not sure if that's particularly good practice though, I'm pretty sure this is meant to be for Objects that persist across the entire session not just across a page request... I assume it's not possible to refactor the code so that it is all on one page? – Jamey Jul 27 '12 at 08:20
  • thank you all. i can persist the parameters to the session/database, however, i wanted to know if there's a built in wicket solution that will be simpler. thanks again, appreciate your help, as always. – zuckermanori Jul 29 '12 at 06:32
  • having a similar problem I stumbled upon this question. Was it ever resolved? And NOT by serializing to the database. (LOL) – froderik Sep 18 '12 at 14:30