连续按下按钮两次 [英] continuation of pressing button twice

查看:14
本文介绍了连续按下按钮两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我发布了一个关于必须按两次按钮才能使其工作的问题.我得到了很好的帮助,这是 stackoverflow 的标志,但问题仍然存在.我将代码缩减到最低限度,但问题仍然存在.我仔细阅读了 BalusC 建议,希望我能找到表格里面的表格.我当然看不到任何东西,所以我会发布我的代码,希望更多的眼睛能看到一些东西.

Yesterday I posted a question about having to press a button twice to get it to work. I received good help, which is the hallmark of stackoverflow, but the problem still exists. I cut down my code to the bare minimum and the problem still exists. I read closely a BalusC suggestion, hoping that I would find a form inside a form. There is certainly nothing I can see so I will post my code in the hopes that additional pairs of eyes will see something.

我有一个模板,从welcome(登录部分)调用.这将转到具有命令按钮的 userInfo.这是命令按钮,我神秘地必须按两次.第二次按下命令按钮会将我带到 userPhoto.一切都被缩减到最低限度,以便我可以发布.

I have a template which I call from welcome (the login part). This goes to userInfo which has a command button. This is the command button which I mysteriously have to press twice. On the second push the command button will take me to userPhoto. Everything is trimmed down to the minimum so that I can post it.

master.xthml:

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:

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>

最后但并非最不重要的是 userInfo.xhtml 需要按两次按钮:

And last but not least userInfo.xhtml with the button which needs to be pressed twice:

<?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>

我没有看到任何表单嵌套在任何其他表单中,但有些错误,我无法弄清楚是什么.也许 BalusC 是正确的,它与 ajax 有关,但我也没有看到.

I don't see any form nested inside any other form, but SOMETHING is wrong and I can't figure out what. Maybe BalusC is correct that it has something to do with ajax, but I don't see that either.

感谢大家的帮助.宜兰

我在 userPhoto 页面上添加了一个按钮,该按钮返回到 userInfo 页面.登录按钮是唯一一个在第一次按下时起作用的按钮.当我使用命令按钮在 userInfo 和 userPhoto 之间来回切换时,总是需要按 2 次.我会显示 userPhoto 的中心

I added a button on the userPhoto page which goes back to the userInfo page. The Login button is the only one which works one the first press. When I use the command buttons to switch back and forth between userInfo and userPhoto, it always takes 2 pushes. I will show the center of 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>

推荐答案

您遇到了一个非常具体的问题.您完全通过 ajax 而不是正常的同步请求进行导航,并且整个视图都被新视图替换.新视图中的表单不再具有视图状态,这确实与 JSF 问题 790.也无法在 update 中引用表单,因为这些表单不存在于同一视图中.

You've there a very specific problem. You're fully navigating by ajax instead of by a normal synchronous request and the whole view is replaced with the new view. The forms in the new view does not have the view state anymore which is indeed related to JSF issue 790. It's also not possible to reference the forms in the update of the <p:commandButton> as the forms does not exist in the same view.

毕竟,完全不推荐使用ajax导航.它使您的页面不可添加书签且不可搜索机器人索引.我建议替换所有形式的

After all, it's not recommendable to fully navigate by ajax. It makes your page non-bookmarkable and non-searchbotindexable. I suggest to replace all forms of

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

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

这将通过正常的同步请求进行导航,并将创建新视图,其中所有表单都将具有其视图状态.请注意, 不需要 ,如有必要,您可以省略它.

This will navigate by normal synchronous requests and will create new views wherein all forms will have their view state. Note that the <p:button> doesn't require a <h:form>, you can omit it if necessary.

与具体问题无关,我也建议将master.xhtml放在/WEB-INF文件夹中,以便最终用户可以永远不要通过在浏览器地址栏中输入/猜测其 URL 来请求它.另见哪个XHTML我需要将文件放在/WEB-INF 中,哪些不需要?

Unrelated to the concrete problem, I also suggest to put master.xhtml in the /WEB-INF folder so that the endusers can never request it by entering/guessing its URL in browser address bar. See also Which XHTML files do I need to put in /WEB-INF and which not?

这篇关于连续按下按钮两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆