public static Result function(){ DynamicForm dynamicForm = DynamicForm.form().bindFromRequest(); String serial1 = dynamicForm.get("firstSerial"); String serial2 = dynamicForm.get("secondSerial"); //Do something with serial1 and serial2, like redirect to a new controller, //render a custom template, save in a database, or process //any other way you need. }
public static Result createMessages(){ DynamicForm df = play.data.Form.form().bindFromRequest(); String from = df.get("from"); String subject = df.get("subject"); String message = df.get("message"); if(from != null && subject != null && message != null){ Message.create(from, subject, message); return ok(toJson("ok")); } else { return ok(toJson("error")); } }
public static Result index() { DynamicForm requestData = Form.form().bindFromRequest(); String name = requestData.get("name"); return ok(name); }
public static Result addText() { DynamicForm df = form.bindFromRequest(); String txt = df.get("txt"); return ok(...); }
public static Result check() { DynamicForm myForm = form().bindFromRequest(); String dict = myForm.get("recieved"); // convert the string to your Dictionary object ... }
public static Result saySomething(){ DynamicForm df = form().bindFromRequest(); return("you entered :" + df.get("email")); }
public class FooController { private final FormFactory formFactory; @Inject public FooController(final FormFactory formFactory) { this.formFactory = formFactory; } public Result hello() { DynamicForm requestData = formFactory.form().bindFromRequest(); String firstname = requestData.get("firstname"); String lastname = requestData.get("lastname"); return ok("Hello " + firstname + " " + lastname); } }
public static Result aboutAMan() { DynamicForm df = form().bindFromRequest(); int age; String name; boolean isAdmin; name = (df.get("name") != null) ? df.get("name") : "The Unknown"; age = (df.get("age") != null) ? Integer.parseInt(df.get("age")) : 0; isAdmin = Boolean.parseBoolean(df.get("is_admin")); String about = (name + " is " + age + " years old and " + ((isAdmin) ? "is" : "isn't") + " an admin"); return ok(about); }
import play.data.DynamicForm; import play.data.Form; public static Result cadastraPedidoNoBanco() { DynamicForm form = Form.form().bindFromRequest(); if (form.data().size() == 0) { return badRequest("Expceting some data"); } else { String response = "Client " + form.get("nome_cliente") + "has phone number " + form.get("telefone_cliente"); return ok(response); } }
public static Result save() { DynamicForm df = form().bindFromRequest(); String value = df.get("video"); if (value == null || value.trim().equals("")) return badRequest("Video param was not sent"); // do something with the value return ok(value); }
public static Result someMethod(){ DynamicForm dynamicForm = form().bindFromRequest(); return otherMethod(dynamicForm); } public static Result otherMethod(DynamicForm dataFromPrevRequest) { String someField = dataFromPrevRequest.get("some_field"); Logger.info("field from request is: " + someField); return ok("Other method's Result"); }
DynamicForm form = new DynamicForm().form().bindFromRequest(); if(form.get("board") == null) { // do something }
/** * Gets the concrete value if the submission was a success. */ public String get(String key) { try { return (String)get().getData().get(asNormalKey(key)); } catch(Exception e) { return null; } }
/** * Gets the concrete value if the submission was a success. */ public String get(String key) { try { return (String)get().getData().get(asNormalKey(key)); } catch(Exception e) { return null; } }
protected boolean isBillingDifferent() { final String flagFieldName = "billingAddressDifferentToBillingAddress"; final String fieldValue = formFactory().form().bindFromRequest().get(flagFieldName); return "true".equals(fieldValue); }
/** * Retrieves a field. * * @param key field name * @return the field - even if the field does not exist you get a field */ public Field field(String key) { Field field = super.field(asDynamicKey(key)); return new Field(this, key, field.constraints(), field.format(), field.errors(), field.value() == null ? get(key) : field.value() ); }