3

当用户在我的应用程序中单击时,我试图阻止页面刷新<h:commandLink>。我试过这个但它不起作用:

更新 :

 <h:dataTable value="#{person.IssueList}" var="p" >
    <h:column style="width: 20px">
        <f:facet name="header">Issue</f:facet>
        <h:commandLink value="#{p.IssueDesc}"/>
    </h:column>

    <h:column style="width: 20px">
         <f:facet name="header">Reporting Date</f:facet>
         <p:calendar  value="#{p.issuerepDt}" rendered="#{p.editable}"                 id="CalendarId"/>                
         <h:outputText value="#{p.issuerepDt}" rendered="#{not p.editable}" />
    </h:column>

    <h:column>
            <f:facet name="header">Action</f:facet>
        <h:commandLink  value="Edit" action="#{person.editAction(p)}">
            <f:ajax execute="@form" render="@none" />          
        </h:commandLink>    

            </h:column>
    </h:dataTable>

爪哇片段:

public void  editAction(PersonIssues pIssues) {
    pIssues.setEditable(true);
}

我正在使用从 MKyong.I编辑 jsf数据表的概念

4

2 回答 2

2

我会尝试使用listeneroff:ajax而不是actionof h:commandLink

<h:commandLink value="Edit">
    <f:ajax listener="#{person.editAction(p)}" execute="@form" render="dataTableId calendarId" />          
</h:commandLink>  

另外,请注意您要在 ajax 之后呈现的内容。

于 2012-09-28T14:59:25.530 回答
2

由于我看到您将 primefaces 用于日历组件,因此您可能还想使用 primefaces 命令按钮和数据表。primefaces 组件一起玩得很好。

从下面的示例中,您可以看到我为您的数据表提供了一个 ID,并且在 commandLink 上,我添加了一个更新属性以在调用操作后更新数据表。默认情况下,primefaces 有一个在 commandLinks 上设置为 true 的 ajax 属性。

<p:dataTable id="myTable" value="#{person.IssueList}" var="p" >
    <p:column style="width: 20px" headerText="Issue">
         <p:commandLink value="#{p.IssueDesc}"/>
    </p:column>

    <p:column style="width: 20px" headerText="Reporting Date">
         <p:calendar  value="#{p.issuerepDt}" rendered="#{p.editable}"                 id="CalendarId"/>                
         <h:outputText value="#{p.issuerepDt}" rendered="#{not p.editable}" />
    </p:column>

    <p:column headerText="Action">
         <p:commandLink  value="Edit" action="#{person.editAction(p)}" update="myTable"/>
    </p:column>
</p:dataTable>
于 2012-09-28T16:52:32.213 回答