首页 \ 问答 \ Primefaces数据表项选择,确认对话框和RequestContext(Primefaces Datatable item selection, confirmation dialog and RequestContext)

Primefaces数据表项选择,确认对话框和RequestContext(Primefaces Datatable item selection, confirmation dialog and RequestContext)

编辑:在构建视图时,在@PostContsruct init() - 该视图的支持bean类的方法中尝试填充集合后,一切正常。 它是@ViewScoped。 所以问题在于组件以某种方式不能识别用作数据表值的集合,实际上具有值,因为它以不常见的方式填充。 无论如何,如果我在视图构建时填充集合,一切都很完美。 但当然这不是解决方案,因为必须在提到的模糊ajax事件上填充集合。 所以这是一种生命周期/范围问题。

EDIT2:我试图将表格添加到与其中具有ajax模糊效果的组件相同的表单中,在弹出窗口中显示弹出窗口和数据表并填充集合。 这也有效。 所以,不知何故,ajax模糊事件和数据表功能的生命周期/范围不同,因为它们的格式不同。 现在我应该以某种方式设法将它们保持在同一范围内,同时在弹出对话框中具有数据表。 现在,数据表笨拙地以相同的形式驻留在上述测试目的中。

我在p:confirmDialog有一个Primefaces p:dataTable ,当我选择一个项目时,该项目的setter只获得null值。 因此设置了null值,并且以下操作显然不起作用,因为我们没有要使用的值。

我认为问题与我必须使用RequestContext来显示对话框有关。 这是因为在窗体的blur事件中检查集合时应显示该对话框。

首先,从InputText检查blur事件:

<p:inputText id="customerIdInput"
             value="#{newCustomerCaseController.id}"
             label="custId" required="true">
    <f:ajax event="blur" listener="#{newCustomerCaseController.performBackgroundSearch}" />
</p:inputText>

然后,在该blur事件上,将在辅助bean中调用一个侦听器方法,该方法通过RequestContext显示一个对话框,如下所示:

public void performBackgroundSearch() {
    showPopUpBecauseCertainConditionsAreMet();
}

public void showPopUpBecauseCertainConditionsAreMet() {

    setExistingCustomerCases(customerCaseService.searchByEmployerId(employerId));
    RequestContext.getCurrentInstance().update("caseform");
    RequestContext.getCurrentInstance().execute(
            "PF('employerAlreadyHasCustomerCasesDialog').show()");
    }
}

这是xhtml中的确认对话框和表格:

<p:confirmDialog widgetVar="employerAlreadyHasCustomerCasesDialog" width="500" appendTo="@(body)" showEffect="fade" hideEffect="fade"
                 closable="false" >
<h:form id="caseform">
        <p:dataTable id="casetable"  var="custcase" rowKey="#{custcase.caseId}" value="#{newCustomerCaseController.existingCustomerCases}"
                     selectionMode="single" selection="#{newCustomerCaseController.selectedAlreadyExistingCustomerCase}" >
            <p:ajax event="rowSelect" process="@this" listener="#{newCustomerCaseController.onExistingCaseRowSelect()}" />
            <p:column headerText="caseId">
                <h:outputText value="#{custcase.caseId}" />
            </p:column>
        </p:dataTable>
</h:form>
<!--some unimportant buttons which we don't touch in this example-->
</p:confirmDialog>

最后,让我们看看onExistingCaseRowSelect侦听器方法的作用。 它只尝试重定向,就像使用我们尝试在p:dataTable选择的customerCasecaseId导航到不同的url一样。

public void onExistingCaseRowSelect(SelectEvent event) {
    try {
        facesContext.getExternalContext().redirect("/customercase.xhtml?caseId=" + selectedAlreadyExistingCustomerCase.getCaseId());
    }catch (Exception e) {
    }
}

这里的问题是,当在表中单击时, selectedAlreadyExistingCustomerCase不会在辅助bean中设置。 单击表中的行时,将设置null 我在getter和setter中用printlines检查过这个。 我认为这里的问题是由于通过RequestContext.getCurrentInstance().update("componentName");视图而发生了一些事情RequestContext.getCurrentInstance().update("componentName");

如何将表中单击的行值 - 一个customerCase - 设置为辅助bean中的选定值,而不是null


EDIT: Everything worked after I tried to populate the collection when the view is constructed, in the @PostContsruct init()-method of that view's backing bean class. It is @ViewScoped. So the problem lies in that the component somehow doesn't recognize the collection that is used as a value of the datatable, actually having values because it is populated in an uncommon way. Anyway, everything works perfectly if I populate the collection when the view builds. But of course that's not a solution because the collection must be populated on that mentioned blur ajax event. So it's some kind of a lifecycle / scope problem.

EDIT2: I tried to add the table to the same form as the component that has ajax blur effect in it, showing the popup and the datatable in that popup and populating the collection. That worked too. So, somehow the lifecycle / scope was different in that ajax blur event and the datatable functionality since they were in different forms. Now I should somehow manage to keep them in the same scope while having the datatable in the popup dialog. Now the datatable clumsily resides in the same form for aforementioned testing purposes.

I have a Primefaces p:dataTable in a p:confirmDialog and when I select an item, the setter of that item just gets null value. So a null value is set and the following operation obviously doesn't work because we don't have a value to work with.

I think the problem has something to do with me having to use RequestContext to show the dialog. This is because the dialog should be shown when a collection is checked in a blur event of a form.

First, a blur event is checked from a InputText:

<p:inputText id="customerIdInput"
             value="#{newCustomerCaseController.id}"
             label="custId" required="true">
    <f:ajax event="blur" listener="#{newCustomerCaseController.performBackgroundSearch}" />
</p:inputText>

Then, on that blur event a listener method will be called in the backing bean, which shows a dialog via RequestContext as follows:

public void performBackgroundSearch() {
    showPopUpBecauseCertainConditionsAreMet();
}

public void showPopUpBecauseCertainConditionsAreMet() {

    setExistingCustomerCases(customerCaseService.searchByEmployerId(employerId));
    RequestContext.getCurrentInstance().update("caseform");
    RequestContext.getCurrentInstance().execute(
            "PF('employerAlreadyHasCustomerCasesDialog').show()");
    }
}

Here's the confirm dialog and table in xhtml:

<p:confirmDialog widgetVar="employerAlreadyHasCustomerCasesDialog" width="500" appendTo="@(body)" showEffect="fade" hideEffect="fade"
                 closable="false" >
<h:form id="caseform">
        <p:dataTable id="casetable"  var="custcase" rowKey="#{custcase.caseId}" value="#{newCustomerCaseController.existingCustomerCases}"
                     selectionMode="single" selection="#{newCustomerCaseController.selectedAlreadyExistingCustomerCase}" >
            <p:ajax event="rowSelect" process="@this" listener="#{newCustomerCaseController.onExistingCaseRowSelect()}" />
            <p:column headerText="caseId">
                <h:outputText value="#{custcase.caseId}" />
            </p:column>
        </p:dataTable>
</h:form>
<!--some unimportant buttons which we don't touch in this example-->
</p:confirmDialog>

Lastly, let's see what the onExistingCaseRowSelect listener method does. It only tries to redirect, as in navigate to different url using the caseId of that customerCase that we try to select in the p:dataTable.

public void onExistingCaseRowSelect(SelectEvent event) {
    try {
        facesContext.getExternalContext().redirect("/customercase.xhtml?caseId=" + selectedAlreadyExistingCustomerCase.getCaseId());
    }catch (Exception e) {
    }
}

The problem here is that the selectedAlreadyExistingCustomerCase doesn't get set in the backing bean when it is clicked in the table. A null is being set when I click the row in the table. I've checked this with printlines in getter and setter. I think the problem here is that something happens because of the update of the view via RequestContext.getCurrentInstance().update("componentName");

How can I get the clicked row value in the table - a customerCase that is - to be set as the selected value in the backing bean, instead of a null?


原文:https://stackoverflow.com/questions/39330729
更新时间:2020-01-19 22:54

最满意答案

您需要在Where-Object scriptblock中添加另一个条件,因为您无法使用LDAP-Query AFAIK过滤空值。 一个建议:

Get-ADUser -Filter * -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { $_.Enabled -notlike "FALSE" -and [string]::IsNullOrEmpty($_.Description.Trim()) } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"

我个人也会将启用检查移动到Get-ADUser的过滤器以加快速度。 现在DC只会向您启用已启用的用户而不是所有用户。 尝试:

Get-ADUser -Filter { Enabled -eq $true } -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { [string]::IsNullOrEmpty($_.Description.Trim()) } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"

You need to add another condition in your Where-Object scriptblock since you can't filter empty values with an LDAP-Query AFAIK. One suggestion:

Get-ADUser -Filter * -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { $_.Enabled -notlike "FALSE" -and [string]::IsNullOrEmpty($_.Description.Trim()) } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"

Personally I would also move the enabled-check into a filter in Get-ADUser to speed things up. Now the DC will only send you enabled users instead of all users. Try:

Get-ADUser -Filter { Enabled -eq $true } -Properties Name,SamAccountName,Description -SearchBase "DC=REMOVED,DC=com" |
? { [string]::IsNullOrEmpty($_.Description.Trim()) } |
Select Name,SamAccountName,Description |
Export-Csv "C:\scripts\NoDescriptionUsers.csv"

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)