繁体   English   中英

Pretty Faces EL注入不起作用

[英]Pretty Faces EL Injection does not work

我正在使用Primefaces和Spring在JSF 2中构建在线应用程序。 我想使用Pretty Faces使我们的搜索URL可添加书签。

这是我的pretty-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.org/prettyfaces/3.3.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://ocpsoft.org/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">

    <url-mapping id="index">
        <pattern value="/" />
        <view-id value="/sites/public/template/index.xhtml" />
    </url-mapping>

    <url-mapping id="searchWithParams">
        <pattern value="/search/#{searchView.searchQuery}/#{searchView.searchTags}/#{searchView.searchOrder}" />
        <view-id value="/sites/public/product/productSearch.xhtml" />
    </url-mapping>

    <url-mapping id="searchWithoutParams">
        <pattern value="/search" />
        <view-id value="/sites/public/product/productSearch.xhtml" />
    </url-mapping>

</pretty-config>

这是我要注入的Bean:

@Component
@Scope("request")
public class SearchView {

    private String searchQuery = "";

    private String searchTags = "";

    private String searchOrder = "";


    public SearchView() {
        // void
    }

    public void navigate() {
        String url = "";
        try {
            url =  "/search" + 
                    "/" + URLEncoder.encode(searchQuery, "UTF-8") + 
                    "/" + URLEncoder.encode(searchTags, "UTF-8") + 
                    "/" + URLEncoder.encode(searchOrder, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            url = "/search";
        }

        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(url);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


    // Getters and Setters ...

}

只有“ /搜索”可以很好地工作。 我还尝试过更改pretty-config.xml中的映射顺序,并对其他两个参数使用伪值,并且仅使用一个参数。 我尝试的另一件事是将表达式“#{bean.param}”更改为“#{getParam:bean.param}”。 更改bean的范围也无济于事。

在网页上,我使用了带有“ searchView.navigate”作为操作参数的primefaces命令链接。

我总是收到以下错误消息:

HTTP状态404-/ search / a / b / c

类型状态报告

消息/ search / a / b / c

说明所请求的资源(/ search / a / b / c)不可用。

绝对采用/search/#{searchView.searchQuery}/#{searchView.searchTags}/#{searchView.searchOrder}这样的模式是一个坏主意。

这是Prettyfaces团队负责人@Lincon 对话的引文:

  • :另外一个,是否可以在模式中添加两个参数? / detail /#{appId} /#{navigationIndex}一样
  • Lincon :当然,您可以创建一个辅助URL映射,该映射也将显示相同的view-ID,并且只要参数不同即可,例如:一个映射为“ / detail”,另一个为“ / detail /#{appId }“, 你会没事的。 但是,如果它们具有相同的模式,那么您将遇到问题。

我个人甚至不将EL表达式用于网址格式。 我开始使用它们,但是它们有一个很大的缺点:它们会迫使您指定在模式中写入的url。

例如,拥有/ students /#{studentId}总是会迫使您指定学生ID才能到达该页面。 否则,您需要为同一view-id声明另一个模式。 Appart从此开始,GET请求中的第二个参数将始终迫使您使用http标准方式传递参数(假设您想添加第二个参数,则需要/ students / detail /#{studentId}?viewMode = 2 ,以其他方式传递它们)。

对我来说,声明/ students / detail之类的东西要容易得多,然后以经典(不太漂亮)的HTTP方法传递参数: / students / detail?studentId = 1&viewMode = 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM