2013-01-14 42 views
4

我想將一些變量值傳遞給pretty-config.xml配置文件中的view-id節點。對於樣本:如何將參數傳遞給Pretty-Faces中的view-id?

我想要做這樣的事情:

<url-mapping id="allReports"> 
     <pattern value="/report/#{type}" /> 
     <view-id value="/pages/report/#{type}.xhtml" /> 
    </url-mapping> 

但我得到的錯誤:

java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in fragment at index 18: http://localhost/#{type}.xhtml 

有人知道該怎麼做呢?

謝謝。

回答

3

隨着Prettyfaces main website說,你必須做下列之一:

<url-mapping id="view-user"> 
    <pattern value="/user/{username}" /> 
    <view-id value="/user/view.xhtml" /> 
</url-mapping> 

這相當於/user/view.xhtml?username=yourParam。如果您輸入此網址/user/Administrator,則會在您的視圖中收到名稱爲username且值爲Administrator的請求參數。只要遵循這個約定。

如果你想從父母身份繼承只是write a mapping for each type。例如,你可以這樣寫:

<url-mapping parentId="view-user" id="admins"> 
    <pattern value="/admin/#{user}" /> 
    <view-id value="/user/admins/view.xhtml" /> 
</url-mapping> 

<url-mapping parentId="view-user" id="externals"> 
    <pattern value="/external/#{user}" /> 
    <view-id value="/user/externals/view.xhtml" /> 
</url-mapping> 

你也有dynamic view id's,但我認爲這是不可能的,靜態的字符串一塊Concat的他們。要以您想要的方式使用它們,您應該從請求中獲取參數,並在bean中處理完整的目標網址。

+0

,但我不想查詢PARAM風格。路徑參數是。這是可能的 ? – abyteneverlie

+0

更新後的回覆。 –

0

我創造了它這樣的:

漂亮-config.xml中

<url-mapping id="static"> 
    <pattern value="/s/#{staticViewBean.requestPath}" /> 
    <view-id value="#{staticViewBean.getViewId}" /> 
</url-mapping> 

StaticViewBean.java

@Controller("staticViewBean") 
@Scope("request") 
public class StaticViewBean { 

    private String requestPath; 

    public String getViewId() { 
     return "/WEB-INF/pages/s/" + requestPath + ".xhtml"; 
    } 

    public String getRequestPath() { 
     return requestPath; 
    } 

    public void setRequestPath(String requestPath) { 
     this.requestPath = requestPath; 
    } 

}