简体   繁体   English

p:dataTable的rowEdit事件上的Bean方法未调用

[英]Bean method on rowEdit event of p:dataTable is not invoked

I am trying edit row from <p:dataTable> n call bean method but the problem is bean method is not invoked on rowEdit event. 我正在尝试从<p:dataTable> n调用bean方法编辑行,但问题是未在rowEdit事件上调用bean方法。 It will be appreciable, if someone could give me the solution. 如果有人可以给我解决方案,那将是不胜感激的。

Also, my bean is already in View Scope, even not working in session scope... I have tried for all three scopes. 另外,我的bean已经在View Scope中,甚至不能在会话范围中工作...我已经尝试了所有三个范围。

My codes are given below : 我的代码如下:

<h:form id="commentList">
    <p:dataTable id="commentTable" editable="true" paginator="true" rows="10" var="comment" value="#{commentAction.list(uID)}" class="table table-striped table-bordered table-hover commentTable" widgetVar="commentListTable">
        <p:ajax event="rowEdit" listener="#{commentAction.updateCommentStatus}"/>
        <p:column filterBy="#{comment.commentId}" footerText="" headerText="Comment Id" filterMatchMode="contains" sortBy="#{comment.commentId}">
            <h:outputText value="#{comment.commentId}" id="commentId"/>
        </p:column>
        <p:column filterBy="#{comment.selectedText}" headerText="Selected Text" sortBy="#{comment.selectedText}">
            <h:outputText value="#{comment.selectedText}" id="selectedText"/>
        </p:column>
        <p:column filterBy="#{comment.commentText}" headerText="Comment" sortBy="#{comment.commentText}">
            <h:outputText value="#{comment.commentText}" id="commentText" escape="false"/>
        </p:column>
        <p:column filterBy="" headerText="Comment From" sortBy="">
            <h:outputText value="" id="commentFrom"/>
        </p:column>
        <p:column filterBy="#{comment.insertedOn}" headerText="Date/Time" sortBy="#{comment.insertedOn}">
            <h:outputText value="#{comment.insertedOn}" id="insertedOn"/>
        </p:column>
        <p:column filterBy="#{comment.commentStatus}" headerText="Comment Status" sortBy="#{comment.commentStatus}">
            <p:cellEditor>
                <f:facet name="output">
                    <h:outputText value="#{comment.commentStatus}" id="commSatus"/>
                </f:facet>
                <f:facet name="input">
                    <h:selectOneMenu value="#{commentAciton.commentStatus}" id="commentStatus" class="commentSelectBox">
                        <f:selectItem itemLabel="UpdateStatus" itemDisabled="true"/>
                        <f:selectItem itemValue="Open" itemLabel="Open"/>
                        <f:selectItem itemValue="Close" itemLabel="Close"/>
                        <f:selectItem itemValue="Cancel" itemLabel="Cancel"/>
                    </h:selectOneMenu>
                </f:facet>
            </p:cellEditor>
        </p:column>
        <p:column style="width:32px">
            <p:rowEditor />
        </p:column>
    </p:dataTable>
</h:form>

And bean method is: 而bean方法是:

public void updateCommentStatus(RowEditEvent event) {
    try {
        logger.info("comment Iddddddddddd: " + commentId);
        logger.info("comment Statusssssss: " + this.commentStatus);
        Comment comment = (Comment) event.getObject();
        logger.info("new value: " + comment.getCommentStatus());
    } catch (Exception ex) {
        logger.info("Exception caught in updateCommentStatus in CommentAction ..." + ex.getMessage());
        ex.printStackTrace();
    }
}

Thanx to @tiny problem is resolved by replacing list retrieving code from getter method to init() in postConstruct annotation. 通过将列表检索代码从getter方法替换为postConstruct批注中的init(),可以解决@tiny问题。 Below is the corrected code 下面是更正的代码

<p:dataTable id="commentTable" editable="true" paginator="true" rows="10" var="comment" value="#{commentAction.commentList}" class="table table-striped table-bordered table-hover commentTable" widgetVar="commentListTable">
<p:ajax event="rowEdit" listener="#{commentAction.updateCommentStatus}"/>
  ....
  ....
  ....
</p:dataTable>
@PostConstruct
    public void init(){
        logger.info("urs: "+ursId);
        CommentManager commentManager = new CommentManager();
        try {
            commentList = commentManager.list(1); //hardcoding ryt now
        } catch (Exception ex) {
            logger.info("Exception caught in init in CommentAction ..." + ex.getMessage());
            ex.printStackTrace();
        }
    }
    public void updateCommentStatus(RowEditEvent event){
        try{
            CommentManager commentManager = new CommentManager();
            Comment comment = (Comment)event.getObject();
            logger.info("*****************************************************");  
            logger.info("comment Iddddddddddd: " +comment.getCommentId());
            logger.info("comment Statusssssss: " +comment.getCommentStatus());
            commentManager.updateCommentStatus(comment);
        } catch(Exception ex){
            logger.info("Exception caught in updateCommentStatus in CommentAction ..." + ex.getMessage());
            ex.printStackTrace();
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM