问题
支持Ajax的JSF按钮...
<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>
显示此页面时,提示以下错误消息
javax.faces.FacesException: <f:ajax> contains an unknown id 'output'
- cannot locate it in the context of the component j_idt8
显然,没有找到' output '的ID,但是已经在<h:outputText id =“ output” />中明确声明了吗?
解
在JSF 2.0中, <f:ajax>标记要求在同一表单级别内进行“渲染”输出。 <h:outputText id =“ output” />标记应在表单内移动。
<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>
参考
翻译自: https://mkyong.com/jsf2/jsf-2-0-f-ajax-contains-an-unknown-id/