admin管理员组文章数量:1334374
I'm trying to implement primefaces' RemoteCommand tag to my application, but somehow it doesn't work as the docs say.
What I'm trying to implement: I have a several pages with different layouts, but all are using the same JSF Template. (Basically the content of the template changes). The different pages should load automatically though, one after another, one by one, with an interval between one another.
<p:remoteCommand name="remoteSwitchPage" actionListener="#{circuitBean.redirect()}" autoRun="false"/>
This is my JSF code, which should
supply me with a JavaScript method called remoteSwitchPage()
, but it does not! It should also not
run, because I've said autoRun="false"
, but it runs on load! After calling the method remoteSwitchPage()
it should render another page via Java (This one works actually. Somehow JSF wouldn't find the redirect method when leaving the brackets, that's why I've put them).
So summarized:
- JavaScript does not supply me with the
remoteSwitchPage()
- The remoteCommand runs on page load, which it
should not!
- JSF won't find my ManagedBean method
resize()
, when leaving the brackets
Do you guys got any clue what I am doing wrong here?
I'm using primefaces 4.0
and JSF 2.1
I'm trying to implement primefaces' RemoteCommand tag to my application, but somehow it doesn't work as the docs say.
What I'm trying to implement: I have a several pages with different layouts, but all are using the same JSF Template. (Basically the content of the template changes). The different pages should load automatically though, one after another, one by one, with an interval between one another.
<p:remoteCommand name="remoteSwitchPage" actionListener="#{circuitBean.redirect()}" autoRun="false"/>
This is my JSF code, which should
supply me with a JavaScript method called remoteSwitchPage()
, but it does not! It should also not
run, because I've said autoRun="false"
, but it runs on load! After calling the method remoteSwitchPage()
it should render another page via Java (This one works actually. Somehow JSF wouldn't find the redirect method when leaving the brackets, that's why I've put them).
So summarized:
- JavaScript does not supply me with the
remoteSwitchPage()
- The remoteCommand runs on page load, which it
should not!
- JSF won't find my ManagedBean method
resize()
, when leaving the brackets
Do you guys got any clue what I am doing wrong here?
I'm using primefaces 4.0
and JSF 2.1
2 Answers
Reset to default 3if you use:
<p:remoteCommand name="remoteSwitchPage" actionListener="#{circuitBean.redirect}" />
JSF will try to find getRedirect
, that's why you should use the circuitBean.redirect()
.
EDIT: i think you should use action
instead of actionListener
.
Here is my example code (tested):
HTML:
<a href="#" onclick="logoutAccount()"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
Another part of HTML (end of the page):
<h:form prependId="false">
<p:remoteCommand action="#{sessionMB.logout()}" name="logoutAccount" />
</h:form>
Bean:
public void logout() {
account = null;
logged = false;
FacesUtil.addInfoGrowl(MessageProvider.getMessage("message.logout.success"), null);
FacesUtil.redirectToPage("", true);
}
redirectToPage method:
public static boolean redirectToPage(String pletePath, Boolean keepMessages) {
try {
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(keepMessages);
FacesContext.getCurrentInstance().getExternalContext().redirect(SimegoUtil.redirectProject() + pletePath);
return true;
} catch (IOException ex) {
FacesUtil.addErrorGrowl(MessageProvider.getMessage("message.redirectFail"), null);
return false;
}
}
So, will be like this:
Click > call remoteCommand Javascript > call bean > redirect to another page
I just didn't get the template part you said, if i can help in something more just tell me, hope you fix it.
SOLVED
Managed it as said in the ment of Simegos' Post.
I created a hidden button that would be clicked every X seconds by JavaScript. Every page that bees rendered after the button got clicked, needs to implement the following code. It would be ideal to put the code in a template which all rendered pages will implement.
<h:form id="form" class="hidden"> --> Hidden button
<h:mandButton id="switchPageButton" action="#{circuitBean.renderNextScreen()}"/>
</h:form>
<h:outputScript>
$(function() {
$(".hidden").each(function() { --> Declare Form as hidden, since it bees overwritten by JSF
$(this).css("display","none");
});
var switchPageLink = $("#form\\:switchPageButton"); --> Get Button via ID
window.setInterval(function() {
switchPageLink.click(); --> Click it
}, #{circuitBean.pageInterval}); --> after X seconds. I'm reading the interval through the bean here. You can just put a number in there
});
</h:outputScript>
本文标签: javaJSF amp PrimefacesRemoteCommand not working properlyStack Overflow
版权声明:本文标题:java - JSF & Primefaces - RemoteCommand not working properly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742261925a2442674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论