【问题标题】:JSF redirect to same URL with different parametersJSF 重定向到具有不同参数的相同 URL
【发布时间】:2015-03-19 21:48:32
【问题描述】:
我的网站结构如下:
web
|_events
|_view.xhtml
|_news
|_view.xhtml
|_pages
|_view.xhtml
...
当用户点击一个链接,比如说,Event #4,他将被重定向到例如http://example.com/events/view.xhtml?itemId=4
在 event->view.xhtml 页面上,我有一个菜单,其中包含一些其他事件的链接(与当前查看的事件有关)。假设它们是 Event #1 和 Event #2。
目前我的菜单链接有 value="../event/view.xhtml?itemId=#{row.id}"。当它被点击时,用户将被重定向到例如http://example.com/events/view.xhtml?itemId=2
但是如果我使用这种方法(在 URL 中使用“../event/”),这意味着我必须创建另外两种链接类型,分别是新闻和页面的 URL。以及我制作的所有其他物品类型...
有没有办法只放“itemId=X”,即只在链接值中放新的参数值?然后我可以为我网站上的每种项目类型使用一个菜单模板。
谢谢!
【问题讨论】:
标签:
jsf
url
redirect
parameters
【解决方案1】:
您可以根据您的用例在 ApplicationScope 或 SessionScope 中使用 List 并在那里添加所有类型。
类似
public class Type implements Serializable {
private String name;
private List<Integer> items;
//getters and setters
}
托管豆
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>