CommandButton操作在加载时自动执行多次

时间:2012-09-10 15:18:22

标签: jsf primefaces

我正在编写一个JSF页面,但是,一个命令按钮在页面加载时多次调用它的动作,但是没有人点击它...这搞乱了我的整个进度......

HTML:

<h:panelGrid columns="2" cellpadding="10">  
<h:form>
    <table>
        <tr>
            <td>姓名:</td>
            <td><p:inplace editor="true"><p:inputText value="#{user.name}"/></p:inplace></td>
        </tr>
        <tr>
            <td>联系方式:</td>
            <td><p:inplace editor="true"><p:inputText value="#{user.phone}"/></p:inplace></td>
        </tr>
        <tr>
            <td>性别:</td>
            <td><h:outputText value="#{user.gender}"/></td>
        </tr>
        <tr>
            <td>身份证号:</td>
            <td><p:inplace editor="true"><p:inputText value="#{user.pid}"/></p:inplace></td>
        </tr>
        <tr>
            <td style="position:absolute; right:30px;"><p:commandButton value="删除" action="#{info.removeUser()}"/></td>
        </tr>
    </table>

</h:form>

的java:

public void removeUser(){
    System.out.println("Current tab:"+index +" Removed............");
    users.remove(Integer.parseInt(index));
}

这里“index”是accordionPanel中的当前选项卡,它是一个String ...

这里有时间问问题,也许我省略了一些信息...

1 个答案:

答案 0 :(得分:1)

如果您忘记在视图中声明p XML namespage,就会发生这种情况。

xmlns:p="http://primefaces.org/ui"

如果您忘记声明p XML命名空间,则所有p:xxx标记都将被视为纯文本。属性中的所有EL表达式都会立即执行,就像它们嵌入纯文本一样。这还包括#{info.removeUser()}表达式。 “很多次”很可能与EL表达式在视图中出现的数量相同。

相关问题