问题
Why i get " contains an unknown id ':commentTextArea' - cannot locate it in the context of the component commentLink" error?
majorra 2.1.7
How i can render commentTextArea.
<ui:repeat var="parentComment" value="#{commentTree.parentCommentsWrapper}"> ....
<h:form>
<h:commandLink id="commentLink" value="comment"
style="height:20px;width:20px;padding: 0; margin: 0;"
action="#{parentComment.changeEditable}">
**<f:ajax render=":commentTextArea"></f:ajax>**
</h:commandLink>
</h:form> <h:panelGroup id="commentTextArea">
<br />
<h:panelGroup rendered="#{parentComment.editable}">
<h:form >
<h:inputTextarea rows="2" cols="20"
value="#{commentTree.newCommentText}"
style="font-family:Arial,Helvetica;font-size:12px;width:365px;margin-right: 4px;margin-left: -1px;">
</h:inputTextarea>
<h:commandButton id="newCommentButton" value="+"
style="height:20px;width:20px;padding: 0; margin: 0;"
action="#{commentTree.saveChildComment(parentComment.comment)}" >
</h:commandButton>
</h:form>
</h:panelGroup>
</h:panelGroup>
</ui:repeat>
'
回答1:
The id :commentTextArea
is an absolute id and relative to the view root. However, ui:repeat
is a NamingContainer and "wraps" your commentTextArea
. (Check the html source in browser to see what id is generated)
A simple solution would be to use only one form in your 'ui:repeat'. Then the relative id with
<f:ajax render="commentTextArea">
(without :
) would work.
来源:https://stackoverflow.com/questions/10682302/jsf2-ajax-render-id-not-found