JSF 2.0 : <f:ajax> contains an unknown id

Problem

A JSF’s button with Ajax support…


<h:outputText id="output" value="#{helloBean.sayWelcome}" />
<h:form>    	
   <h:inputText id="name" value="#{helloBean.name}"></h:inputText>
   <h:commandButton value="Welcome Me">
   	 <f:ajax execute="name" render="output" />
   </h:commandButton>
</h:form>

When this page is displayed, it prompts the following error message


javax.faces.FacesException: <f:ajax> contains an unknown id 'output'
                             - cannot locate it in the context of the component j_idt8

Obviously, the id of ‘output‘ is not found, but it’s explicitly declared in the <h:outputText id=”output” /> already?

Solution

In JSF 2.0, the <f:ajax> tag required the “render” output within the same form level. The <h:outputText id=”output” /> tag should move inside the form.


<h:form>    	
   <h:outputText id="output" value="#{helloBean.sayWelcome}" />
   <h:inputText id="name" value="#{helloBean.name}"></h:inputText>
   <h:commandButton value="Welcome Me">
   	 <f:ajax execute="name" render="output" />
   </h:commandButton>
</h:form>

Reference

  1. JSF 2.0 + Ajax hello world example

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
9 Comment threads
3 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
10 Comment authors
saasirashankarvo ly luanPoornimaDickens Recent comment authors
newest oldest most voted
saasira
Guest
saasira

could have used :form_id:output, but the example lacked id for the form component; so pulling the ‘output’ component within the form is the only solution in this context.

shankar
Guest
shankar

Thanks

vo ly luan
Guest
vo ly luan

This is my code , but it not working, i can’t get value of txtContent
Any solution , please help me, Thank so much

Poornima
Guest
Poornima

Hi, could u please attach the folder structure with libraries and web.xml and faces-config.xml file.

thanks

Dickens
Guest
Dickens

In IE9, I get the following error, but no error in Firfox and Chrome. Do you know how to solve this problem?

malformed xml unable to get value of the property ‘removechild’ object is null or undefined

trackback
JSF 2.0 Tutorial

[…] JSF 2.0 : <f:ajax> contains an unknown id […]

Ahmed feki
Guest
Ahmed feki

what is we need that is doesnt belong to the same form !!
cheers!

Danilo Miranda
Guest
Danilo Miranda

Param,

I try put render=”:busca_produto” but doesn’t work.

Look the error message

f:ajax> contains an unknown id ‘:busca_produto’ – cannot locate it in the context of the component inputNumber

Another shot

Message:
javax.servlet.ServletException: inputNumber

Help me

param
Guest
param

If you wanted to render a component outside of the form using the tag, then you must specify the render ids absolutely, ie, with respect to the top level container. So in this case render=”:output” would do the trick.

Musa
Guest
Musa

Good job, param

Ravi
Guest
Ravi

Even I tried to put the outputtextid inside the form ..Its is not working it is giving the same error.

Ravi
Guest
Ravi

Sorry my bad.. I had n otgiven the id=”name” in the inputtext element..