You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Getting Web Page URL as String

Always a favorite of mine to get a page url, and send in an email, or re-display back in the current page. Any way you shake it, it becomes useful when building applications. So here goes with an example:

class MyPage extends WebPage {

{panel}
    public MyPage() {
         String url = urlFor("pageMapName", MyPage.class, new PageParameters("foo=bar"));
    }
{panel}
}

This can be then sent in an email, displayed back to the user, saved to a database, whatever you desire. You can also do so from within a Form subclass

class MyPage extends WebPage {
{panel}
   public MyPage() {
   }
{panel}

{panel}
   private class MyForm extends Form {
       public void onSubmit() {
           String url = getPage().urlFor("pageMapName", MyPage.class, new PageParameters("foo=bar"));
       }
    }
{panel}
}

Did you know you can define page class alias to not expose your package structure in the URL? Just use application.getPages().putClassAlias(MyPage.class, "myAlias"); The URL will than look like http://.../myApp?bookmarkablePage=myAlias

  • No labels