2

my xhtml form code :

            <h:inputText id="name" value="#{customer.name}" 
                size="20" required="true"
                label="Name" onblur="alert(this.value())" >
            </h:inputText>

Now when I view source it renders to

<input id="j_idt22:name" name="j_idt22:name" onblur="alert(this.value())" size="20"    type="text">

If we check their is a prefix appended to it: j_idt22:,
I want to get this prefix name in my bean form.

how I can achieve that?

ManMohan Vyas
  • 4,004
  • 4
  • 27
  • 40
  • if you want to avoid this random generated name you could do it – jmj Jul 23 '12 at 09:42
  • thanks ... how I can do that ?? And what is the purpose for this prefix?? can you give link for same. And but still if I want to get prefix, any idea on how that can be done – ManMohan Vyas Jul 23 '12 at 09:44
  • 1
    set prependId to false as ` ` – jmj Jul 23 '12 at 09:45
  • @JigarJoshi thanks that works!! what is the purpose of prefix ?? and how I can get this prefix in managed bean – ManMohan Vyas Jul 23 '12 at 09:51
  • JSf generates the dynamic id, you can have value directly binded with your JSF bean – jmj Jul 23 '12 at 09:53
  • 1
    What do you need it for in your backing bean? Whatever problem you're trying to solve based on this information needs most likely to be solved differently. – BalusC Jul 23 '12 at 23:26
  • @BalusC .. m trying to create a frame work , where by reflection I can directly insert values to db by taking the Model class as argument. In case if any extra functionality is needed then that formClass can be extended. Any suggestions ..I can open different question if it is going off topic – ManMohan Vyas Jul 24 '12 at 05:39

4 Answers4

5

To avoid dynamically generated ids in JSF component you could use

<h:form prependId="false"> 

You can directly get the values binded with your managed bean

If you want to retrieve list of names then you could use request.getParameterMap()

jmj
  • 237,923
  • 42
  • 401
  • 438
  • thanks that definitely helps .. but doesn't answer my question of how I can get prefix in managed bean – ManMohan Vyas Jul 23 '12 at 09:57
  • I don't think anyone one will answer this post, your answer is not exactly what I want ..but that helped .. marking it as answer .. thanks for help – ManMohan Vyas Jul 25 '12 at 06:32
  • This prepend thing should never have been introduced and not used https://stackoverflow.com/questions/7415230/uiform-with-prependid-false-breaks-fajax-render – Kukeltje Feb 09 '19 at 13:08
4

The id you see is the client id of the component. If you have a binding to the component in your bean, component.getClientId(<FacesContext>) will return the HTML id (j_idt22:name) of the element.

Ashwin Prabhu
  • 9,285
  • 5
  • 49
  • 82
2

you can set an id to the form tag as well to avoid the autogenerated id. that way you will know the prefix as you have set it yourself.

wemu
  • 7,952
  • 4
  • 30
  • 59
  • but that way I wont be able to get that generically, basically what I want is to create a generic managed bean for all form component that I can extend their after to add special functionality, hardocoding of id on every form wont helps much – ManMohan Vyas Jul 23 '12 at 10:24
1

I think You don't have mentioned your form, if mention the form name it will generate the id as formname:idname.

NPKR
  • 5,368
  • 4
  • 31
  • 48