Datatable multiple selection not working

UI Components for JSF
Post Reply
Erates
Posts: 11
Joined: 16 Jul 2015, 09:43

30 Apr 2018, 16:16

Hello,

In the code I show you below I have a lazy datatable, and I want to place multiple selection on it. I want the checkbox type, so I'm adding selectionMode="multiple" on a column. But for some reason, when I process the datatable, my selection is empty.

The JSF code

Code: Select all

<p:dataTable
                id="table"
                value="#{messageBulkBean.model}"
                var="msg"
                widgetVar="table"
                paginator="true"
                rows="#{settingsBean.numberOfRows}"
                rowKey="#{msg.id}"
                paginatorTemplate="#{mymSettingsBean.paginationTemplate}"
                lazy="true"
                currentPageReportTemplate="{totalRecords} #{rmsg.results}"
                pageLinks="5"
                paginatorPosition="bottom"
                sortBy="#{msg.inTimestamp}"
                sortOrder="descending"
                selection="#{messageBulkBean.selectedMessages}"
                paginatorAlwaysVisible="false"
                emptyMessage="#{rmsg.no_messages}">

	<p:column width="35" selectionMode="multiple" rendered="#{resend}">
	</p:column>

	<!-- other columns -->
</p:dataTable>
My Model

Code: Select all

@Named
@ViewScoped
public class MessageModel extends LazyDataModel<DtoMessage> {

    private static final long serialVersionUID = 1L;
    private static final int MAX_RESULTS = 10000;

    private static final Logger LOGGER = LogManager.getLogger(MessageModel.class);

    private final DtoMessageStatelessBeanLocal sb;

    public MessageModel(DtoMessageStatelessBeanLocal sb) {
        this.sb = sb;
    }

    @Override
    public Object getRowKey(DtoMessage message) {
        if (message == null) {
            return StringUtils.EMPTY;
        } else {
            return message.getId();
        }
    }

    @Override
    public List<DtoMessage> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
        // Logic to load the messages
    }

    @Override
    public DtoMessage getRowData(String rowKey) {
        try {
            DtoMessage message = sb.getMessageById(rowKey);
            return message;
        } catch (EJBException ex) {
            Throwable rootCause = ExceptionUtils.getRootCause(ex);
            LOGGER.warn("Could not get the message for rowKey " + rowKey, rootCause);
        }
        return null;
    }
}
The bean with the selected rows

Code: Select all

@Named
@ViewScoped
public class MessageBulkBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOGGER = LogManager.getLogger(MessageBulkBean.class);

    @Inject
    private transient DtoMessageStatelessBeanLocal sbMessages;

    private List<DtoMessage> selectedMessages;

    @PostConstruct
    public void postConstruct() {
        selectedMessages = new ArrayList<>();
    }

    public List<DtoMessage> getSelectedMessages() {
        return selectedMessages;
    }

    public void setSelectedMessages(List<DtoMessage> selectedMessages) {
        this.selectedMessages = selectedMessages;
    }
}
Button to view the selected rows

Code: Select all

<p:commandButton value="#{rmsg.bulk}" process=":archiveForm:table" update=":bulkDialogForm"
                                         oncomplete="PF('bulkDialog').show();" />
When I click the button to view the selected rows (which opens a dialog with a plain datatable with the selectedMessages from the MessageBulkBean), the setter for the '' field is called, but with no rows.

Does somebody have an idea what I am doing wrong? I am using the rowKey like I've seen on multiple places, the button processes the table.
JSF 2.2
Primefaces 5.3
Payara 4.1.1.171

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

01 May 2018, 15:07

is getRowKey and/or getRowData called at all? And does they return the correct values

Erates
Posts: 11
Joined: 16 Jul 2015, 09:43

02 May 2018, 06:35

No they are not called. Not during initial rendering of the page, not when I'm selecting one (or more) rows, but also not when I'm processing the form. Am I missing something?
JSF 2.2
Primefaces 5.3
Payara 4.1.1.171

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 56 guests