NullPointerException when trying to use crud.custom tag

Bug #494193 reported by dres
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

I got the error below when trying to use the crud.custom tag for the first time. It seems to be do to a very strict requirement in crud that only supports known types.

Here is the template.

#{crud.form fields:['course','startDate']}
                        #{crud.custom 'startDate'}
                                <p>
                                        test
                                        </p>

                        #{/crud.custom}
                #{/crud.form}

I basically want to override the handling of a single field that is a
joda LocalDate (startDate). It seems like it can't even find the
property so below is a snippet of my model too. When I get rid of the
fields arg to the tag, it renders all the fields except the custom
one.

@Entity
public class CourseSection extends Model {

...

        @ManyToOne(cascade=CascadeType.ALL)
        public Course course;

        @Type(type="org.joda.time.contrib.hibernate.PersistentLocalDate")
        public LocalDate startDate;

...

Execution error occured in template {module:crud}/app/views/tags/crud/
form.html. Exception raised was NullPointerException : Cannot get
property 'name' on null object.

In {module:crud}/app/views/tags/crud/form.html (around line 34)

30:

31:
        %{ if(fieldsHandler[fieldName]) { }%
32:
                %{
33:
                        def handler = fieldsHandler[fieldName];
34:
                        handler.setProperty('fieldName', 'object.' + field.name +
(field.type == 'relation' ? '@id' : ''));
35:
             def oldObject = handler.getProperty('object');
36:
                        handler.setProperty('object', currentObject);
37:
                        out.println(handler.toString());
38:
                        handler.setProperty('object', oldObject);
39:
                        handler.setProperty('fieldName', null);
40:
                }%

Looks like ObjectField does not set the type property for anything but
know types.
public ObjectField(Field field)

This causes the ObjectType object to not add it to the field list:
public List<ObjectField> getFields() {
            List fields = new ArrayList();
            for (Field f : entityClass.getFields()) {
                if(Modifier.isTransient(f.getModifiers())) {
                    continue;
                }
                ObjectField of = new ObjectField(f);
---> if (of.type != null) {
                    fields.add(of);
                }
            }
            return fields;
        }

That's why the field object is null when this is called in form.html:
%{ def field = currentType.getField(fieldName) }%

Tags: crud tag template
Changed in play:
status: New → Fix Committed
Revision history for this message
Guillaume Bort (guillaume-bort) wrote :

There is a typo in the fix ...

Changed in play:
status: Fix Committed → Incomplete
Changed in play:
status: Incomplete → Fix Committed
Revision history for this message
hugo lassiège (hakanai-deactivatedaccount) wrote :

Hi,

How do we know in launchpad the version number of this commit ? Is there a link between Bazaar and Launchpad ?
I would like to know because I have the version 713 and I don't know if I'm supposed to have this fix or not.

Revision history for this message
Guillaume Bort (guillaume-bort) wrote : Re: [Bug 494193] Re: NullPointerException when trying to use crud.custom tag

It is fixed here:

http://bazaar.launchpad.net/%7Eplay-developers/play/1.0/revision/735

We usually add the bug fix number to the commit message. Perhaps there
is a better way to do it using launchapd.

2010/1/15 hugo lassiège <email address hidden>:
> Hi,
>
> How do we know in launchpad the version number of this commit ? Is there a link between Bazaar and Launchpad ?
> I would like to know because I have the version 713 and I don't know if I'm supposed to have this fix or not.
>
> --
> NullPointerException when trying to use crud.custom tag
> https://bugs.launchpad.net/bugs/494193
> You received this bug notification because you are subscribed to play
> framework.
>

Revision history for this message
hugo lassiège (hakanai-deactivatedaccount) wrote :

ok thanks, I was looking on the branch 1.1, that's why I didn't saw the build number.
And it seems my problem is not the same one indeed. I'll open a new issue. My purpose was to add some custom fields in the form. My common use case is a form to create a user. The field "confirmPassword" is not a field in the model but I would like to add it in the form (and handle it in the save method, I don't know how for the moment).

#{crud.custom 'confirmPassword'}
... some code to display the confirm password
#{/crud.custom}

Revision history for this message
dres (me-andresmarch) wrote :

I still get this error. How about some null checks?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.