2015-01-21 88 views
0

我有以下的網站結構:
JSF重定向到相同的URL使用不同的參數

web 
|_events 
    |_view.xhtml 
|_news 
    |_view.xhtml 
|_pages 
    |_view.xhtml 
... 


當用戶點擊一個鏈接,讓我們說,事件#4,他將被重定向到例如http://example.com/events/view.xhtml?itemId=4
event-> view.xhtml頁面我有一個菜單,其中包含一些其他事件的鏈接(與當前查看的事件有關)。假設這些是事件#1事件#2
目前我的菜單鏈接有value =「../ event/view.xhtml?itemId =#{row.id}」。當它被點擊時,用戶將被重定向到例如http://example.com/events/view.xhtml?itemId=2
但是,如果我使用這種方法(在URL中使用「../event/」),這意味着我必須創建兩個鏈接類型,其中包含新聞和頁面的URL。並且對於我製作的每種其他項目類型...
是否有任何方法僅將「itemId = X」,即鏈接值中僅包含新參數值?然後,我可以爲我的網站上的每種商品類型使用一個菜單模板。
謝謝!

回答

1

根據您的用例,您可以在ApplicationScope或SessionScope中使用List,並在其中添加所有類型。

喜歡的東西

public class Type implements Serializable { 
    private String name; 
    private List<Integer> items; 
    //getters and setters 
} 

Managed Bean的

public class TestBean { 
     private List<Type> types; 
     @PostConstruct 
     public void init(){ 
      //constructTypesAccordingToSomeLogic(); 
     } 
     //getters and setter 
} 

查看

<ui:repeat value="#{testBean.types}" var="type"> 
     <ui:repeat value="#{type.items}" var="item"> 
      <h:outputLink value="../#{type.name}.xhtml?itemId=#{item}"></h:outpuLink> 
     </ui:repeat> 
</ui:repeat> 
相關問題