How to pass parameter to f:ajax in h:inputText? f:param does not work

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I need to pass a parameter to the server in my ajax request. Please see the code below. Scope: View Scope

Without f:param

Managed Bean

public final void onCostoBrutoChange(final AjaxBehaviorEvent event) {     createCostoBrutoOptions(promoArticlesList); } 

In this case, the method onCostoBrutoChange() does gets invoked. But, it does not get invoked when I include f:param. Please see the code below.

With f:param

Managed Bean

public final void onCostoBrutoChange(final AjaxBehaviorEvent event) {     createCostoBrutoOptions(promoArticlesList);     String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("myId"); } 

Not able to identify whats incorrect in this code. Please guide.

Thanks, Shikha

回答1:

The works in links and buttons only, not in inputs.

If your environment supports EL 2.2, just pass it as method argument instead:

public void listener(Long id) {     // ... } 

You can also just pass the whole item:

public void listener(Item item) {     // ... } 

If your environment doesn't or can't support EL 2.2, then evaluate EL programmatically instead.

public void listener() {     FacesContext context = FacesContext.getCurrentInstance();     Long id = context.getApplication().evaluateExpressionGet(context, "#{item.id}", Long.class);     // ... } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!