0

I'm having some issues retrieving a list of entities and overall interacting with a managed bean class in a jsf project. This is the class

@Named(value = "userRegistrationController")
@ViewScoped
public class UserRegistrationController implements java.io.Serializable{

@EJB
UserFacade ejbFacade;

private User current;
private List<User> userList;

public UserRegistrationController() {
}

public String populateUsers(){
    this.userList = ejbFacade.findAll();
    System.out.println("SIZE == "+userList.size());
    return "admin/currentUsers";
}

public String print(){
    return "EJBFACADE = "+ejbFacade.findAll().size()+" |  = "+userList.size();
}

public String flowHandler(FlowEvent event){
    if(current != null){
        System.out.println("current: "+current);
        if(!current.isEnableNotifications()){
            return "confirm";
        }else{
            return event.getNewStep();
        }
    }
    else{
        return event.getNewStep();
    }
}

public String create(){
    int userCount = ejbFacade.findAll().size();
    current.setId(BigDecimal.valueOf(userCount+1));
    ejbFacade.create(current);
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Successful User Entry", "Successful User Entry"));
    return null;
}

// getters setters

When i call this from a xhtml page with

<p:dataTable id="registeredUserList" value="#{userRegistrationController.userList}" var="u">..</>

partial jsf page with p:cellEditor:

<f:view>

<body>

    <f:event type="preRenderView" listener="#{userRegistrationController.populateUsers}"/>

    <ui:composition template="../layout/template.xhtml">

        <ui:define name="content">
            <h1>Current Registered Users</h1><br/>
            <h:form id="currentUserForm">

                <h:outputText value="#{userRegistrationController.print}"/>

                <p:dataTable id="registeredUserList" value="#{userRegistrationController.userList}" var="u"
                             editable="true" editMode="cell">
                    <p:ajax event="cellEdit" listener="#{userRegistrationController.cellEditAction}"
                            update=":currentUserForm:currentUsersFormMessages"/>
                    <p:column id="firstName" headerText="First">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{u.first}"/>
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText id="firstNameInput" value="#{u.first}"/>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
..........

This is the method userRegistrationController.cellEditAction that properly worked before adding the fix

public void cellEditAction(CellEditEvent event) {
    System.out.println("INSIDE CELLEDIT");
    Object oldValue = event.getOldValue();
    Object newValue = event.getNewValue();
    if (newValue != null && !newValue.equals(oldValue)) {
        FacesMessage message = new FacesMessage("The " + event.getColumn().getHeaderText() + " column has been changed to " + newValue);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

As a matter of fact it show the proper changed value in the faces message but it fails to save it to the User object.

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
MrSir
  • 516
  • 2
  • 9
  • 26
  • So you did check if ``#{userRegistrationController.populateUsers}` is called at all to populate the list? – Kukeltje Sep 28 '17 at 21:11
  • Your initial 'problem' was caused by https://stackoverflow.com/questions/6525050/understand-the-purpose-of-jsf-uicomposition. If you want to have meta in a composite, make sure it is in an define that is used in the template. See https://stackoverflow.com/questions/19307646/can-i-add-a-meta-tag-to-a-particular-page-that-is-using-templates – Kukeltje Sep 28 '17 at 21:18
  • @ Kukeltje When the page gets loaded there's no call to `.populateUsers` since it gives me no print in console, once i call it again via action with a `h:commandButton` it reloads and works. I checked those links, i tried to use a an `ui:insert` in the main template to then define it in the client but it doesn't work, bare in mind my main template is all inside a `` if that might be an issue. – MrSir Sep 29 '17 at 13:09
  • One i load the client page the first time i noticed i have a warning `The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within ` . Once i reload and it properly displays the datatable i have `Unable to find matching navigation case with from-view-id '/admin/currentUsers.xhtml' for action '#{userRegistrationController.populateUsers}' with outcome 'admin/currentUsers'` . If that might be of any help. – MrSir Sep 29 '17 at 13:10
  • So you fixed it and have a new question. Please creatie a new question then – Kukeltje Sep 30 '17 at 11:31

0 Answers0