开发者

JSF ajax commandbutton from multiple forms within same page reinitiliazes the viewscoped bean

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?

<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}" 开发者_Go百科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

@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());
    }
}


It might just be that the listener attributes need the # prefix,

listener="{assortiment.changeOffers}"

should be

listener="#{assortiment.changeOffers}"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜