Paweł H
Paweł H

Reputation: 66

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 way to pass something that idetifies my inputText? Or any way to set size in some other stage? Where?

Upvotes: 1

Views: 1553

Answers (1)

BalusC
BalusC

Reputation: 1108722

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)}" />

Upvotes: 2

Related Questions