QueryStringBindable for custom enumeration

I determined the type of enum Formatthat implements QueryStringBindable. I think I implemented it correctly, but in the routes file I cannot specify my type as a route parameter, because the compiler cannot find it, and I do not know how to import it into the routes file.

Here's the listing:

package web;

import java.util.Map;

import play.libs.F;
import play.mvc.QueryStringBindable;

public enum Format implements QueryStringBindable<Format> {
    Html,
    Pdf,
    Csv;

    private Format value;

    @Override
    public F.Option<Format> bind(String key, Map<String, String[]> data) {
        String[] vs = data.get(key);
        if (vs != null && vs.length > 0) {
            String v = vs[0];
            value = Enum.valueOf(Format.class, v);
            return F.Option.Some(value);
        }
        return F.Option.None();
    }

    @Override
    public String unbind(String key) {
        return key + "=" + value;
    }

    @Override
    public String javascriptUnbind() {
         return value.toString();
    }
}

And here is my route:

GET     /deposits                                    controllers.Deposits.index(selectedAccountKey: Long ?= 0, format: Format ?= Format.Html)

How can I tell the compiler about my listing? Thank!

Edit

I also tried adding the type path to Build.scala, as recommended in other posts:

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
  routesImport += "web.Format",
  resolvers += Resolver.url("My GitHub Play Repository", url("http://www.joergviola.de/releases/"))(Resolver.ivyStylePatterns)
)

I changed this and restarted my server, but it does not seem to make any difference.

+5
source share
2 answers

, , , , , .

PathBindable QueryStringBindable, , Bindable No Argument. enum Java.

, ( ) . Wrapper, QueryStringBindable PathBindable.

play framework -

+4

, .. web.Format

0

All Articles