2015-01-21 131 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> 
相关问题