1

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?

Paweł H
  • 66
  • 10

1 Answers1

2

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)}" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks @BalusC, that's what I needed. An extra question: passing component.id to bean works great, I get my id. While doing value binding same way: value="#{myBean.values[component.id])" binds not to my id but to some j_idt6 name.... – Paweł H Aug 30 '11 at 18:38
  • Unfortunately, that doesn't work that way in values. The default `id` is been obtained before the fixed `id` is been set. You might want to parameterize the string "some1" instead, e.g. by `` so that you don't need to repeat it. Or, have a look at tag files like as the example here: http://stackoverflow.com/questions/5713718/how-to-make-a-grid-of-jsf-composite-component/5716633#5716633 – BalusC Aug 30 '11 at 18:53