gpt4 book ai didi

jsf - f :setPropertyActionListener inside p:commandLink doesn't set the property value to the target request scoped bean

转载 作者:行者123 更新时间:2023-12-04 18:20:09 24 4
gpt4 key购买 nike

我正在尝试使用 <f:setPropertyActionListener> 将属性值设置为目标 bean里面<p:commandLink>如下。

<h:form id="form" prependId="true">
<p:panel id="dataPanel" closable="false" toggleOrientation="horizontal" toggleable="true" style="border: none; text-align: center;">
<p:dataGrid id="dataGrid" value="#{productDetailsManagedBean}" var="row" rowIndexVar="rowIndex" rows="4" first="0" columns="1" paginator="true" paginatorAlwaysVisible="false" pageLinks="10" lazy="true" rowsPerPageTemplate="5,10,15">

<p:commandLink process="@this">
<h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
<!--row.subCatName is correctly retrieved here.-->
<f:setPropertyActionListener value="#{row.subCatName}" target="#{productDetailsManagedBean.subCatName}" />
</p:commandLink>

</p:dataGrid>
</p:panel>
</h:form>

对应的JSF托管bean如下。

@ManagedBean
@RequestScoped
public final class ProductDetailsManagedBean extends LazyDataModel<SubCategory>
{
public ProductDetailsManagedBean() {}

@EJB
private final ProductDetailsBeanLocal productService=null;
private String subCatName;

public String getSubCatName() {
return subCatName;
}

public void setSubCatName(String subCatName) {
System.out.println("setSubCatName() called. : "+subCatName); //Never invoked.
this.subCatName = subCatName;
}

//The following methods are not needed to be reviewed.

@Override
public List<SubCategory> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters)
{
int rowCount = productService.rowCount().intValue();
setRowCount(rowCount);
return productService.getList(first, pageSize);
}
}

<p:commandLink>被点击,bean中对应的setter方法setSubCatName(String subCatName)预计会被调用,但此方法从未被调用,因此 bean 属性 subCatName永远不会设置一个值。

我在这里忽略了什么?

我使用的是 Mojarra 2.2.5 和 PrimeFaces 4.0。

process <p:commandLink> 的属性已设置为 @this .我已经尝试设置 prependId<h:form>false但这也没有什么不同。


编辑:

当托管 bean 的范围从 @RequestScoped 更改时,这有效至 @ViewScoped .这应该适用于 @RequestScoped bean 也。我在这里做错了什么?这是预期的行为吗?

最佳答案

这确实需要一个比请求范围更高的范围才能工作(在这种情况下,至少需要一个 View 范围的 bean)。请see这个答案。

关于jsf - f :setPropertyActionListener inside p:commandLink doesn't set the property value to the target request scoped bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22587809/

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