Open primefaces tagcloud links in a new window

我的未来我决定 提交于 2019-12-24 15:25:25

问题


I'm using primefaces tagcloud. But when i clicked on the links given on the tagcloud, it opened in that same window.But on clicking the tagcloud links it should open in a new window not on the same window. I want a new window will open when i click on the tagcloud links. Can anyone please help me about this topics ???


回答1:


JavaScript solution:

One possible approach could be JavaScript:

<p:tagCloud model="#{tagCloudBean.model}" onclick="preventDefault(event)">
    <p:ajax event="select" update="msg" listener="#{tagCloudBean.onSelect}" />
</p:tagCloud>

onclick triggers a JavaScript function which prevents the link from getting opened.

function preventDefault(e) {
   e.preventDefault();
}

Also, by adding an ajax event you can call a listener in your managed bean.

public void onSelect(SelectEvent event) {
    TagCloudItem item = (TagCloudItem) event.getObject();
    String url = item.getUrl();
    String script = "window.open('" + url + "');"
    RequestContext.getCurrentInstance().execute(script);
}

There you can access the url of the TagCloudItem and execute a JavaScript statement which should open a new browser window.

This possible solution is untested, but just give it a try.



来源:https://stackoverflow.com/questions/24133140/open-primefaces-tagcloud-links-in-a-new-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!