p:commandButton在将其类型设置为submit时不起作用

时间:2014-10-31 13:50:39

标签: jsf primefaces jsf-2.2 commandbutton

我有一张表格。在表单中,我有一个数据表。您可以在下面找到我的代码:

<p:column headerText="Extra request">
    <p:commandButton id="requestDetailsButton" value="details" type="button"
                     update="detailPanel"
                     action="#{enbBean.sendEnbDetailsRequest(selectedEnbData.eNbAddress)}"
                     onclick="enbDetailsDialog.show()">

        <f:setPropertyActionListener id="rowSelected" value="a" target="#{enbBean.selectedEnbData}" />
    </p:commandButton>
</p:column>

问题是我需要使用type=submit设置命令按钮。但是当我这样做时,整个页面都会中断。为什么它会破裂,我怎么能克服这个问题?

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

<p:commandButton id="requestDetailsButton" value="details"
                 update="detailPanel"
                 action="#{enbBean.sendEnbDetailsRequest}"
                 oncomplete="enbDetailsDialog.show()">
    <f:setPropertyActionListener value="a" target="#{enbBean.selectedEnbData}" />
</p:commandButton>

public void sendEnbDetailsRequest() {
    ...
}   

setPropertyActionListener将在调用action之前设置#{enbBean.selectedEnbData}

或者您可以尝试这样的事情:

<p:commandButton id="requestDetailsButton" value="details"
                 update="detailPanel"
                 actionListener="#{enbBean.sendEnbDetailsRequest}"
                 oncomplete="enbDetailsDialog.show()">
    <f:attribute name="selectedEnbData" value="a"/>
</p:commandButton>

public void sendEnbDetailsRequest(ActionEvent ae) {
    String selectedEnbData = (String)ae.getComponent().getAttributes().get("selectedEnbData");
    ...
}