继续按两次按钮

Ila*_*Tal 2 ajax jsf primefaces

昨天我发布了一个关于必须按两次按钮才能使其工作的问题.我收到了很好的帮助,这是stackoverflow的标志,但问题仍然存在.我将我的代码减少到最低限度,问题仍然存在.我仔细阅读了BalusC的建议,希望我能在表格中找到一个表格.我肯定没有什么可以看到所以我会发布我的代码,希望额外的双眼会看到一些东西.

我有一个模板,我从welcome(登录部分)调用.这将转到userInfo,它有一个命令按钮.这是我神秘地要按两次的命令按钮.在第二次按下命令按钮将我带到userPhoto.一切都被削减到最小,以便我可以发布它.

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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

最后但并非最不重要的是userInfo.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="formP">
            <p:commandButton type="submit" value="photos"  action="userPhoto" />
        </h:form>
        <p:messages />
    </ui:define>
</ui:composition>
</html>
Run Code Online (Sandbox Code Playgroud)

我没有看到嵌套在任何其他形式的任何形式,但SOMETHING错了,我无法弄清楚是什么.也许BalusC是正确的,它与ajax有关,但我也没有看到.

谢谢你的帮助.宜兰

我在userPhoto页面上添加了一个按钮,该按钮返回到userInfo页面."登录"按钮是唯一一个在第一次按下时工作的按钮.当我使用命令按钮在userInfo和userPhoto之间来回切换时,它总是需要2次推送.我将展示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>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 7

你有一个非常具体的问题.您完全通过ajax导航而不是通过正常的同步请求进行导航,并且整个视图将替换为新视图.新视图中的表单不再具有视图状态,这确实与JSF问题790有关.它也不可能引用表格中update<p:commandButton>作为形式在同一视图不存在.

毕竟,不建议用ajax完全导航.它使您的页面不可收藏且非searchbotindexable.我建议更换所有形式的

<p:commandButton ... action="otherViewId" />
Run Code Online (Sandbox Code Playgroud)

通过

<p:button ... outcome="otherViewId" />
Run Code Online (Sandbox Code Playgroud)

这将通过常规同步请求进行导航,并将创建新视图,其中所有表单都将具有其视图状态.请注意,<p:button>不需要<h:form>,您可以在必要时省略它.


无关的具体问题,我也建议把master.xhtml/WEB-INF文件夹,以便在最终用户不能输入/猜测它的URL在浏览器地址栏中提出要求.另请参阅哪些XHTML文件需要放入/ WEB-INF,哪些不是?