gpt4 book ai didi

jsf - OmniFaces:SelectItemsConverter 不适用于 PrimeFaces: PickList

转载 作者:行者123 更新时间:2023-12-01 23:13:21 25 4
gpt4 key购买 nike

我正在尝试将 SelectItemsConverter 与 PrimeFaces Picklist 结合使用。

XHTML:

<p:pickList id="plUpdateFirma" value="#{bsvttController.dlmFirma}" var="plFirma"
itemLabel="#{plFirma.schluesselFirma}" itemValue="#{plFirma}"
converter="FirmaConverter">

<f:facet name="sourceCaption">
Vorjahr
</f:facet>
<f:facet name="targetCaption">
#{bsvttController.selSaison}
</f:facet>

<p:column>
#{plFirma.schluesselFirma}
</p:column>

</p:pickList>

转换器:

@FacesConverter(value = "FirmaConverter")
public class FirmaConverter extends SelectItemsConverter
{

@Override
public String getAsString(final FacesContext facesContext, final UIComponent component, final Object object)
{
return ((Firma) object).getSchluesselFirma();
}

}

bean :

@ManagedBean
@ViewScoped
public class BsvttController implements Serializable
{
private DualListModel<Firma> dlmFirma;
private List<Firma> dlmFirmaSource;
private List<Firma> dlmFirmaTarget;
private Firma firma;

@PostConstruct
public void init()
{
dlmFirmaSource = FirmaPersistenz.leseFirmaAlle();
dlmFirmaTarget = new ArrayList<Firma>();
dlmFirma = new DualListModel<>(dlmFirmaSource, dlmFirmaTarget);
}

public DualListModel<Firma> getDlmFirma()
{
return dlmFirma;
}
public List<Firma> getDlmFirmaSource()
{
return dlmFirmaSource;
}
public List<Firma> getDlmFirmaTarget()
{
return dlmFirmaTarget;
}

public void setDlmFirma(DualListModel<Firma> dlmFirma)
{
this.dlmFirma = dlmFirma;
}
public void setDlmFirmaSource(List<Firma> dlmFirmaSource)
{
this.dlmFirmaSource = dlmFirmaSource;
}
public void setDlmFirmaTarget(List<Firma> dlmFirmaTarget)
{
this.dlmFirmaTarget = dlmFirmaTarget;
}

}

在调试转换器时,我可以看到 getAsString 方法工作正常。但提交表单后,两个数组列表(dlmFirmaSource 和 dlmFirmaTarget)都是空的。

OmniFaces 展示表明这一点

"The omnifaces.SelectItemsConverter allows you to populate e.g. a drop-down with complex Java model objects as value of f:selectItems and have JSF convert those automatically back without the need to provide a custom converter which may need to do the job based on possibly expensive service/DAO operations."

但是对于 PickList 组件,不存在任何 f:selectItems 标记。

SelectItemsConverter 是否支持 PickList 组件?

最佳答案

Does SelectItemsConverter even support PickList component?

不,事实并非如此。

自 OmniFaces 1.5 起,您可以使用 omnifaces.ListConverteromnifaces.ListIndexConverter达到预期的目的。另请参阅the ListConverter showcase example它还演示了 <p:pickList> 上的用法.

关于jsf - OmniFaces:SelectItemsConverter 不适用于 PrimeFaces: PickList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14832899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com