Skip to main content

Why this table In-Cell editor, doesnt work?



I am trying to figure out, how the primefaces in-cell editor works.





For some reason, it does not work. I just see it activating and also i can type, but the values do not change. What is missing?







<?xml version='1.0' encoding='UTF-8' ?>

<!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:h="http://java.sun.com/jsf/html"

xmlns:p="http://primefaces.org/ui"

xmlns:f="http://java.sun.com/jsf/core">



<h:form>

<p:dataTable id="allSubjects" var="subject" value="#{subjectControllerUpdate.retrieve()}" paginator="true" rows="7" >

<p:column headerText="Name" sortBy="#{subject.name}" style="width:200px" >

<p:cellEditor>

<f:facet name="output">

<h:outputText value="#{subject.name}"/>

</f:facet>

<f:facet name="input">

<p:inputText value="#{subject.name}" style="width:100%"/>

</f:facet>

</p:cellEditor>

</p:column>



<p:column sortBy="#{subject.description}" headerText="Description">

<p:cellEditor>

<f:facet name="output">

<h:outputText value="#{subject.description}"/>

</f:facet>

<f:facet name="input">

<p:inputText value="#{subject.description}" style="width:100%"/>

</f:facet>

</p:cellEditor>

</p:column>



<p:column sortBy="#{subject.credits}" headerText="Credits" style="width:50px">

<p:cellEditor>

<f:facet name="output">

<h:outputText value="#{subject.credits}"/>

</f:facet>

<f:facet name="input">

<p:inputText value="#{subject.credits}" style="width:100%"/>

</f:facet>

</p:cellEditor>

</p:column>



<p:column headerText="Options" style="width:50px">

<p:rowEditor />

</p:column>

</p:dataTable>

</h:form>



</html>







This is the managed bean







package controllers;



import crudfacades.SubjectFacade;

import entities.Subject;

import java.io.Serializable;

import java.util.List;

import javax.ejb.EJB;

import javax.enterprise.context.SessionScoped;

import javax.inject.Named;



@Named("subjectControllerUpdate")

@SessionScoped

public class SubjectControllerUpdate implements Serializable {



private List<Subject> subjects;

private Subject currentSubject;

@EJB

private SubjectFacade ejbFacade;



//INITIALIZATION

public SubjectControllerUpdate() {

currentSubject = new Subject();

}



//RETRIEVE

public List<Subject> retrieve() {

return getSubjectFacade().findAll();

}



//UPDATE



//HELP METHODS

//RETURN THE FACADE FOR DATA MANIPULATION(Best practice)

private SubjectFacade getSubjectFacade() {

return ejbFacade;

}



//GETTERS AND SETTERS

public Subject getCurrentSubject() {

return currentSubject;

}



public void setCurrentSubject(Subject currentSubject) {

this.currentSubject = currentSubject;

}



public List<Subject> getSubjects() {

return subjects;

}



public void setSubjects(List<Subject> subjects) {

this.subjects = subjects;

}

}




Comments

  1. but when i click comfirm, the value in the UI is not changed


    You've bound the value of the <p:dataTable> to retrieve() instead of getSubjects(). So every single getter call will get the values straight from the DB instead of the model.


    and i see no changes in the database


    You are not saving anything in the DB.

    Fix your controller as follows:

    @Named
    @SessionScoped
    public class SubjectControllerUpdate implements Serializable {

    private DataModel<Subject> subjects;

    @EJB
    private SubjectFacade ejbFacade;

    @PostConstruct
    public void init() {
    subjects = new ListDataModel<Subject>(ejbFacade.findAll());
    }

    public void save() {
    ejbFacade.save(subjects.getRowData());
    }

    public List<Subject> getSubjects() {
    return subjects;
    }

    }


    with

    <h:form>
    <p:dataTable value="#{subjectControllerUpdate.subjects}" ...>
            <p:ajax event="rowEdit" listener="#{subjectControllerUpdate.save}" />
    ...
    </p:dataTable>
    </h:form>


    Using DataModel<Subject> instead of List<Subject> is necessary in order to be able to get the current row.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex