将参数从Primefaces表单传递到后端Bean

huangapple go评论48阅读模式
英文:

Pass parameter from Primefaces sheet to backing bean

问题

你想从PrimeFaces表格列传递参数到JSF后端bean,如下所示:

<pe:sheetcolumn headerText="HTS Chapter" value="#{material.htsChapter}" colWidth="100"
                rendered="true"
                colType="dropdown"
                readonlyCell="#{!itemActionsManagedBean.authCheckForEditForHtsChapter(material.country)}"
                selectItems="#{itemActionsManagedBean.getMapItemsForHtsChapter(material.country)}"/>

我可以通过readonlyCell属性传递参数。但是对于selectItems,它无法将参数传递到后端bean。它总是传递nullselectItems。我的范围是@ViewScoped

JSF版本:2.2.1,PrimeFaces版本:12.0.0,PrimeFaces扩展版本:12.0.5。

英文:

I want to pass parameters from primefaces sheet column to jsf backing bean like below.

 &lt;pe:sheetcolumn headerText=&quot;HTS Chapter&quot; value=&quot;#{material.htsChapter}&quot; colWidth=&quot;100&quot;
                                                rendered=&quot;true&quot;
                                                colType=&quot;dropdown&quot;
                                                readonlyCell=&quot;#{!itemActionsManagedBean.authCheckForEditForHtsChapter(material.country)}&quot;
                                                selectItems=&quot;#{itemActionsManagedBean.getMapItemsForHtsChapter(material.country)}&quot;/&gt;

I can pass parameters via readonlyCell attribute. But with selecitems it doesnt pass parameters to backing bean. Its always passing null for selectitems. My scope is @ViewScoped.

JSF: 2.2.1, PrimeFaces: 12.0.0, PrimeFaces Extensions: 12.0.5

答案1

得分: 1

SelectItems 不是每一行调用一次,而是对整个列调用一次,ReadOnly 则是每行评估一次,这是它们之间的区别。SelectItems 不能在每一行中有不同的值,这也是为什么它只被调用一次以提高性能的原因,因此在调用时会期望 NULL,因为你并不处于行的“上下文”中。因此,当调用 SelectItems 时,material.country 是 NULL,因为 material 是你的行,甚至还没有被评估。

英文:

SelectItems is NOT called per row its called once for the whole column and ReadOnly is evaluated per row that is the difference. SelectItems cannot be different per row which for performance is why its called only once so NULL is expected as you are not in "context" of a row. So material.country is NULL when SelectItems is called because material is your ROW which is not even evaluated yet.

huangapple
  • 本文由 发表于 2023年4月17日 18:54:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034385.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定