Gambo
Gambo

Reputation: 1572

Playframework: Dynamic Search Fields

I need to implement a search dialog within play but don't know to solve this. I have 3 integer fields in my database and want to search each of them with min and max values:

select * from office where maxSeats <= maxParamFromPage and maxSeats >= minParamFromPage ...

All fields are optional so if a user only enters the minParamFromPage all offices should be listed which are higher than this param. Now I have 3 params like maxSeats and I need to buildup my query dynamically based on the input parameters. I thought about replacing them with "0" or null when those are not entered but this is placed one to one in the sql query.

Can somebody help me on this?

Thank you!

Upvotes: 0

Views: 362

Answers (1)

basav
basav

Reputation: 1453

You should used JPA Criteria API to construct your criterion based on the form values.

Refer this example

Upvotes: 3

Related Questions