changeThe page has 2 forms. In the first form, the ajax-button initializes an attribute of the viewscoped managed bean. In the second form, the ajax-button uses that attribute to do some stuff.
Problem is that the method called by the second form button never gets invoked. Instead, the viewscoped bean is re-initialized and when I hit the same button again, of course the attribute is null resulting in NPE.
When I put the 2 buttons within the same form, then everything works as expected.
Is this normal: should ajax enabled buttons always reside within the same form?
更改页面有2个表单。在第一种形式中,ajax-button初始化viewscoped托管bean的属性。在第二种形式中,ajax按钮使用该属性来做一些事情。问题是第二个表单按钮调用的方法永远不会被调用。相反,视图结构bean被重新初始化,当我再次点击同一个按钮时,属性为null,导致NPE。当我将2个按钮放在同一个表单中时,一切都按预期工作。这是正常的:ajax启用的按钮是否总是位于同一个表单中?
<h:form id="frmDetail">
<h:commandButton id="btn_changePlant" title="#{msg.ttChangePlant}" immediate="true" image="/resources/img/edit.png">
<f:ajax event="click" render=":fsDetailPlant :headerMsg" listener="{assortiment.detailPlantId}"/>
</h:commandButton>
</h:form>
...some other code ...
<h:form id="frmOffers">
<h:commandButton id="btn_offers" title="#{msg.ttOfferPlant}" immediate="true" value="#{msg.btn_offers}">
<f:ajax event="click" render=":fsDetailPlant :headerMsg" listener="{assortiment.changeOffers}"/>
</h:commandButton>
</h:form>
and the managed bean looks like
并且托管bean看起来像
@ManagedBean
@ViewScoped
public class Assortiment extends BeanObject implements Serializable {
....
public void detailPlantId(AjaxBehaviorEvent actionEvent) {
clear();
plantdetail = facade.findPlantdetail(plantdetailsIdModel.getRowData());
}
public void changeOffers(AjaxBehaviorEvent actionEvent) {
System.out.println("........ Assortiment.changeOffers(AjaxBehaviorEvent actionEvent)");
if (containerItems.isEmpty()) {
SessieUtils.fillPropertyItems(containerItems, PlantProperty.codeValuesList(ECodeType.logistic, "L02"), facade.getLocale());
}
//
if (offersModel == null) {
offersModel = new ListDataModel<OffersDto>(plantdetail.getOffersList());
}
}
1 个解决方案
#1
0
It might just be that the listener attributes need the # prefix,
可能只是监听器属性需要#前缀,
listener="{assortiment.changeOffers}"
should be
应该
listener="#{assortiment.changeOffers}"
#1
0
It might just be that the listener attributes need the # prefix,
可能只是监听器属性需要#前缀,
listener="{assortiment.changeOffers}"
should be
应该
listener="#{assortiment.changeOffers}"