需要在 <p:commandLink/>
之后打开或重定向到多个页面(primefaces 库的)被单击。
有一个包含 url 的列表。我已经尝试过了:
List<String> newUrlsList = returnNewUrlsList(oldUrl);
for (int i = 0; i < newUrlsList.size(); i++) {
//Executes the redirect for each of the elements in the list
//In every url, in the case of the method returnNewUrlsList() has encountered more than one URL
FacesContext.getCurrentInstance().getExternalContext().redirect(newUrlsList.get(i));
}
但仅打开第一个 URL (i=0)。
<小时/>此外,我还尝试了如下 JavaScript:
<a href="#" class="openPages"> Link </a>
运行:
<script type="text/javascript">
$('a.openPages').click(function (e) {
e.preventDefault();
window.open('http://www.google.com.br');
window.open('http://www.google.com.br');
window.open('http://www.google.com.br');
window.open('http://www.google.com.br');
window.open('http://www.google.com.br');
});
</script>
它有效,但不是最好的方法,因为每当需要打开多个选项卡时,它都会显示浏览器阻止弹出窗口的警告。
<小时/>如果有好的建议,我将不胜感激。
提前致谢!
最佳答案
您无法从 Primefaces(或任何其他服务器端引擎)打开多个窗口。您必须从客户端执行此操作,就像您已经使用 Javascript 所做的那样。
如果需要,您可以使用 EL 表达式构建动态 URL 列表,但您必须使用 Javascript 的 window.open()
才能同时打开多个页面。
关于javascript - JSF 重定向/从列表中打开多个 url<String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49901772/