Ducaz035
Ducaz035

Reputation: 3132

Play Framework Multiple QueryStrings

I can get one queryString from the template however, never managed to get two. This is my controller

  def get = Action { implicit request =>
    val requestedProviderName = request getQueryString "providerName"
    val requestedReleaseId = request getQueryString "releaseId"
}

Like that my router produces

Here is my router.conf : http://localhost:9000/fail?providerName=oneProviderName this is all correct but I want to pass more than one option.

GET /fail                                 @controllers.mycontroller.get

What I have as a view is so basic,

@helper.form(routes.mycontroller.get)  {
<select name="providerName" class="selectpicker" data-live-search="true">
    @for((providerName, failedReleasesNumber) <- providers){
    <option id="selectedvalue" value="@providerName" selected="selected">
        @providerName, @failedReleasesNumber
    </option>
    }
</select>

<div class="row-fluid">
    <div class="span6">
        <label>Start Date: <input type="date" id="startDate"></label>
        <label>End Date: <input type="date" id="endDate"></label>
        <label>Release Id: <input type="number" id="releaseId"></label>
        <label>Results Start?!: <input type="number" id="resultStart"></label>
        <label>Max Results: <input type="number" id="maxResults"></label>

        <input type="submit" class="btn btn-primary" value="Get Failed Releases" style="margin-top:-10px">
    </div>
</div>
}

My question is more, how I can define these inputs as I want them to be in the QueryPath. I have searched the web however, couldn't find a solution. Everyone written stuff about router but how to define them in template is unanswered or I am missing something completely. I am using Play Framework 2.1.1 with Scala

Upvotes: 1

Views: 417

Answers (2)

Ducaz035
Ducaz035

Reputation: 3132

Well I have found my answer, as it is answered before the operation should be GET

However, e.g.

<input type="number" name="maxResults" id="maxResults"> Just id of input field is not enough thus, there should be name field as well and after everything is okay. Even there is no need for input variables to the functions. You can get the variables like

val requestedProviderName = request getQueryString "providerName"

Which returns an optional value of input variable in the template(view).

Upvotes: 1

user3366706
user3366706

Reputation: 1599

For question 1:

To use url like http://localhost:9000/fail?providerName="xyz"&secondQueryString="abc" define like this in routes file

GET /fail controllers.mycontroller.get(providerName: String, secondQueryString: String)

and modify get method signature like get(providerName: String, secondQueryString: String)

For question 2:

When the form action is defined for GET method then by default all the input fields will be passed in query string. Just ensure using same query string names defined for url path (in routes file) and the name used in the html file.

Upvotes: 2

Related Questions