5

I have a question about spring roo.

How can you add a custom page to your web application? It seems really basic and easy if I'm using standard Servlet, but I'm totally confused to do this in Spring roo. All I want to have is a link in main page (with the menus etc) that links to my custom page.

I have tried to add a new Servlet to the application, setting its path mapping to /custompage. but when I access http://localhost:8080/myapp/custompage , it shows that the resource is unavailable.

I also can't add a link in the main page, I have tried to edit the menu.jspx directly and it fails.

Can anyone shed me light on this? Any help will be greatly appreciated.

Tetrax
  • 65
  • 1
  • 6

3 Answers3

6

First of all edit your {project_root}/src/main/webapp/WEB-INF/spring/webmvc-config.xml and add new mvc:view-controller definition for your new page. Something like:

<mvc:view-controller path="/custompage" />

Then open {project_root}/src/main/webapp/WEB-INF/views/views.xml and add the following definition:

  <definition extends="public" name="custompage">
    <put-attribute name="body" value="/WEB-INF/views/custompage.jspx"/>
  </definition>

And add your custompage.jspx to the {project_root}/src/main/webapp/WEB-INF/views/ folder.

And then edit {project_root}/src/main/webapp/WEB-INF/views/menu.jspx and new menu:item with url="/custompage".

I think it should work.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • 1
    You may like to generate a controller if you want to compute some things and then pass it to the page. You may also like to have your own definition of tiles which does not depend on roo theme. – geoaxis Apr 18 '11 at 00:07
6

The simplest way is to let Roo do it for you. Use controller class --class ~.web.CustomPageController --preferredMapping /custompage and Roo will create everything for you.

Make sure you only have what you need in the resulting controller since it won't work if you have more than one mapping per request (I think the default in 1.1.4 is that there is an ambiguous mapping for a simple 'get')

robert
  • 33,242
  • 8
  • 53
  • 74
Tal
  • 71
  • 1
  • 1
  • 1
    I did that, and pared the controller down to just one "index" method that returns "custompage/index", and I verified that those view fragments got created. Even so, when I browse to /myapp/custompage, I get the Roo "resource not found" page. – Dan Ray Oct 07 '11 at 18:20
2

I did same. I got the same issue. Then I noticed webmvc-config.xml not having entry of <mvc:view-controller path="/custompage/index"/>. I put the entry and now it is working now. Make sure the presence of the above said code.

Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
Ramesh
  • 21
  • 1