selectBooleanCheckBox在p:对话框中不起作用

时间:2013-04-07 06:21:05

标签: jsf jsf-2 primefaces

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

第一个问题是当p:对话框出现时我无法单独选择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:对话框调用

                                                <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>

1 个答案:

答案 0 :(得分:0)

你的标记有点可怕,我不明白为什么你在<p:selectOneButton(所有<tr>)中有这么多东西所以不要试图纠正一切,因为我开始明白你想要达到的目标我会给你一个有效的例子。

Sample.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;
    }
}

view.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>

正如您所看到的,我正在存储currentSamplesampleBean 必须@ViewScoped),这有助于我使用正确的当前内容呈现自定义对话框信息。

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

如果您不清楚某些事情,请随时发表评论!