How to integrate wicket framework 6.x with plain old jsp

青春壹個敷衍的年華 提交于 2019-12-19 11:48:13

问题


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 ?


回答1:


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




回答2:


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().



来源:https://stackoverflow.com/questions/18997870/how-to-integrate-wicket-framework-6-x-with-plain-old-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!