zoukankan      html  css  js  c++  java
  • Tapestry5之方法返回值

    在JumpStart中有相关的介绍,总结一下

    void - redisplay the same page.
    null - redisplay the same page.
    false - same as returning null.

    这三个一样,应该没有什么区别。


    Class (must be a page class) - go to new page.
    String (must be a logical page name) - go to new page.

    这俩,基本相同(“PageA”, PageA.java)。


    page object - go to new page, with the option of setting up its parameters first.

    @InjectPage
    private SomePage page;

    这样的话,我们可以page.setSomeProperty("someValue");

    return page;

    即可。

    Link - go to new page, with the option of setting up a context first.

        @Inject
        private PageRenderLinkSource pageRenderLinkSource;
    
        Link onReturnLink() {
            String parameters = "Howdy";
            Link link = pageRenderLinkSource.createPageRenderLinkWithContext(ReturnTypesLink.class, parameters);
            return link;
        }

    这个貌似比较牛逼。其实和PageReturn差不大多。主要是这个Inject挺有意思,它有两个返回link的方法,一个是只有一个参数的,一个是带两个参数的,第二个参数就是所有的url参数信息。


    StreamResponse - used by pages or components to return images, PDFs, XML, etc.

    if (postfix.equals(".XLS") || postfix.equals(".XLT") || postfix.equals(".XLW") || postfix.equals(".CSV")) {
    contentType = "application/vnd.ms-excel";
    } else if (postfix.equals(".DOC")) {
    contentType = "application/msword";
    } else if (postfix.equals(".RTF")) {
    contentType = "application/rtf";
    } else if (postfix.equals(".TEXT")) {
    contentType = "text/plain";
    } else if (postfix.equals(".XML") || postfix.equals(".TXT")) {
    contentType = "";
    return;
    } else if (postfix.equals(".BMP")) {
    contentType = "image/bmp";
    } else if (postfix.equals(".JPG") || postfix.equals(".JPEG")) {
    contentType = "image/jpeg";
    } else if (postfix.equals(".GIF")) {
    contentType = "image/gif";
    } else if (postfix.equals(".AVI")) {
    contentType = "video/x-msvideo";
    } else if (postfix.equals(".MP3")) {
    contentType = "audio/mpeg";
    } else if (postfix.equals(".MPA") || postfix.equals(".MPE") || postfix.equals(".MPEG") || postfix.equals(".MPG")) {
    contentType = "video/mpeg";
    } else if (postfix.equals(".PPT") || postfix.equals(".PPS")) {
    contentType = "application/vnd.ms-powerpoint";
    } else if (postfix.equals(".PDF")) {
    contentType = "application/pdf";
    } else if (postfix.equals(".ZIP") || postfix.equals(".RAR")) {
    contentType = "application/zip";
    }

    以上就是所有的contentType了(几乎哈)。

    实现代码基本如下:

        StreamResponse onShowPDFFile()
        {
            return new StreamResponse() {
                InputStream inputStream;
                public void prepareResponse(Response response)
                {
                    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                    //inputStream = classLoader.getResourceAsStream("company/study/tapestry/pages/doc/Test.txt");
                    inputStream = classLoader.getResourceAsStream("company/study/tapestry/pages/doc/DOC.doc");
                    try {
                        response.setHeader("Content-Length", "" + inputStream.available());
                    } catch (IOException e) {
                        // Ignore the exception in this simple example.
                    }
                }
                public InputStream getStream() throws IOException
                {
                    return inputStream;
                }
                public String getContentType()
                {
                    return "application/msword";
                }
            };
        }

    URL - go to a java.net.URL of an external page.

        URL onReturnURL() throws MalformedURLException {
            return new URL("http://tapestry.apache.org");
        }

    true - redisplay same page, aborting event bubbling (see Event Bubbling example).

    这个真心不懂。

    ------------

    如果返回值为true的话,就不会继续查找满足条件的方法了。因为方法可能会出现重载等。

  • 相关阅读:
    ios中的任务分段
    UVA 531
    OGG同构(ORACLE-ORACLE)、异构(ORACLE-MYSQL)同步配置及错误解析
    JavaScript自调用匿名函数
    Redis 主从配置和参数详解
    python开发环境设置(windows)
    Havel-Hakimi定理 hdu2454 / poj1695 Havel-Hakimi定理
    libevent源码分析-介绍、安装、使用
    Linux网络监控工具nethogs
    spring(3)------控制反转(IOC)/依赖注入(DI)
  • 原文地址:https://www.cnblogs.com/voctrals/p/2981052.html
Copyright © 2011-2022 走看看