簡體   English   中英

JSF 2.0 - 將“h:inputTextarea”嵌套在“h:repeat”中時出現問題

[英]JSF 2.0 - Problem getting 'h:inputTextarea' nested in a 'h:repeat'

我只是將我的項目移動到 JSF2.0 並且我遇到了這個問題。 我只是無法獲得位於 ah:repeat 中的 inputTextarea。 在重復之外,效果很好......

有誰知道這個的解決方案? 我猜這是一件簡單的事情。

觀點:(只有重要的)

    <ui:repeat value="#{pub.commentList}" var="com">
    <h:panelGroup>
                        <h:form id="pub" >                                            
                            <h:inputTextarea id="comment2" value="#{classController.msgComment}"  />                        
                            <div>
                                <h:commandButton type="submit" value="Postar" action="#{classController.saveComment}"  />                            
                            </div>
                        </h:form>
                    </h:panelGroup>
    </ui:repeat>

豆豆一切正常。 只是屬性“msgComment”的獲取/設置。

感謝您的回復!

您需要將值綁定到當前迭代的 object,而不是父托管 bean。

<h:inputTextarea id="comment2" value="#{com.msgComment}" />

我認為您想要做的是(假設您的容器支持 EL 2.2):

<ui:repeat value="#{pub.commentList}" var="com">
    <h:panelGroup>
        <h:form id="pub" >                                            
            <h:inputTextarea id="comment2" value="#{com.msgComment}"  />                        
            <div>
                <h:commandButton type="submit" value="Postar" action="#{classController.saveComment(com)}"  />                            
            </div>
        </h:form>
    </h:panelGroup>
</ui:repeat>

在你的classController bean 中:

public String saveComment(Comment com) {
    //do stuff
    return "success"; //or anything
}

如果您沒有 EL 2.2,您應該使用setPropertyActionListener做一些簡單的解決方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM