在JSF中不调用action方法

gek*_*ish 8 jsf

这是我的阶段监听器

public class AdminPhaseListener implements PhaseListener {

private static final long serialVersionUID = -1161541721597667238L;

    public void afterPhase(PhaseEvent e) {
        System.out.println("after Phase " + e.getPhaseId());
    }

    public void beforePhase(PhaseEvent e) {
        System.out.println("before Phase " + e.getPhaseId());
        if(e.getPhaseId()== PhaseId.RESTORE_VIEW)
        {

        }

    }

    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }
}
Run Code Online (Sandbox Code Playgroud)

单击我页面中的命令按钮,我调用一个动作方法并进行一些处理,但是根本没有调用动作方法,但是在服务器日志中,我可以看到我的PhaseListener为所有阶段打印的消息.

如果我的视图没有改变,它会在RESTORE_VIEW阶段之后停止吗?

有什么想法吗?

添加如何显示命令按钮的代码:

<table width="100%">
    <h:column rendered="#{adminBean.displayResultsSize > 0}">

        <tr>
            <td colspan="14" height="5" nowrap="nowrap" class="WhiteRow"></td>
        </tr>
        <tr>
            <td colspan="14" height="1" nowrap="nowrap" align="center"
                bgcolor="#999999"></td>

        </tr>
        <h:inputHidden  id="removeUserId" value="#{adminBean.removeUserId}"/>
        <h:inputHidden  id="removeIBD" value="#{adminBean.removeIBD}"/>
        <h:inputHidden  id="removeAPA" value="#{adminBean.removeAPA}"/>
        <tr>
            <td colspan="14" height="30" nowrap="nowrap"
                class="FilterColumnGrayHeader" align="center">&nbsp;&nbsp;&nbsp;
            <input type="button" disabled="disabled" id="button_edit"
                value="Edit Details" class="disabledfield"
                onclick="populateEditRow();">
            </input> <h:commandButton type="submit" class="disabledfield" immediate="true"
                id="button_remove" value="Remove" onclick="populateRemoveRow();" action="#{adminBean.remove}">
            </h:commandButton> &#160;

            </td>
        </tr>
        <tr bgcolor="#000000">
            <td colspan="14" height="1" nowrap="nowrap" align="center"
                bgcolor="#999999"></td>
        </tr>
        <tr>
            <td height="10"></td>
        </tr>
    </h:column>
</table>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 35

我引用这个答案:

只要UICommand组件无法调用关联的操作,请验证以下内容:

  1. UICommand组件必须放在UIForm组件内(例如h:form).
  2. 您不能将多个组件嵌套UIForm在一起(注意包含文件!).
  3. 不应该发生验证/转换错误(用于h:messages获取所有错误).
  4. 如果UICommand部件被放置在内部UIData部件中,确保完全一样的DataModel(在后面的对象UIDatavalue属性)被保留.
  5. rendereddisabled组件的属性,并且父组件的所有不应该求false期间应用请求值阶段.
  6. 确保请求 - 响应链中没有PhaseListener或任何EventListener已更改JSF生命周期以跳过调用操作阶段.
  7. 确保没有FilterServlet在同一个请求 - 响应链中FacesServlet以某种方式阻止了请求.

另一个原因可能是您没有运行您认为正在运行的代码.


Boz*_*zho 6

这通常意味着页面上存在验证错误.尝试设置immediate="true"以克服错误,或用于<h:messages>显示出现的错误.