0

So I have a list xhtml file that works fine:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<ui:composition template="layout.xhtml">
    <ui:define name="content">
        <h:form id="form">
            <p:panel header="User List">
                <p:dataTable id="table" var="user" value="#{userList.users}">
                    <p:column headerText="ID">
                        <h:outputText value="#{user.id}" />
                    </p:column>

                    <p:column headerText="Name">
                        <h:outputText value="#{user.fullName}" />
                    </p:column>

                    <p:column headerText="Birthday">
                        <h:outputText value="#{user.birthDate}" />
                    </p:column>
                    
                </p:dataTable>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
</html>

With this "controller"

package com.eugene.userlist.controller;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

import com.eugene.userlist.domain.User;
import com.eugene.userlist.service.UserService;

@RequestScope
@Component (value = "userList")
public class UserListJSFController {
    @Autowired
    private UserService service;

    private List<User> users;

    @PostConstruct
    public void loadData() {
        users = service.getUserList(null, null, null);
    }
    
    public List<User> getUsers() {
        if(users == null || users.isEmpty())
            users = service.getUserList(null, null, null);
        return users;
    }
   
}

Now I'm trying to add a delete button

<p:column>
                        <h:commandButton icon="ui-icon-circle-close"
                            action="#{userList.remove(user)}" style="border-color:#FF0000" />
                    </p:column>

Adding this method to the controller

public String remove(User user) {
        service.delete(user);
        return "/user-list.xhtml?faces-redirect=true";
    }

But when I do it the get method stops being called and therefore the list never renders. I have look into a lot of questions already but I don't seem to be able to find the answer. Please help!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
MREugeneJ7
  • 1
  • 2
  • 8

0 Answers0