0

I am looking for examples for how to ingrate wicket 6.10 with jsp We have lots of code written in jsp , which is a good code and we want it to be in our wicket 1. application to contain those jsp files , how can we integrate it ? 2. put jsp files inside wicket panel ?
3. where should those jsp files be ?

What I have done was inside web mark up :

  @Override
public void onComponentTagBody(MarkupStream markupStream, ComponentTag tag) {

    // Set up mock response and dispatch.
    ServletContext context = WebApplication.get().getServletContext();
    ServletRequest request = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest();
    MockResponse mockResponse = new MockResponse((HttpServletResponse) RequestCycle.get().getResponse().getContainerResponse());

    try {
        context.getRequestDispatcher("/" + pageName + ".jsp").include(request, mockResponse);
    } catch (ServletException | IOException e) {
        e.printStackTrace();
    }

    try {

        replaceComponentTagBody(markupStream, tag, mockResponse.getOutput());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

class MockResponse extends HttpServletResponseWrapper {
    ServletOutputStream servletStream;
    ByteArrayOutputStream byteStream;

    public MockResponse(HttpServletResponse response) {
        super(response);
        byteStream = new ByteArrayOutputStream();
        servletStream = new ServletOutputStream() {

            @Override
            public void write(int b) {
                byteStream.write(b);
            }
        };
    }

    @Override
    public ServletOutputStream getOutputStream() {
        return servletStream;
    }

    public String getOutput() throws UnsupportedEncodingException {
        return byteStream.toString("UTF-8"); 
    } 

}

the html is started by myjsp html ... and then thewicket psage what i want is all the wicket i have mocked to be inside my component how can i achive it ?

yoav.str
  • 1,547
  • 6
  • 33
  • 73
  • I've never don it myself, but this might give you some ideas: (http://herebebeasties.com/2007-03-01/jsp-and-wicket-sitting-in-a-tree/) Even though it's for older version of wicket, basic remain the same. – Michał Krzemiński Sep 25 '13 at 06:52
  • It's the first google answer , it's not compatible with 6. X versions I need a good reference for my work ... Note : all wicket rendering was changed in 1.5 therefore lots of examples out there not working due to compatibility issues – yoav.str Sep 25 '13 at 07:11

2 Answers2

3

the new version of the wicketstuff minis project is supporting the integration of jsp files into wicket pages:

<dependency>
   <groupId>org.wicketstuff</groupId>
   <artifactId>wicketstuff-minis</artifactId>
   <version>6.17.0</version><!-- or 7.0.0-M3 -->
</dependency>

Only use the following line in your Wicket-WebApplication:

getPageSettings().addComponentResolver(new WicketServletAndJSPResolver());

Then you are able to include jsp's like this:

<wicket:jsp file="/de/test/jspwicket/TestPage.jsp"/>

A documentation can be found in the "wicketstuff-minis-example"-Projekt of the same version.

kind regards

Updated information (22.10.2014):

Since the new SNAPSHOT versions of Wicketstuff the jee integration has been moved to a separate project:

<dependency>
   <groupId>org.wicketstuff</groupId>
   <artifactId>wicketstuff-jee-web</artifactId>
   <version>6.18.0-SNAPSHOT</version>
   <!-- soon 6.18.0 --><!-- or 7.0.0-SNAPSHOT, soon 7.0.0 -->
</dependency>

The class name has been changed slightly:

getPageSettings().addComponentResolver(new JEEWebResolver());

There is also a lot of new stuff to check out like form submit support with el functions / tags.

The documentation has been moved to the projects wiki page (JEE Web Integration) on github. To enable the SNAPSHOT-Repository refer to the documentation of Wicketstuff.

Updated information (15.02.2015):

http://java.dzone.com/articles/integrate-jspjsf-pages-wicket

kind regards

klopfdreh
  • 126
  • 8
0

To add JSP content to a Wicket page, you can use Include.

To use Wicket-dependent infrastructure in JSP pages (such as the WebSession and WebApplication instances, or generating URLs for Wicket pages), you can use WicketSessionFilter.

I don't know if including Wicket content in a JSP page is very advisable, but you may try the WicketTester, calling startPage() or startComponentInPage(), and then getting the resulting HTML with getLastResponseAsString().

tetsuo
  • 10,726
  • 3
  • 32
  • 35