Search code examples
scalaviewplayframework-2.1controllers

Issue in receiving parameter from controller functions to a view page


I am getting error while trying to receive values in view from controller. In controllers I am using two functions. Both functions return a value to view page

Here is the example:

public static Result home() {

    Identity user = (Identity) ctx().args.get(SecureSocial.USER_KEY);
String userEmail = user.email().isDefined() ? user.email().get() : "Not available";
System.out.println("Logged in - "+  userEmail);
String emailCheck = userEmail.substring(userEmail.indexOf("@") + 1, userEmail.length());
emailCheck = emailCheck.substring(0, emailCheck.indexOf("."));

    if (emailCheck.matches(Messages.get("emailCheckAll"))) {
        return ok(home.render(user));
    }

    public static Result getId() {
        Map<String, String[]> parameters = request().body().asFormUrlEncoded();
        String EAN_code= parameters.get("truckid")[0].trim();
        List<Truck> isvalid= Truck.findTruckId(EAN_code);
        System.out.println(EAN_code);
        System.out.println(isvalid.get(0));
        BigInteger qty=Truck.getTruckQuantity(EAN_code);
        return ok(home.render(qty.toString()));
    }

In home.scala.html i am trying to receive like

@(user : securesocial.core.Identity)
(qty:String)
@import securesocial.core.IdentityProvider 
@import Http.Context.Implicit 

but I can't get value from the qty. But I have the value in the controllers. The same value not go to view. Please anyone help me. It shows me error in scala file "value qty not found"...


Solution

  • You've declared your view as having two parameter lists:

    @(user : securesocial.core.Identity) (qty:String)

    You're only satisfying one of them when you call the view.

    ok(home.render(qty.toString()))

    Try:

    ok(home.render(user)(qty.toString()))