【问题标题】:selectBooleanCheckBox does not work seperatly in p:dialogselectBooleanCheckBox 在 p:dialog 中不能单独工作
【发布时间】:2023-04-03 09:57:01
【问题描述】:

我有一个按钮,当我单击它时,会出现对话框,在该对话框中,我有 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>

【问题讨论】:

  • but it does not disappear and it shows permanently 是什么意思,您说的是一直显示的对话框吗?你必须在某个时候调用 dlg.hide() 来隐藏它。
  • @Alexandre:谢谢。是的,我使用“oncomplete="dlg.hide()”,第二个问题解决了。但第一个问题仍然存在:(
  • 那么dialog到底隐藏了吗?顺便说一句,如果验证失败,您的对话框将隐藏,因为它只等待 ajax 请求完成。
  • 是的,对话框现在隐藏。但我仍然不能单独选择 p:selectBooleanCheckBox。当我想选择其中一个时,所有这些都被选中。
  • 请显示触发对话框打开的facelets的相关部分,加上循环的父元素(&lt;p:dataTable&lt;ui:repeat...)最多简化

标签: jsf jsf-2 primefaces


【解决方案1】:

你的标记有点吓人,我不明白为什么你的&lt;p:selectOneButton(所有&lt;tr&gt;)中有这么多东西,所以当我开始理解什么时,我没有尝试纠正所有内容你努力实现我会给你一个工作的例子。

示例.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),这有助于我使用正确的当前信息呈现自定义对话框。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2014-10-31
    相关资源
    最近更新 更多