0

I'm using PlayFramework 2.2.1 and the below code is my Entity class which belongs to Model:

package models;

import java.util.Date;
import java.util.List;

import javax.persistence.*;
import javax.validation.*;

import com.avaje.ebean.annotation.*;
import controllers.Application.FindForm;  //this is a inner class for temporarily retaining a value from a form

import play.db.ebean.*;
import play.data.validation.*;
import play.data.validation.Constraints.*;

import controllers.Application.FindForm;
import play.data.Form;
import play.libs.F;
import play.mvc.Result;
import views.html.find;

@Entity
public class Message extends Model{

    @Id
    public Long id;

    @Required(message = "This item is required.")
    public String name;

    @Email(message = "Enter your email address")
    public String mail;

    @Required
    @MinLength(10)
    @MaxLength(200)
    @ValidateWith(value = IsUrl.class, message = "Fill in the message which starts URL")
    public String message;

    @CreatedTimestamp
    public Date postdata;

    public static Finder<Long, Message> find = 
                                    new Finder<Long, Message>(Long.class, Message.class);


    @Override
    public String toString() {
        return ("[id:" + id + ", name:" + name + ", mail:" + mail +
            ", message:" + message + ", data:" + postdata + "]");
    }

    public static class IsUrl extends Validator<String> {

        //this method is not strict, originally have to use regular expression.
        public boolean isValid(Stirng s) {
            return s.toLowerCase().startsWith("http://");
        }

        @Override
        public F.Tuple<String, Object[]> getErrorMessage() {
            return new F.Tuple<String, Object[]>("error.invalid", new String[]{});
        }
    }



}

There seem to be many questions related to this title in stackoverflow. And of all these questions, I think this might sound really relevant to my question.

How do I disambiguate in Scala between methods with vararg and without But if you see this question, you will easily understand they are discussing about method, not class. And now I am facing compilation error which says:

reference to Validator is ambiguous

In my expectation, this is derived from Scala code which exists deep inside of Framework. So, I have no idea what to do and I exhaustively googled about this error message, but the problem still remains.

What should I do?

Community
  • 1
  • 1
Kazuya Tomita
  • 667
  • 14
  • 34
  • 1
    maybe because you import both `import javax.validation.*;` and `import play.data.validation.*;` I guess that `import javax.validation.*;` is the one you need – Scary Wombat Oct 25 '16 at 02:11
  • Thank you for your comment. I tried what you sand, but still doesn't work well. Same compilation error message appeared. – Kazuya Tomita Oct 25 '16 at 02:28
  • When you use `Validator` in your code you may need to fully specify the package. – Scary Wombat Oct 25 '16 at 02:30
  • Sorry, I had done what you said incorrectly. And when I perfectly followed your advice, the error message changed. – Kazuya Tomita Oct 25 '16 at 02:33
  • "type Validator does not take parameters" compiler said. And I'm so sorry that I had separated my comment, still I'm not accustomed to the operation of stackoverflow. – Kazuya Tomita Oct 25 '16 at 02:35
  • maybe `IsUrl ` extends `play.data.validation.Constraints.Validator` ? – Scary Wombat Oct 25 '16 at 02:41
  • When I saw your comment, I immediately understood your intention. I just changed my code from "Validator" to "Constraint.Validator" after "extends". But, still compilation doesn't give me okay. The compiler says "cannot find symbol" toward "String" part of "public boolean isValid(Stirng s)". However, I don't understand at all because the compiler pointed out String, but String is already usable in all java class from scratch. Sorry for my persistent question. – Kazuya Tomita Oct 25 '16 at 02:52
  • You have spelt `String` wrong – Scary Wombat Oct 25 '16 at 02:53
  • Next problem came. The compiler says "cannot find symbol" to annotation part "@Required". This annotation is prepared in play.data.validation.Constraints class. By your advice, I integrated two import statements to one statement like this: import data.validation.*; Probably I have to add "import play.data.validation.Constraitns.*;" to my code, but if so the compiler would not be able to find validator class again. – Kazuya Tomita Oct 25 '16 at 03:05
  • Against my assumption, when I did add the import statement "import.data.validation.*; to my code, the compiler recognized Validator clearly. However, the compiler says: "IsUrl is not abstract and does not override abstract method getErrorMessageKey() in Validator" . But as you can see, I already override the getErrorMessageKey() method. What does it mean? – Kazuya Tomita Oct 25 '16 at 03:13
  • Sorry, I just had easy mistakes, now I can't use IDE for coding, so I tend to have such very easy mistakes, so sorry. – Kazuya Tomita Oct 25 '16 at 08:19
  • Gambatte - No need to apologize – Scary Wombat Oct 25 '16 at 08:22

1 Answers1

0

By Scary Wombat's useful comment, I could solve my problem. I no longer need any answer. Thank you so much, Scary.

Kazuya Tomita
  • 667
  • 14
  • 34