JSF CommandButton操作未被调用 [英] JSF CommandButton action not invoked

查看:115
本文介绍了JSF CommandButton操作未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是没有调用JSF CommandButton操作。
我有一个托管bean roleController,如

I'm having a problem with JSF CommandButton action not being invoked. I have a managed bean roleController, as in

@ManagedBean(name = "roleController")
@RequestScoped
public class RoleController {
        public Role getSelectedRole() {
    return selectedRole;
}

public void updateSelectedRole() {
    System.out.println(selectedRole.getRole());
}

在我的.jsf文件中我试图在h上编辑调用updateSelectedRole动作:commandButton,但它似乎不起作用。我试图将方法名称更改为不正确的名称,并且没有抛出异常 - 但是当我对其他表单执行相同操作时,抛出异常 - 因此很可能甚至不会调用该操作。

In my .jsf file I'm trying to edit invoke updateSelectedRole action on h:commandButton, but it doesn't seem to work. I've tried to change the method name to incorrect one, and there's no exception thrown - but when I do the same with other form, the exception is thrown - so most likely the action isn't even invoked.

<h:panelGroup rendered="${param.action == 'edit'}">
    <h:form>
        <ol>
            <li>
                <label for="ID">
                    <h:outputText value="#{msg.roleEditID}" />
                </label>
                <h:inputText readonly="true" 
                    value="#{roleController.selectedRole.id}" />
            </li>
            <li>
                <label for="Role">
                    <h:outputText value="#{msg.roleEditRole}" />
                </label>
                <h:inputText value="#{roleController.selectedRole.role}" />
            </li>
            <li>
                <h:commandButton value="#{msg.buttonUpdate}" 
                    action="#{roleController.updateSelectedRole()}"/>
            </li>
        </ol>
    </h:form>
</h:panelGroup>

我发现它可能是嵌套表格引起的,但在本例中并非如此。这个问题的根源是否可能是我的导航规则?

I found that it may be caused be nested forms, but that's not the case in this example. Is it possible that the root of this problem is my navigation rule?

<navigation-rule>
    <from-view-id>/admin/roles.xhtml</from-view-id>
    <navigation-case>
        <to-view-id>/admin/roles.xhtml</to-view-id>
        <from-outcome>true</from-outcome>
        <redirect>
            <view-param>
                <name>action</name>
                <value>edit</value>
            </view-param>
        </redirect>
    </navigation-case>
</navigation-rule>


推荐答案

未调用该操作,因为命令按钮组件未呈现。

The action is not been invoked, because the command button component is not rendered.

在处理表单提交期间,呈现=$ {param.action =='edit'}<已重新评估父面板组组件上的/ code>(作为防止被篡改/被黑客入侵的请求的保护)。但是,由于您显然没有在回发中保留该请求参数(至少,代码中没有任何内容证明),它的计算结果为 false 。因此,不呈现父面板组组件,包括其所有儿童。

During processing of the form submit, the rendered="${param.action == 'edit'}" on the parent panel group component is been re-evaluated (as safeguard against tampered/hacked requests). However, as you're apparently not retaining that request parameter in the postback (at least, nothing in the code proves otherwise), it evaluates to false. And thus the parent panel group component is not rendered, including all of its childen.

您需要确保呈现属性及其所有父组件的计算结果为 true 。在这种特殊情况下,您可以通过在命令按钮本身中包含< f:param> 来保留请求参数来实现这一点。

You need to make sure that the rendered attribute of the command button and all of its parent components evaluates to true during the form submit. In this particular case you can achieve that by retaining the request parameter by including a <f:param> in the command button itself.

<h:commandButton ...>
    <f:param name="action" value="#{param.action}" />
</h:commandButton>



参见:




  • 未调用commandButton / commandLink / ajax操作/侦听器方法或输入值未更新 - 第5点适用于您

  • See also:

    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated - Point 5 applies to you
    • 无关具体问题,建议禁止在JSF中使用 $ {} ,否则会导致不必要的混淆和问题。只需坚持#{}

      Unrelated to the concrete problem, it's recommend to ban the usage of ${} in JSF as it would otherwise lead to unnecessary confusion and questions. Just stick to #{} all the time.

      这篇关于JSF CommandButton操作未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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