In datatable cell-editing...

UI Components for JSF
Post Reply
User avatar
kimausoleil
Posts: 48
Joined: 10 Nov 2010, 12:12
Location: FRANCE

15 Nov 2010, 10:57

Hello!

I use a datatable to persist in a database.
And it works very well!

My problem occurs when I persist my data.
If I throw an exception because my data does not satisfy the constraints, my datatable still appears with the change.

How can I keep in cell-editing?

Or how to display the value of the database (which has not been updated) instead of those that have just been validated (which is wrong).

This is my code

Code: Select all

            <h:form>
                <p:dataTable var="typeSpectacles" value="#{typeSpectaclesController.typesSpectacles}" rowEditListener="#{typeSpectaclesController.rowEdit}" onRowEditUpdate="msgs" >

                    <p:column headerText="Code" style="width:70px">
                        <h:outputText value="#{typeSpectacles.code}" />
                    </p:column>

                    <p:column headerText="Libellé">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{typeSpectacles.libelle}" />
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{typeSpectacles.libelle}" style="width: 100%" />
                            </f:facet>
                        </p:cellEditor>
                    </p:column>

                    <p:column headerText="Opts" style="width:50px">
                        <p:rowEditor />
                    </p:column>

                </p:dataTable>
            </h:form>
and my function in my controller to persist :

Code: Select all

    public void rowEdit(RowEditEvent ev) {

        TypeSpectacles obj = null;
        try {
            obj = (TypeSpectacles) ev.getObject();
            ejb.edit(obj);
        } catch (Exception ex) {
            addMessage(ex);
        }

    }


Thank you!
JSF2 - Glassfish 3.0.1 - Mojarra 2.0.4 - PrimeFaces 2.2.1 - Netbeans 6.9.1

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Nov 2010, 12:35

Right now it only stay editable when validation is failed by checking FacesContext.getCurrentInstance().isValidationFailed() so when you catch the exception as a workaround you can try;

Code: Select all

public void rowEdit(RowEditEvent ev) {

        TypeSpectacles obj = null;
        try {
            obj = (TypeSpectacles) ev.getObject();
            ejb.edit(obj);
        } catch (Exception ex) {
            addMessage(ex);
            FacesContext.getCurrentInstance().validationFailed();
        }

    }

User avatar
kimausoleil
Posts: 48
Joined: 10 Nov 2010, 12:12
Location: FRANCE

15 Nov 2010, 12:57

Ok !

:mrgreen:
JSF2 - Glassfish 3.0.1 - Mojarra 2.0.4 - PrimeFaces 2.2.1 - Netbeans 6.9.1

User avatar
kimausoleil
Posts: 48
Joined: 10 Nov 2010, 12:12
Location: FRANCE

15 Nov 2010, 18:28

I'm sorry but an other question about this !

So now, when an exception is caught, it stays editable !
But if after I click to cancel, the message is still displayed !

Code: Select all

            <p:messages id="msgs" />            
            <h:form>
                <p:dataTable var="typeSpectateurs" value="#{typeSpectateursController.typesSpectateurs}" rowEditListener="#{typeSpectateursController.rowEdit}" onRowEditUpdate="msgs">


...
How can I mask it ?
There is action when we click to cancel ?
JSF2 - Glassfish 3.0.1 - Mojarra 2.0.4 - PrimeFaces 2.2.1 - Netbeans 6.9.1

User avatar
kimausoleil
Posts: 48
Joined: 10 Nov 2010, 12:12
Location: FRANCE

16 Nov 2010, 15:59

I tried to use renderer property in p:messages...

But what can I test, and what does it do when I click to cancel button for cell-editing ?
JSF2 - Glassfish 3.0.1 - Mojarra 2.0.4 - PrimeFaces 2.2.1 - Netbeans 6.9.1

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

24 Nov 2010, 14:49

If you just want the FacesMessage displayed for a short time and then hidden you should take a look at the growl component of PrimeFaces.

User avatar
kimausoleil
Posts: 48
Joined: 10 Nov 2010, 12:12
Location: FRANCE

24 Nov 2010, 16:10

You're right !

But If I want to do another action when I click the cross to cancel in-cell editing...

I'd like a "cancelListener" ! :)

May be one day...
JSF2 - Glassfish 3.0.1 - Mojarra 2.0.4 - PrimeFaces 2.2.1 - Netbeans 6.9.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests