0

I am trying edit row from <p:dataTable> n call bean method but the problem is bean method is not invoked on rowEdit event. 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.

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:

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();
    }
}
Tiny
  • 27,221
  • 105
  • 339
  • 599
Khushboo
  • 1
  • 4
  • The XHTML code cannot be parsed. The tag `` is untidy and missing a `>` at the end. Is this your real code? Unrelated but `listener` of `` in this case, will not navigate to the stated navigation case outcome `success`. It basically expects a `void` method in the associated backing bean. Unlike `action`, the return type will simply be ignored. – Tiny Jan 21 '15 at 05:10
  • @Tiny : > tag for was writing mistake... Also removing return tag from bean method, function is still not invoked... edited the bean method above... but now i am getting exception: – Khushboo Jan 21 '15 at 05:39
  • com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError SEVERE: javax.faces.model.NoRowAvailableException Can some one plz help – Khushboo Jan 21 '15 at 05:45
  • What is the scope of the bean? (In this case, It should be view scoped - `@ViewScoped` or even broader, if needed). – Tiny Jan 21 '15 at 06:13
  • Yes, it is view scope only – Khushboo Jan 21 '15 at 06:14
  • Here in the `value` attribute (of ``) - `value="#{commentAction.list(uID)}"`, what is the argument `uID` supposed to be? Are you sure about the list which is supposed to be populated in the backing bean properly at the right place and right time (inside a method decorated/annotated by `@PostConstruct` or one of the overloaded lazy data model's `load()` methods, if you happened to use it in your real code etc)? – Tiny Jan 21 '15 at 06:39
  • @tiny : no i am not using postConstruct. Plz explain its usage & importance. And uID is urs id, comment list is retrived from db for particular uid – Khushboo Jan 21 '15 at 06:49
  • That's another separate question. :) [Here](http://docs.oracle.com/javaee/7/api/javax/annotation/PostConstruct.html) is the Java docs, however. In this case, how do you populate the list which is bound to the given `` - in a getter method? If it is the case then, it has to be avoided. [Here](http://stackoverflow.com/a/2090062/1391249) is why. – Tiny Jan 21 '15 at 06:57
  • Thanx a lot @tiny its working now, problem was populating the list using getter method. But by writing code of getting list in init() resolves the problem. – Khushboo Jan 21 '15 at 09:37

1 Answers1

0

Thanx to @tiny problem is resolved by replacing list retrieving code from getter method to init() in postConstruct annotation. 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();
        }
    }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Khushboo
  • 1
  • 4