命令按钮在第二次推送(jsf)时调用操作 [英] Command buttons invokes actions on second push (jsf)

查看:100
本文介绍了命令按钮在第二次推送(jsf)时调用操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了我的应用程序的奇怪行为.命令按钮开始在第二次点击时调用动作.首先-没有任何反应.它对火狐和铬有影响,但在顿悟中照常工作.

I came to strange behaviour of my application. Command buttons start to invoke actions on second hit. On first - nothing happens. It takes effect on firefox and chromium, but in epiphany works as usual.

我的环境: -Ubuntu 11.04 -玻璃鱼3.1.1 -jsf 2.X -Primefaces 3.2 -Firefox 12.0 -主显节2.30.6

My environment: - ubuntu 11.04 - glassfish 3.1.1 - jsf 2.X - primefaces 3.2 - firefox 12.0 - epiphany 2.30.6

代码示例:

    <ui:define name="content">
       <h:form id="form">
            <h:panelGrid id="panelGrid" columns="3">

                <h:outputText value="#{msg.fieUserName}:"/>
                <h:inputText  id="name"  value="#{userBb.editedUser.username}" />
                <h:message    for="name" styleClass="error_msg"/>

                <h:outputText value="#{msg.fieUserDescription}:"/>
                <h:inputText  id="description"  value="#{userBb.editedUser.description}" />
                <h:message    for="description" styleClass="error_msg"/>

                <h:outputText   value="#{msg.fieUserPassword}:"/>
                <h:inputSecret  id="password" value="#{userBb.editedUser.password}" redisplay="true"/>
                <h:message      for="password" styleClass="error_msg"/>

                <h:outputText value="#{msg.fieUserRights}:"/>
                <p:selectOneMenu id=       "rights"
                                 value=    "#{userBb.editedUserGroup}"
                                 converter="#{pGroupOfUsersConverter}">
                    <f:selectItems
                        value    ="#{groupDao.findAll()}"
                        var      ="row"
                        itemLabel="#{groupDao.rightsDescription(row.id)}"
                        itemValue="#{row.groupname}" 
                        >
                    </f:selectItems>
                </p:selectOneMenu>
                <h:message for="rights" styleClass="error_msg"/>

                <h:outputText value="#{msg.fiePorofolioName}:" rendered="#{userBb.chosenNew}"/>
                <h:inputText  id="portName" value="#{userBb.portfelForNewUser.nazwa}" rendered="#{userBb.chosenNew}">
                    <f:validateBean disabled="true" />
                </h:inputText>
                <h:message for="portName" styleClass="error_msg" rendered="#{userBb.chosenNew}"/>

                <h:outputText    value="#{msg.fiePotofolioCurrency}:" rendered="#{userBb.chosenNew}"/>
                <p:selectOneMenu id=       "waldep" 
                                 value=    "#{userBb.portfelForNewUser.walutaDepozytowa}"
                                 converter="#{igConverter}"
                                 rendered= "#{userBb.chosenNew}"
                                 >
                   <f:selectItems value=    "#{igDao.waluty}" 
                                  var=      "row"
                                  itemLabel="#{row.nazwa}"/>
                </p:selectOneMenu>
                <h:message for="waldep" styleClass="error_msg" rendered="#{userBb.chosenNew}"/>

            </h:panelGrid>
            <h:panelGrid columns="2">
               <h:commandButton value="#{msg.butCreate}" action="#{userBb.formCreate()}" rendered="#{userBb.chosenNew}" />
               <h:commandButton value="#{msg.butSave}"   action="#{userBb.formEdit()}"   rendered="#{!userBb.chosenNew}"/>
               <h:commandButton value="#{msg.butBack}"   action="#{userBb.formBack()}"/>
            </h:panelGrid>
        </h:form>
    </ui:define>

在此示例中,尽管按钮可见,但仅在第二次单击命令按钮时才调用userBb.formCreate()方法.如果没有正确填写字段,则旁边会显示相应的消息,但是……仅在第二次单击时!有什么建议吗?

In this example method userBb.formCreate() is invoked only on second click on command button although button is visible. When fields are not properly filled up than appropriate messages appear next to them, but... only on second click! Any advice?

我从以下位置查看要点:此建议,但未找到解决方案.

I check out points from: this advice, but not found solution.

推荐答案

好,我发现了问题所在.所以:

Ok, I found what was wrong. So:

问题的出现: 我有一个用于用户数据的页面.一些输入项和命令按钮.单击创建"按钮时,将签出输入数据.如果数据正常,将创建用户并显示用户表,或者在出现错误时-显示错误消息,并且用户停留在同一页面上:

Appearance of the problem: I've got a page for user data. Some input items and command buttons. When clicking "Create" button, input data is checked out. If data is ok user is created and table of users appears, or when there are errors - errors messages appear and user stays on the same page:

我发现了一些不稳定的行为.第一次单击(动作)没有任何反应,只有第二个和后续动作才有效.但.这种行为与我使用的Web浏览器相关.

I found some erratic behavior. Nothing has happened on first click (action), only second and subsequent actions have an effect. But. This behavior was related to kind of web browser I use.

所有操作均从首次点击开始,在网络浏览器中:主显节和konqueror.尽管在火狐和铬中,我观察到了我上面描述的这种不稳定行为.命令按钮的代码为:

All actions takes place from the first click, in webrowsers: epiphany and konqueror. Although in firefox and chromium I observed this erratic behavior which I described above. Code for a command button was:

<h:commandButton value="#{msg.butCreate}" action="#{userBb.formCreate()}" rendered="#{userBb.chosenNew}"/>

不同浏览器中的不同行为.

Different behaviors in different webbrowsers.

原因. @Balusc在他的注释中列举了原因,我大致是第一次阅读.确实是pt. 7.

The cause. The cause was enumerated by @Balusc in his note, which I read roughly first time. It was indeed pt. 7.

解决方案. 我试图通过这种方式更改按钮声明:

The solution. I've tried to change button declaration this way:

<h:commandButton value="#{msg.butCreate}" action="#{userBb.formCreate()}" rendered="#{userBb.chosenNew}">
   <f:ajax render="userForm"/>
</h:commandButton> 

其中userForm是h:form的正确ID.没有结果,仍然只有第二次和之后的点击才会生效-显示错误消息.

where userForm was proper id of h:form. No result, still only second and subsequent clicks has an effect - shows error messages.

因此,我从上一页更改了声明命令按钮,该按钮调用了不稳定的行为页面.最初是:

So I changed declaration command button from previous page, that invoked erratic behavior page. Originally it was:

<p:commandButton value="#{msg.butNew}"    action="#{userBb.actionNew()}"/>

primefaces命令按钮.就是这样,就像Balusc写道:如果预先通过ajax请求渲染/更新了带有UICommand按钮的父级,那么第一个操作将始终失败."

primefaces command button. And that was it, as Balusc wrote: "If a parent of the with the UICommand button is been rendered/updated by an ajax request beforehand, then the first action will always fail."

所以我将声明更改为:

<p:commandButton value="#{msg.butNew}"    action="#{userBb.actionNew()}" ajax="false"/>

就是这样.第一步,它在任何浏览器中都可以正常工作.

And that's it. It works fine in any browser, for the first action.

这篇关于命令按钮在第二次推送(jsf)时调用操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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