Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

jsf - p:commandLink won't redirect to new page?

I'm using JSF2 and GlassFish, PrimeFaces 2.1.

This works, showCreateProfile() method gets hit, and the method returns "profileForm" and the browser redirects to that page:

<h:commandLink action="#{profileHandler.showCreateProfile}" value="#{msg.menu_createNewProfile}" />

However, this doesn't work, showCreateProfile() method get hits, and the method returns "profileForm" but the browser does not redirect to the page. I tried three different things with no luck:

<p:commandLink action="#{profileHandler.showCreateProfile}" value="#{msg.menu_createNewProfile}" />

<p:commandLink action="#{profileHandler.showCreateProfile}" value="#{msg.menu_createNewProfile}" ajax="false" />

<p:commandLink action="#{profileHandler.showCreateProfile}" value="#{msg.menu_createNewProfile}" ajax="false" immediate="true"/>

Any ideas what I'm doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Primefaces' p:commandLink fires by default an ajax request. It does not return a whole HTTP response, but only a partial HTTP response which has got to be updated in HTML DOM tree by JS.

You have basically two options:

  1. Disable ajax by ajax="false" attribute. It'll then fire a normal HTTP request.

  2. Update (re-render) the partial content (on the same page!) by update="clientid" attribute. You can use rendered attribute to control the rendering of content.

If neither works, then the problem lies somewhere else. Since the h:commandLink works and the action method of p:commandLink also get executed, then it can only mean that you're not running the code you think you're running while trying the ajax="false". Verify, save, rebuild, redeploy, restart.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...