-1

I am trying to pass an object from populated with items table to Controller. Then I use JS alert to verify success. However I fail to pass anything from the table.

Any help would be appreciated.

issues.xhtml

<p:dataTable var="issue" value="#{issuesController.findWithParameter(issues, startenddates)}" styleClass="list" selectionMode="single" selection="#{issuesController.issue}" rowKey="#{issue.id}" >
    <p:ajax event="rowSelect" update="mainForm" listener ="#{issuesController.onRowSelect}" 
            oncomplete="alert(args.name)"/>  

    <p:column headerText="Id"  id = "head_id" style="width:0%; padding: 0px;">
        <h:outputText value="#{issue.id}"/>
    </p:column>
    <p:column headerText="Child" id = "head_child" style="width:12%;">
        <h:outputText value="#{issue.child}"/>
    </p:column>
...
</p:dataTable>

IssuesController.java

@Named("issuesController")
@RequestScoped
public class IssuesController implements Serializable {

    @Inject
    private Issues issue;
....
public void onRowSelect(SelectEvent event) throws IOException {
        Issues i = (Issues) event.getObject();
        String toWrite;
        if (i == null) {
            toWrite = "Item is not recieved";
        } else {
            toWrite = i.toString();
        }
        RequestContext.getCurrentInstance().addCallbackParam("name", toWrite);
}

Issues.java

@Named("issues")
@SessionScoped
@XmlRootElement
public class Issues implements Serializable {
....
}

I tried different types of scope, tried f:attribute...neither of this worked...

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Please start by comparing with the PrimeFaces showcase (all works there and have been for a long time). After that, search the (with 'primefaces datatable row selection ajax' (adding 'site:stackoverflow.com' in the search terms helps) and start reading. And if you cannot find the cause then, create a [mcve], post it here so we can investigate. And 'failed to pass anything' is sort of strange, method not called? object 'null' ? Then search more specifically for those terms. (oh and off-topic, `private Issues issue;` is strange, plural and single) – Kukeltje Jan 17 '20 at 14:01
  • What is your primefaces version? – BugsForBreakfast Jan 17 '20 at 14:01
  • And read these: https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Jan 17 '20 at 14:41
  • Tried removing the update and oncomplete from the ajax tag and using a view scoped bean? – ChadNC Jan 23 '20 at 19:35

1 Answers1

0

Try using process="@this" and change the scope to @ViewScoped.

Noah
  • 68
  • 1
  • 7