Menu

"Invalid or unexpected token" only when using a model detail view

2021-04-24
2021-05-28
  • Lucio Crusca

    Lucio Crusca - 2021-04-24

    I have a "Contatto" model like this:

    @Entity @Getter @Setter
    public class Contatto extends AceArcId implements Serializable {
        private static final long serialVersionUID = 1L;
    
        @Column(length=80)
        private String cognome;
    
        @Column(length=80)
        private String nome;
    
        @Column(length=80)
        private String appellativo;
    
        @Column()
        @Enumerated(EnumType.STRING)
        private Sesso sesso; 
    
        @Column()
        private Date dataNascita;
    
        @Column(length=80)
        private String luogoNascita;
    
        @Column(length=18)
        private String codiceFiscale;
    
        @Column(length=120)
        private String indirizzo;
    
        @Column(length=120)
        private String comune;
    
        @Column(length=120)
        private String cap;
    
        @Column(length=120)
        private String provincia;
    
        @Column(length=254)
        private String telefonoFisso;
    
        @Column(length=254)
        private String email;
    
        @Column(length=120)
        private String nazione;
    
        @Column(length=80)
        private String cittadinanza;
    
        @Column(length=80)
        private String professione; 
    
        @Column()
        private Date dataAccettazionePrivacy;
    
        @ManyToOne(fetch=FetchType.LAZY,optional=true) 
        //@DescriptionsList(descriptionProperties = "codice") 
        private Lingua linguaPreferita; 
    
        @ManyToOne(fetch=FetchType.LAZY,optional=true) 
        //@DescriptionsList(descriptionProperties = "codice") 
        private Lingua linguaAlternativa; 
    
        @OneToMany(mappedBy="contatto",cascade=CascadeType.REMOVE)
        //@ListProperties("tipo.abbreviazione,numero") 
        private Collection<DocumentoId> documenti; 
    
        @OneToMany(mappedBy="contatto",cascade=CascadeType.REMOVE)
        //@ListProperties("email,telefono") 
        private Collection<Recapito> altriRecapiti; 
    
        @OneToMany(mappedBy="contatto",cascade=CascadeType.REMOVE) 
        //@ListProperties("campo.codice, campo.inizio") // Thus the reference is displayed using a combo
        private Collection<Iscrizione> campiEdEventi; 
    
        @OneToMany(mappedBy="contatto",cascade=CascadeType.REMOVE) 
        //@ListProperties("ruolo.nome, incarico, inizio, fine") // Thus the reference is displayed using a combo
        private Collection<Collaborazione> collaborazioni; 
    
        @OneToMany(mappedBy="contatto",cascade=CascadeType.REMOVE) 
        //@ListProperties("ruolo.nome, incarico, inizio, fine") // Thus the reference is displayed using a combo
        private Collection<Ospite> ospite; 
    
        @Column()
        private Boolean vegetariano;
    
        @Column()
        private Boolean vegano;
    
        @Column()
        private Boolean noLatticini;
    
        @Column()
        private Boolean celiaco;
    
        @Column()
        private Boolean noMaiale;
    
        @Column(length=1000)
        @Stereotype("MEMO")
        private String altreIndicazioni;
    }
    

    Then I have a "Iscrizione" model like this:

    @Entity @Getter @Setter
    public class Iscrizione extends AceArcId implements Serializable {
    
        private static final long serialVersionUID = 1L;
    
        @ManyToOne(fetch=FetchType.LAZY, optional=false)
        @DescriptionsList(descriptionProperties = "cognome, email") 
        private Contatto contatto; 
    
        @ManyToOne(fetch=FetchType.LAZY,optional=false)
        @DescriptionsList(descriptionProperties = "codice, inizio")
        private Campo campo; 
    
        @Column()
        @Enumerated(EnumType.STRING)
        private RuoloIscrizione ruolo; 
    
        @Column()
        private Date dataIscrizione;
    
        @Column()
        private Date arrivo;
    
        @Column()
        private Date partenza;
    
        @Stereotype("MONEY")
        @Column()
        private Float quotaScelta;
    
        @Stereotype("MONEY")
        @Column()
        private Float quotaVersata;
    
        @Column()
        private Boolean autorizzazioneFoto;
    
        @Column()
        private Boolean arrivoInPullman;
    
        @Column()
        private Boolean partenzaInPullman;
    
        @Column()
        private Boolean accettaPrivacyPerQuestaIscrizione;
    
        @Column()
        private Boolean accettaPrivacyIndirizzario;
    
        @Column()
        private Boolean newsletterPerQuestaIscrizione;
    
        @Column(length=1000)
        @Stereotype("MEMO")
        private String note;
    
    }
    

    The MySQL database holds about 18K rows in the 'Contatto' table and a few dozen in 'Iscrizione' table. List view of both models do work with no problem, as does Contatto detail view. However when I try to create a new 'Iscrizione' entity by clicking the "Nuovo" button in the 'Iscrizione' list view, I get a window.alert() modal dialog that says "Invalid or unexpected token".

    The Eclipse console does not show any exceptions, while the browser console shows this:

    dwr-engine.js?ox=6.5:1310 console.trace
    dwr.engine._debug @ dwr-engine.js?ox=6.5:1310
    dwr.engine.defaultErrorHandler @ dwr-engine.js?ox=6.5:164
    dwr.engine._handleError @ dwr-engine.js?ox=6.5:1077
    dwr.engine._remoteHandleCallback @ dwr-engine.js?ox=6.5:918
    eval @ VM508:16
    dwr.engine._eval @ dwr-engine.js?ox=6.5:980
    dwr.engine._stateChange @ dwr-engine.js?ox=6.5:869
    batch.req.onreadystatechange @ dwr-engine.js?ox=6.5:646
    XMLHttpRequest.send (async)
    dwr.engine._sendData @ dwr-engine.js?ox=6.5:678
    dwr.engine.endBatch @ dwr-engine.js?ox=6.5:212
    dwr.engine._execute @ dwr-engine.js?ox=6.5:403
    Module.request @ Module.js?ox=6.5:13
    openxava.ajaxRequest @ openxava.js?ox=6.5:33
    openxava.executeAction @ openxava.js?ox=6.5:772
    openxava.executeActionConfirmLosesChangedData @ openxava.js?ox=6.5:751
    (anonymous) @ VM507:1
    dwr-engine.js?ox=6.5:1311 Error: SyntaxError, Invalid or unexpected token
    

    How do I find the cause?

     
  • Javier Paniza

    Javier Paniza - 2021-04-27

    Hi Lucio,

    Does it work if you change your browser language to English?
    Have you a custom controller for Iscrizione? If yes, put it here.

    Also put here your own i18n labels and messages.

    Try to remove all Iscrizione properties except note. Does it work? if yes, try to put back the properties one by one, until we find the guilty property.


    Help others in this forum as I help you.

     
    • Lucio Crusca

      Lucio Crusca - 2021-04-30

      Does it work if you change your browser language to English?

      no

      Have you a custom controller for Iscrizione?

      no

      Also put here your own i18n labels and messages.

      I have none

      Try to remove all Iscrizione properties except note. Does it work?
      if yes, try to put back the properties one by one, until we find the guilty property.

      After those tests I isolated the line of code that causes the problem:

      @DescriptionsList(descriptionProperties = "cognome, email") 
      

      if I comment out that line, the error doesn't show anymore. As soon as I remove the comment and put that line back into the code, the error shows up again.

       

      Last edit: Lucio Crusca 2021-04-30
  • Javier Paniza

    Javier Paniza - 2021-05-03

    Hi Lucio,

    Surely the problem is some character in the data that breaks the HTML, perhaps a <. I don't know

    Try only with cognome, thus:

    @DescriptionsList(descriptionProperties = "cognome") 
    private Contatto contatto;
    

    Does it fail?
    Then only with email:

    @DescriptionsList(descriptionProperties = "email") 
    private Contatto contatto;
    

    So we can figure out what is the culprit column. Then revise the data for that column looking for a strange character. If you don't find any, create a sample dataset with just 10 records that fails and attach here the records so I couldl revise them. Of course, don't use real names or emails for the sample.


    Help others in this forum as I help you.

     
  • Lucio Crusca

    Lucio Crusca - 2021-05-24

    I've now cleaned up cognome and email columns and here is the current status:

    MariaDB [acearc]>select uuid from Contatto where email like '%>%' or email like '%<%' or email like '%&%' or cognome like '%>%' or cognome like '%<%' or cognome like '%&%';
    Empty set (0.031 sec)

    However the 'Invalid or unexpected token' error still shows up.

    I'm absolutely convinced it's being caused by a problem with my data, but I don't know what to look for after <, > and &. Are there any other characters, such as non-ASCII accented letters or the like, that can cause the error? Manually looking through 17000+ records is not feasible, nor guessing a 10 records subset that contains the problematic data.

    Please note that those 17000+ records were imported by means of a LOAD DATA INFILE statement, from a CSV file, that in turn was a backup of a previous (very old) Postgresql database: I don't know if that makes any difference, but I'm sure most of the data didn't go through OX input validation.

     

    Last edit: Lucio Crusca 2021-05-25
  • Javier Paniza

    Javier Paniza - 2021-05-26

    Hi Lucio:

    Are there any other characters, such as non-ASCII accented letters or the like, that can cause the error?

    Look for " and '
    Look also for [ ] { } ,

    Although all the above character should be supported.

    through 17000+ records

    Such big dataset are not going to be performante with @DescriptionsList. @DescriptionsList only works nicely with small datasets, though this is something we want to improve in the future. The standard html combo (select) has also that problem given it load all the data into the page.

    Anyways, I'm interested in solve the issue with your data. If you could put here a file including the CSV for your data, with only the key and the cognom. Beware, in order that the key will not be a official person identifier (like dni), and only include the cognom, so it will be impossible to identify a real person from the data. Attach the file and I will try the find the bad characters.


    Help others in this forum as I help you.

     
  • Lucio Crusca

    Lucio Crusca - 2021-05-26

    Thanks for you support, but I can't attach the data here, since the problem is with the email field, not cognome (I tried setting to NULL all email values on a copy of my database and the error disappeared, while setting to NULL all cognome it kept showing up).

    Now I'm going to look for the other characters you mentioned. If I won't find any, I could send the data to you privately, if you want.

    EDIT: I couldn't find any of the characters you mentioned in the email field. Moreover, I checked all values of the email field against a regex that validates RFC 5322 syntax and they are all valid (regex found here).

    For the time being I removed the email field from my @DescriptionList, and I can live without it for a good while, but I'd like to see this solved sooner or later, just for the sake of it.

     

    Last edit: Lucio Crusca 2021-05-26
  • Javier Paniza

    Javier Paniza - 2021-05-28

    Hi Lucio:

    the problem is with the email field

    I just tried using emails in a @DescriptionsList and they work fine for me. Did you try usethe email field alone in the @DescriptionsList? Does it work in that case?

    I could send the data to you privately, if you want.

    No problem, you can send me the data privately. I'm interested in fix the issue.


    Help others in this forum as I help you.

     

Log in to post a comment.

MongoDB Logo MongoDB