0

我有按钮,当我单击它时,会出现对话框,在该对话框中,我有p:selectBooleanCheckBoxh:outputlable

第一个问题是当 p:dialog 出现时我不能p:selectBooleanCheckBox单独选择。这意味着当我点击其中一个时,全部p:selectBooleanCheckBox 选择。

p:commandButton第二个问题是当我在对话框中单击时,actionListener工作但它不会消失并且它会永久显示。我认为问题是由 Ajax 引起的。你能告诉我如何解决这个问题吗?

              <h:panelGrid>
                <p:dialog  appendToBody="true"  header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg">  
                        <h:panelGrid columns="1" id="display">  
                            <p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.filterBusinessRequest()}"
                                        columns="1" >
                                <tr>
                                    <td>
                                        <p:selectBooleanCheckbox/>
                                    </td>
                                    <td>
                                        <h:outputLabel value="test"/>
                                    </td>
                                </tr>
                            </p:dataGrid>
                        <p:commandButton  id="acceptCommonButton" value="#{inviteRequest_msg.accept}"  
                                          actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}" 
                                          update="display" />
                        </h:panelGrid> 


                </p:dialog>
            </h:panelGrid>

            <table style="width: 100%" id="tabell">
                <p:selectOneButton  value="#{inviteRequestManagedBean.filterType}">  
                    <f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" />  
                    <f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />   
                    <f:ajax event="change"  execute="@form" render="@form" />             
                    <tr>
                        <td>
                            <p:panel></p:panel>

                            <p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo" 
                                        value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" >

                                <p:column>
                                    <div>
                                        <table border="0"  width="100%">
                                            <tr>
                                                <td>
                                                    <p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/>
                                                </td>
                                                <td>
                                                    <div>
                                                        <table border="0" width="100%">
                                                            <tr>
                                                                <td>
                                                                    <h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                </td>    

这是 p:dialog 调用的地方

                                                <td>

                         <p:commandButton  id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
                                                                      onclick="dlg.show()" />
                                                </td>


                                                <td>
                                                    <p:commandButton  id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"  
                                                                      actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}" 
                                                                      update="@form" />
                                                </td>
                                                <p:blockUI block="acceptCommonButton" trigger="acceptCommonButton"/>
                                                <p:blockUI block="noNowCommonButton" trigger="acceptCommonButton"/>
                                                <p:blockUI block="acceptCommonButton" trigger="noNowCommonButton"/>
                                                <p:blockUI block="noNowCommonButton" trigger="noNowCommonButton"/>

                                                <td>
                                                    <p:panel>
                                                        <p:ajaxStatus>
                                                            <f:facet name="start">
                                                                <p:graphicImage value="../resources/img/loading.gif"/>
                                                            </f:facet>
                                                            <f:facet name="complete">
                                                                <h:outputLabel value=""/>
                                                            </f:facet>
                                                        </p:ajaxStatus>
                                                    </p:panel>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <hr/>
                                </p:column>
                            </p:dataGrid>                   
                        </td>
                    </tr>
                </p:selectOneButton>

            </table>

    </h:panelGrid>
    <h:panelGrid>
        <p:dialog  appendToBody="true"  header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg">  
                <h:panelGrid columns="1" id="display">  
                    <p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.loadPartyRelationShipType()}"
                                columns="1" >
                        <tr>
                            <td>
                                <p:selectBooleanCheckbox/>
                            </td>
                            <td>
                                <h:outputLabel value="test"/>
                            </td>
                        </tr>
                    </p:dataGrid>
                 <p:commandButton  id="acceptCommonButton" value="#{inviteRequest_msg.accept}"  
                                  actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}" 
                                  update="display" oncomplete="dlg.hide()"  />

                </h:panelGrid> 

        </p:dialog>
    </h:panelGrid>
</ui:composition>
4

1 回答 1

0

你的标记有点吓人,我不明白为什么你的<p:selectOneButton(所有的<tr>)里有这么多东西,所以当我开始理解你试图实现的目标时,我不会试图纠正一切,我会给你一个工作的例子。

示例.java

public class Sample implements Serializable {

    private String name;

    private boolean checked;

    public Sample() {
    }

    public Sample(String name, boolean checked) {
        this.name = name;
        this.checked = checked;
    }

    // Getter and Setter for name and checked omitted
}

SampleBean.java

@ManagedBean
@ViewScoped
public class SampleBean implements Serializable {

    private List<Sample> samples;

    private Sample currentSample;

    public void prepareEdit(Sample sample) {
        this.currentSample = sample;
    }

    public void edit() {
        // Do what you need to do with sample
        // You can get it with : this.currentSample
        RequestContext.getCurrentInstance().execute("dlg.hide()");
    }

    public List<Sample> getSamples() {
        if (this.samples == null) {
            this.samples = new ArrayList<Sample>();

            for (int i = 1; i <= 10; ++i) {
                this.samples.add(new Sample("Sample n°" + i, (i % 3 == 0)));
            }
        }
        return samples;
    }

    public void setSamples(List<Sample> samples) {
        this.samples = samples;
    }

    public Sample getCurrentSample() {
        return currentSample;
    }

    public void setCurrentSample(Sample currentSample) {
        this.currentSample = currentSample;
    }
}

视图.xhtml:

<h:form id="myForm">
    <p:dataTable value="#{sampleBean.samples}" var="sample">
        <p:column headerText="Name">
            <h:outputText value="#{sample.name}" />
        </p:column>
        <p:column headerText="Checked?">
            <h:outputText value="#{sample.checked}" />
        </p:column>
        <p:column style="width: 1px; text-align: center;">
            <p:commandButton value="edit"
                             actionListener="#{sampleBean.prepareEdit(sample)}"
                             update=":dialog"
                             oncomplete="dlg.show()" />
        </p:column>
    </p:dataTable>
</h:form>
<p:dialog id="dialog" widgetVar="dlg" header="Editing">
    <h:form rendered="#{!empty sampleBean.currentSample}">
        <h:outputText value="Current sample is #{sampleBean.currentSample.name}" />
        <br />
        <p:selectBooleanCheckbox value="#{sampleBean.currentSample.checked}" />
        <br />
        <p style="width: 100%; text-align: center;">
            <p:commandButton actionListener="#{sampleBean.edit()}"
                             value="Edit"
                             update="@form :myForm" />
        </p>
    </h:form>
</p:dialog>

如您所见,我正在存储一个currentSample( sampleBean must be @ViewScoped),它可以帮助我使用正确的当前信息呈现自定义对话框。

我对您的绑定问题的最后评论<p:selectBooleanCheckbox很重要,因为只有当它基于上下文绑定到不同的端点时,您才能获得自定义复选框值(此处currentSample)。

如果您有不清楚的地方,请随时发表评论!

于 2013-04-07T11:47:19.143 回答