Continue pressing a button twice

Yesterday I asked a question about the need to double-click a button to make it work. I got good help, which is the hallmark of stackoverflow, but the problem still exists. I cut my code to a minimum and the problem still exists. I carefully read the BalusC proposal, hoping that I would find the form inside the form. Of course, I donโ€™t see anything, so I will send my code in the hope that additional pairs of eyes will see something.

I have a template that I call from the greeting (part of the input). This applies to userInfo, which has a command button. This is the button that I mysteriously must click twice. When I press the second button, the command button will lead me to userPhoto. Everything is cut to a minimum so that I can publish it.

master.xthml:

<?xml version="1.0" encoding="UTF-8"?> <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <h:head> <title>Master template</title> </h:head> <h:body> <p:layout fullPage="true" > <p:layoutUnit position="north" size="254"> Top </p:layoutUnit> <p:layoutUnit position="east" size="50" resizable="true"> Hello </p:layoutUnit> <p:layoutUnit position="south" size="30"> south </p:layoutUnit> <p:layoutUnit position="center"> <ui:insert name="AreaOne">Default text</ui:insert> </p:layoutUnit> </p:layout> </h:body> </html> 

welcome1.xhtml:

 <?xml version="1.0" encoding="UTF-8"?> <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <ui:composition template="master.xhtml"> <ui:define name="AreaOne"> <h:form id="form1"> <p:commandButton type="submit" value="Login" action="userInfo" /> </h:form> <p:messages /> </ui:define> </ui:composition> </html> 

And last but not least, userInfo.xhtml with a button that you need to double-click:

 <?xml version="1.0" encoding="UTF-8"?> <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <ui:composition template="master.xhtml"> <ui:define name="AreaOne"> <h:form id="formP"> <p:commandButton type="submit" value="photos" action="userPhoto" /> </h:form> <p:messages /> </ui:define> </ui:composition> </html> 

I donโ€™t see any form embedded in any other form, but SOMETHING is wrong, and I canโ€™t understand that. Perhaps BalusC is correct that it has something to do with ajax, but I don't see that either.

Thanks for the help. Ilan

I added a button on the userPhoto page, which returns to the user information page. The "Login" button is the only one that works the first time it is clicked. When I use the command buttons to switch between userInfo and userPhoto, it always takes 2 clicks. I will show the center userPhoto

 <ui:composition template="master.xhtml"> <ui:define name="AreaOne"> <h:form id="form3"> <p:commandButton type="submit" value="home page" action="userInfo" /> </h:form> <p:messages /> </ui:define> </ui:composition> 
+2
ajax jsf primefaces
source share
1 answer

You have a very specific problem. You are completely navigating with ajax instead of the usual synchronous request, and the whole view is replaced with a new view. Forms in the new view no longer have a view state that is actually associated with JSF issue 790 . It is also impossible to refer to forms in update <p:commandButton> , since forms do not exist in the same view.

After all, it is not recommended to navigate ajax completely. This makes your page unclassifiable and non-searchbotindexable. I suggest replacing all forms

 <p:commandButton ... action="otherViewId" /> 

by

 <p:button ... outcome="otherViewId" /> 

This will navigate through regular synchronous requests and create new views in which all forms will have their view state. Note that <p:button> does not require <h:form> , you can omit it if necessary.


Unrelated to a specific problem, I also suggest placing master.xhtml in the /WEB-INF folder so that end users can never request it by entering / guessing its URL in the address bar of the browser. See Also Which XHTML files do I need to enter / WEB -INF and which do not?

+7
source share

All Articles