开发者

How to pass some ID of h:inputText to a bean in action

I'm using JSF 2.0 with GF3.1

I have many h:inputTexts on my page and want to format their size on some conditions depending their ID.

My bean method:

  public String doSize(Object obj) {
    if (obj.equals(...)) 
        return "5";
    else
        return "10";
  }

And my JSF page:

....
<h:inputText id="some1" value="#{myBean.values['1']}" 
   size="{myBean.doSize(this)}" />
.... (another inputTexts) ....

I always get null passed to bean. Is there any 开发者_StackOverflow社区way to pass something that idetifies my inputText? Or any way to set size in some other stage? Where?


Use #{component}. It refers to the current UIComponent which is in this particular case of subtype UIInput.

<h:inputText id="some1" value="#{myBean.values['1']}" 
    size="#{myBean.doSize(component)}" />

You can even explicitly pass the ID which is obtained from UIComponent#getId():

<h:inputText id="some1" value="#{myBean.values['1']}" 
    size="#{myBean.doSize(component.id)}" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜