我是一名JSF初学者,我有一个简单的JSF问题,但我无法解决这里的逻辑问题。
我通过命令按钮打开新的mv.xhtml
页面,如下所示:
<p:commandButton value="#{grBean.protocolName(item)}"
onclick="window.open('/SearchMap/faces/mv.xhtml?url=#{item}')">
</p:commandButton>
我有mvBean
这是一个会话范围。我使用在postconstructed init方法中调用的函数获取url参数。方法如下:
Map <String, String>tempMap= FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
if(tempMap.get("url") !=null)
url=tempMap.get("url");
问题出在这里,因为mvBean
是会话作用域,init方法只被调用一次,因此我无法自然地获得新的url参数。
我想使用mvBean
作为sessionScoped因为我想将所有传递的URL保存在ArrayList中。
那么,当我使用会话bean时,如何获取url参数?或者您有任何建议或解决方案吗?
感谢您的帮助。
答案 0 :(得分:1)
您不必在init()
中执行此操作,这是一个快速的解决方案。将其放在mv.xtml
页面<h:form>
<p:remoteCommand name="onload" action="#{mvBean.checkUrl()}" autoRun="true" />
并将您的逻辑从init()
移至public void checkUrl()
。