Primefaces数据表项选择,确认对话框和RequestContext(Primefaces Datatable item selection, confirmation dialog and RequestContext)
编辑:在构建视图时,在@PostContsruct init() - 该视图的支持bean类的方法中尝试填充集合后,一切正常。 它是@ViewScoped。 所以问题在于组件以某种方式不能识别用作数据表值的集合,实际上具有值,因为它以不常见的方式填充。 无论如何,如果我在视图构建时填充集合,一切都很完美。 但当然这不是解决方案,因为必须在提到的模糊ajax事件上填充集合。 所以这是一种生命周期/范围问题。
EDIT2:我试图将表格添加到与其中具有ajax模糊效果的组件相同的表单中,在弹出窗口中显示弹出窗口和数据表并填充集合。 这也有效。 所以,不知何故,ajax模糊事件和数据表功能的生命周期/范围不同,因为它们的格式不同。 现在我应该以某种方式设法将它们保持在同一范围内,同时在弹出对话框中具有数据表。 现在,数据表笨拙地以相同的形式驻留在上述测试目的中。
我在
p:confirmDialog
有一个Primefacesp: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
选择的customerCase
的caseId
导航到不同的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 ap:confirmDialog
and when I select an item, the setter of that item just getsnull
value. So anull
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 ablur
event of aform
.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 viaRequestContext
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 thecaseId
of thatcustomerCase
that we try to select in thep: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. Anull
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 viaRequestContext.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 anull
?
原文:https://stackoverflow.com/questions/39330729
最满意答案
您需要在
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"
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
安全选择 replace后的规范dropna df.replace({'XNGS': {'': np.nan}}).dropna(subset=['XNGS']) date XNGS BBG FX 0 16/11/2007 19.414648 0.6819 19.414648 1 19/11/2007 19.340593 0.6819 19.340593 2 20/11/2007 19.490805 0.6739 19.4908 ...
-
查找表中的特定条目会导致列未找到异常(Finding specific entry in the table causes Column not found exception)[2024-02-08]
我不确定,因为我不是Java开发人员,但不应该是: Cursor c = sqlDB.query(DB_TABLE_NAME, dbCols, DB_EMAIL_COL + "='" + findEm + "'", null, null, null, null); I'm not sure especially as I'm no Java developer, but shouldn't it be : Cursor c = sqlDB.query(DB_TABLE_NAME, dbCols, DB_E ... -
如何从矩阵中选择具有特定列中唯一条目的行?(How to select rows from matrix with unique entry in specific column?)[2022-01-25]
这是一种方式: DeleteDuplicates[list, First@#1 === First@#2 &] 编辑 请注意,下面的时间和讨论基于M7 经过反思,我找到了一个解决方案,对于大型列表来说,(至少)数量级会快一些,有时会快两个数量级(对于这种特殊情况,可能更好的方法就是下面的解决方案)会有不同的计算复杂度): Clear[delDupBy]; delDupBy[nested_List, n_Integer] := Module[{parts = nested[[All, n]], ord, ... -
或者,您可以将ISNULL或COALESCE Null设置为相同的''和组相同: Select Name, ISNULL(emergencyContact, ' ') AS emergencyContact FROM employeeDatabase Group By Name, ISNULL(emergencyContact, ' '); Alternatively, you can ISNULL or COALESCE Nulls to the same ' ' and group by same: ...
-
您需要在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 top 10 * from Shipping_Bill a join (select sb_number from Shipping_Bill group by SB_Number having count(*) > 1) b on a.SB_Number = b.SB_Number 请尝试此查询。 它会帮助你。 select top 10 * from Shipping_Bill a join (select sb_number ...
-
我认为您需要反转排序顺序,以便您按反向启动时间排序。 另外,我不确定你的排除应该做什么。 你想得到的东西比当前项目少 ,所以删除那个排除似乎更合理,只使用__lt而不是__lte 。 former_entries = Entry.objects.all().filter(start__lt=entry.start, customer=customer).order_by('-start')[:3] I think you need to reverse the sort order, so that yo ...
-
如果构建组,则可以使用聚合函数max()来获取每个组的最高值 select t1.* from btB t1 join ( SELECT max(bID) as bID, beitragID FROM btB WHERE beitragID in (1013, 1213) group by beitragID ) t2 on t1.bid = t2.bid and t1.beitragID = t2.beitragID If you build a group you can ...