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

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

问题描述

昨天我张贴了关于不必preSS一个按钮两次,得到它的工作的问题。我收到了很好的帮助,这是计算器的标志,但问题依然存在。我砍我的code到最低限度,但问题仍然存在。我仔细的阅读一个<一个href="http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183">BalusC建议,希望我可以找到一个表单内的表单。当然是有什么我可以看到,所以我会后我的code的希望,更多双眼睛将看到的东西。

我有我从欢迎(登录部分)调用模板。这正好USERINFO其中有一个命令按钮。这是命令按钮,我鬼使神差得preSS两次。关于第二个推命令按钮会带我去userPhoto。一切都下调到最小,这样我可以将它张贴。

master.xthml:

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;! - 
要改变这种模板,选择工具|模板
和打开,在编辑的模板。
 - &GT;
!&LT; D​​OCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&LT; HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
的xmlns:F =htt​​p://java.sun.com/jsf/core
的xmlns:UI =htt​​p://java.sun.com/jsf/facelets
的xmlns:H =htt​​p://java.sun.com/jsf/html
的xmlns:P =htt​​p://primefaces.org/ui&GT;
&LT; H:头&GT;
&LT;冠军&GT;主模板&LT; /标题&GT;
&LT; / H:头&GT;
&LT; H:身体GT;
&LT;电话号码:布局全页=真正的&GT;
    &LT;电话号码:layoutUnit位置=北大小=254&GT;
        最佳
    &LT; / P:layoutUnit&GT;

    &LT;电话号码:layoutUnit位置=东进大小=50调整大小=真正的&GT;
        您好
    &LT; / P:layoutUnit&GT;

    &LT;电话号码:layoutUnit位置=南方大小=30&GT;
        南
    &LT; / P:layoutUnit&GT;

    &LT;电话号码:layoutUnit位置=中心&GT;
        &LT; UI:插入NAME =一区&GT;默认文字&lt; / UI:插入&gt;
    &LT; / P:layoutUnit&GT;
&LT; / P:布局&GT;

&LT; / H:身体GT;
&LT; / HTML&GT;
 

welcome1.xhtml:

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;! - 
要改变这种模板,选择工具|模板
和打开,在编辑的模板。
 - &GT;
&LT;!DOCTYPE HTML&GT;
&LT; HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
的xmlns:UI =htt​​p://java.sun.com/jsf/facelets
的xmlns:H =htt​​p://java.sun.com/jsf/html
的xmlns:P =htt​​p://primefaces.org/ui&GT;
&LT;用户界面:作文模板=master.xhtml&GT;

    &LT; UI:定义名称=一区&GT;
        &LT; H:表格ID =Form1的&GT;
            &LT;电话号码:的commandButton类型=提交值=登陆行动=用户信息/&GT;
        &LT; /小时:形式GT;
        &LT;电话号码:信息/&GT;
    &LT; / UI:定义&GT;
&LT; / UI:组合物&gt;
&LT; / HTML&GT;
 

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

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;! - 
要改变这种模板,选择工具|模板
和打开,在编辑的模板。
 - &GT;
&LT;!DOCTYPE HTML&GT;
&LT; HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
的xmlns:UI =htt​​p://java.sun.com/jsf/facelets
的xmlns:H =htt​​p://java.sun.com/jsf/html
的xmlns:P =htt​​p://primefaces.org/ui&GT;
&LT;用户界面:作文模板=master.xhtml&GT;

    &LT; UI:定义名称=一区&GT;
        &LT; H:格式ID =formP&GT;
            &LT;电话号码:的commandButton类型=提交值=照片行动=userPhoto/&GT;
        &LT; /小时:形式GT;
        &LT;电话号码:信息/&GT;
    &LT; / UI:定义&GT;
&LT; / UI:组合物&gt;
&LT; / HTML&GT;
 

我看不出有任何形式的嵌套在任何其他形式,但什么是错的,我想不出什么。也许BalusC是正确的,它有事情做与阿贾克斯,但我没有看到,无论是。

感谢所有帮助。 宜兰

我添加了userPhoto页面,该页面返回到用户信息页面上的按钮。登录按钮是唯一一个作品一件第一preSS。当我使用命令按钮用户信息和userPhoto之间来回切换,它总是需要2推。我会告诉userPhoto中心

 &LT;用户界面:作文模板=master.xhtml&GT;
    &LT; UI:定义名称=一区&GT;
        &LT; H:格式ID =form3&GT;
            &LT;电话号码:的commandButton类型=提交值=主页行动=用户信息/&GT;
        &LT; /小时:形式GT;
        &LT;电话号码:信息/&GT;
    &LT; / UI:定义&GT;
&LT; / UI:组合物&gt;
 

解决方案

您已经有一个非常具体的问题。你被AJAX,而不是通过一个正常同步请求充分导航和整个视图被替换为新的图。在新视图的形式没有视图状态了这确实是关系到 JSF问题790 。它也不能引用表格中的更新&LT;电话号码:的commandButton&GT; 的形式不存在同样的观点。

毕竟,这不是值得推荐给阿贾克斯充分导航。它使你的页面不加入书签和非searchbotindexable。我建议,以取代所有形式的

 &LT;电话号码:的commandButton ...行动=otherViewId/&GT;
 

 &LT;电话号码:按钮......结果=otherViewId/&GT;
 

这将通过正常的同步请求导航,将创造新的观点,其中各种形式都会有自己的视图状态。请注意,&LT;电话号码:按钮&GT; 不需要&LT; H:形式GT; ,则可以省略如果需要的话它。


无关的具体问题,我建议把 master.xhtml / WEB-INF 文件夹,以便在最终用户永远不能要求它通过输入/猜测它在浏览器地址栏中的URL。另请参见<一个href="http://stackoverflow.com/questions/9031811/which-xhtml-files-do-i-need-to-put-in-web-inf-and-which-not">Which XHTML文件我需要在/ WEB-INF,哪些不是?

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.

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:

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

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.

Thanks for all the help. Ilan

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>

解决方案

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.

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" />

by

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


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?

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

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