JSF Navigation and AJAX

UI Components for JSF
Post Reply
GottfriedEgger
Posts: 6
Joined: 14 Mar 2012, 11:00

14 Mar 2012, 16:26

Hello

Up to now, you have to add ajax="false" to the command button if you use JSF standard navigation (outcome).

But there are usecases where you don't know if the button navigates or not:

first example:
depending on some state the 'next' button displays a popup or navigates no another page

second example:
you enter some data to a search form. If there is just one result navigate to the next page. On zero or many results stay on the same page and update the table.

It would be very practical of JSF navigation works with ajax="true".

Should I make a probably a feature request?

Hamsterbau
Posts: 401
Joined: 28 Dec 2011, 17:44

14 Mar 2012, 16:53

First: You can use dynamic navigation (action returned from a bean for example)
Second: NavigationHandler can be used in a PhaseListener or directly in your bean.

There are already many things you could do with JSF2 navigation. One good source:
http://mkblog.exadel.com/2009/09/learni ... avigation/

Here for the NavigationHandler implementation:
http://docs.oracle.com/javaee/6/api/jav ... ndler.html

Also Javascript already give you some sort of navigation (i hope this following code is valid, not tested):

Code: Select all

onclick="if(#{myBean.reallyNavigate}) { submit(); } else { return false; }"
Primefaces 6.1.8 (PF Extensions 6.1.5)
JSF: Mojarra 2.2 (Spec 2.2) - running on WildFly 10.1.0.Final

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

14 Mar 2012, 17:02

also navigation can be done with ajax redirect

Code: Select all

<p:commandButton value="goToPagexyz" action="pagexyz?faces-redirect=true"/>
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

GottfriedEgger
Posts: 6
Joined: 14 Mar 2012, 11:00

14 Mar 2012, 17:28

The thing is, that we currently migrating our project to PrimeFaces. Previosly we've worked with navigation rules and outcomes. I don't want to implement some other navigation handler.
The 'realyNavigate'-solution doesn't work for every case. I.e. it doesn't really work for the second example I've described on the first post, because the determination if the result contains one or many items can just be done within the action.

The only thing I'd like to have a working p:commandButton with ajax="true" for navigation. So either a navigation is done to the next page, or the current page is updated. I could do it with ajax="false" but then a full request is done instead uf just an ajax request.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

14 Mar 2012, 17:51

Can you share your bean and xhtml and navigation cases, so we can advise further?

I'm not using JSF standard navigation at all as I have one /index.xhtml that contains ui:include src="#{bean.page}", and I have hundreds of xhtml pages that is displayed via this concept of mine. Of course. I use actionListener="#{bean.method}" for p:commandButton's and for certain pages and PrimeFaces components and situations/scenarios, I use both ajax="false" and ajax="true", and most of my beans are ViewScoped. Only userController and PageNavigationController are SessionScoped. This works as designed for me.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

GottfriedEgger
Posts: 6
Joined: 14 Mar 2012, 11:00

15 Mar 2012, 08:58

Thanks for the fast responses!
I tried out the solution from kwintesencja with the faces-redirect=true.

The bean looks now like this:

if (unternehmensList.size() == 1) {
return goToKepPartnerDetailAction.execute() + "?faces-redirect=true";
}
return null;

And I could remove the ajax="false" on the command button:

<p:commandButton id="cmdToggleShowPartnerSuchresultateAction"
value="Search" action="#{showSearchResultBean['execute']}"
update=":searchForm:partnerSearchResult">
</p:commandButton>

So when the search result is not 1 a POST is done, but on Navigation a GET. So that was the solution I've looked for.
THX a lot

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests