[英]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.