0

In this simple page below, both the standard button and the PrimeFaces button trigger the validation and display the expected message. However, if there is no validation error, the browser navigates to nextPage.xhtml only if the standard button Submit B is used. Pressing Submit A just seems to alter the appearance of the page somewhat, and no navigation takes place.

<h:head>
   <title>Some Title</title>
</h:head>

<h:body>
   <h:form id="form">
      <p:panelGrid id="panel" columns="2" border="0" cellpadding="10" cellspacing="1">      
         <p:outputLabel value="Enter Username" />
         <p:inputText id="username" size="20" label="UserName" required="true">
            <f:validateLength for="username" minimum="5" maximum="20" />            
         </p:inputText>

         <p:outputLabel value="PrimeFaces Btn" />
         <p:commandButton value="Submit A" action="nextPage" update="form"/>

         <p:outputLabel value="Standard Btn" />
         <h:commandButton value="Submit B" action="nextPage" />
      </p:panelGrid>
      <!-- <p:messages autoUpdate="true" /> -->
      <p:message for="username" />
   </h:form>
</h:body>
</html>
DTs
  • 1,196
  • 1
  • 11
  • 28
  • Your Example working just fine for me. Using Primefaces 5.2 and JSF-Mojarra 2.2.0 – Kishor Prakash Oct 21 '15 at 04:27
  • If a request is done with AJAX and you need navigation, you need to use "redirect" as to `` or make a synchronous request with a navigation (thus, by setting the `ajax` attribute associated with `` to `false`). – Tiny Oct 21 '15 at 04:39
  • @Tiny Appending `?faces-redirect=true` works fine, thanks. However I was hoping to not have to do that as I'd like the URL in the address bar to remain pointing at the main App. If users bookmark the resulting page it will get messy. I'm working on a larger app, I just posted a simplified page here to illustrate the problem. There should be a different solution, note that if the standard button is pressed, it works fine with a forward, no redirect takes place. I'm also curious as to why it works for @KishorP and not me, I'm on PrimeFaces 5.2 and Mojarra 2.1.9 – DTs Oct 21 '15 at 04:58
  • The resulting page will no longer be bookmarkable, if the POST request sent is not redirected to the resulting page. If this is however, not required, then there is no option other than setting `ajax` to `false` making a synchronous forward (Browsers will warn against refreshing the page (F5)). – Tiny Oct 21 '15 at 05:29
  • @Tiny I think the option that makes sense would be to fix my environment and make this work as expected. The standard button works fine with no hacks or compromises, the PrimeFaces button should do. It works for KishorP. If only I knew where to look though, any ideas appreciated. – DTs Oct 21 '15 at 05:35
  • I have just tested on PrimeFaces 5.2 / Mojarra 2.2.12. It does not function without modifying the example. In Google search results, I have just [found](http://stackoverflow.com/a/4640701/1391249) an answer from Cagatay Civici himself, "***You must use redirect**, if you are doing navigation and request is done with ajax.*". – Tiny Oct 21 '15 at 05:51
  • Food for read: http://stackoverflow.com/q/3909267, http://stackoverflow.com/q/15521451 – BalusC Oct 21 '15 at 07:48
  • @BalusC Thanks for the pointers. The code snippet above is simplified for clarity but in the real application, my ` ` is submitting a form that registers a user. After the DB is updated, I want to navigate the user to an intermediate page that has a phone PIN validation. I don't want this page to be bookmark-able. Therefore using `?faces-redirect=true` is not appropriate. Doing `` does, is that not possible? – DTs Oct 21 '15 at 22:38
  • Just conditionally render content on same view (e.g. dialog). – BalusC Oct 22 '15 at 06:32
  • @BalusC You mean render the PIN validation page in a dialog? Then it gets messy if the user closes the browser and decides to do the validation next time they login. I can't believe I have to do all these hacks just to get the PrimeFaces button do the obvious thing that the standard button does out of the box, I find it really mind blowing. Let's look at this from a different angle: can I skin the standard button to look like the PrimeFaces button? How would I go about that? – DTs Oct 22 '15 at 07:24
  • Turning off ajax does just same as h:commandButton. – BalusC Oct 22 '15 at 07:25

0 Answers0