本文整理匯總了Java中play.data.DynamicForm類的典型用法代碼示例。如果您正苦於以下問題:Java DynamicForm類的具體用法?Java DynamicForm怎麽用?Java DynamicForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DynamicForm類屬於play.data包,在下文中一共展示了DynamicForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: grantUserPermission
import play.data.DynamicForm; //導入依賴的package包/類
@Restrict({@Group("ADMIN")})
public Result grantUserPermission() {
DynamicForm df = formFactory.form().bindFromRequest();
String permissionString = df.get("permission");
User user = Ebean.find(User.class, df.get("id"));
if (user == null) {
return notFound();
}
if (user.getPermissions().stream().noneMatch(p -> p.getValue().equals(permissionString))) {
Permission.Type type;
try {
type = Permission.Type.valueOf(permissionString);
} catch (IllegalArgumentException e) {
return badRequest();
}
Permission permission = Ebean.find(Permission.class).where().eq("type", type).findUnique();
user.getPermissions().add(permission);
user.update();
}
return ok();
}
示例2: revokeUserPermission
import play.data.DynamicForm; //導入依賴的package包/類
@Restrict({@Group("ADMIN")})
public Result revokeUserPermission() {
DynamicForm df = formFactory.form().bindFromRequest();
String permissionString = df.get("permission");
User user = Ebean.find(User.class, df.get("id"));
if (user == null) {
return notFound();
}
if (user.getPermissions().stream().anyMatch(p -> p.getValue().equals(permissionString))) {
Permission permission = Ebean.find(Permission.class).where()
.eq("type", Permission.Type.valueOf(permissionString))
.findUnique();
user.getPermissions().remove(permission);
user.update();
}
return ok();
}
示例3: createInspection
import play.data.DynamicForm; //導入依賴的package包/類
@Restrict({@Group("ADMIN"), @Group("TEACHER")})
public Result createInspection() {
DynamicForm df = formFactory.form().bindFromRequest();
Long examId = Long.parseLong(df.get("examId"));
Exam exam = Ebean.find(Exam.class, examId);
if (exam == null) {
return notFound("sitnet_error_exam_not_found");
}
if (exam.getLanguageInspection() != null) {
return forbidden("already sent for inspection");
}
if (!exam.getSubjectToLanguageInspection()) {
return forbidden("not allowed to send for inspection");
}
LanguageInspection inspection = new LanguageInspection();
User user = getLoggedUser();
AppUtil.setCreator(inspection, user);
inspection.setExam(exam);
inspection.save();
return ok();
}
示例4: registerExamWithoutRecord
import play.data.DynamicForm; //導入依賴的package包/類
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result registerExamWithoutRecord() throws IOException {
DynamicForm df = formFactory.form().bindFromRequest();
final Exam exam = Ebean.find(Exam.class)
.fetch("languageInspection")
.fetch("parent")
.fetch("parent.creator")
.where()
.idEq(Long.parseLong(df.get("id"))).findUnique();
return validateExamState(exam, false).orElseGet(() -> {
exam.setState(Exam.State.GRADED_LOGGED);
exam.setGrade(null);
exam.setGradeless(true);
exam.update();
return ok();
});
}
示例5: answerEssay
import play.data.DynamicForm; //導入依賴的package包/類
@ActionMethod
public Result answerEssay(String hash, Long questionId) {
return getEnrolmentError(hash).orElseGet(() -> {
DynamicForm df = formFactory.form().bindFromRequest();
String essayAnswer = df.get("answer");
ExamSectionQuestion question = Ebean.find(ExamSectionQuestion.class, questionId);
if (question == null) {
return forbidden();
}
EssayAnswer answer = question.getEssayAnswer();
if (answer == null) {
answer = new EssayAnswer();
} else if (df.get("objectVersion") != null) {
long objectVersion = Long.parseLong(df.get("objectVersion"));
answer.setObjectVersion(objectVersion);
}
answer.setAnswer(essayAnswer);
answer.save();
question.setEssayAnswer(answer);
question.save();
return ok(answer);
});
}
示例6: scoreExamQuestion
import play.data.DynamicForm; //導入依賴的package包/類
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result scoreExamQuestion(Long id) {
DynamicForm df = formFactory.form().bindFromRequest();
ExamSectionQuestion essayQuestion = Ebean.find(ExamSectionQuestion.class, id);
if (essayQuestion == null) {
return notFound("question not found");
}
EssayAnswer answer = essayQuestion.getEssayAnswer();
if (answer == null) {
// Question was not answered at all.
answer = new EssayAnswer();
answer.save();
essayQuestion.setEssayAnswer(answer);
essayQuestion.update();
}
String essayScore = df.get("evaluatedScore");
Double score = essayScore == null ? null : Double.parseDouble(essayScore);
answer.setEvaluatedScore(round(score));
answer.update();
return ok(Json.toJson(essayQuestion));
}
示例7: addInspectionComment
import play.data.DynamicForm; //導入依賴的package包/類
@Restrict({@Group("ADMIN"), @Group("TEACHER")})
public Result addInspectionComment(Long id) {
Exam exam = Ebean.find(Exam.class, id);
if (exam == null) {
return notFound("Inspection not found");
}
DynamicForm df = formFactory.form().bindFromRequest();
InspectionComment ic = new InspectionComment();
User user = getLoggedUser();
AppUtil.setCreator(ic, user);
AppUtil.setModifier(ic, user);
ic.setComment(df.get("comment"));
ic.setExam(exam);
ic.save();
return ok(ic, PathProperties.parse("(creator(firstName, lastName, email), created, comment)"));
}
示例8: saveShareRecord
import play.data.DynamicForm; //導入依賴的package包/類
public Result saveShareRecord() {
DynamicForm form = Form.form().bindFromRequest();
String userId = form.get("userId");
String appId = form.get("appId");
String url = form.get("url");
try {
ShareRecord shareRecord = new ShareRecord();
shareRecord.id = CodeGenerator.GenerateUUId();
shareRecord.app = Application.find.byId(appId);
shareRecord.appId = appId;
shareRecord.account = Account.find.byId(userId);
shareRecord.userId = userId;
shareRecord.share_url = url;
shareRecord.create_time = new Date();
Ebean.save(shareRecord);
return ok();
}
catch (Throwable e) {
Logger.info("erroR:" + e.getMessage());
}
return ok();
}
示例9: saveShareLog
import play.data.DynamicForm; //導入依賴的package包/類
public Result saveShareLog() {
DynamicForm form = Form.form().bindFromRequest();
String domain = form.get("domain");
String path = form.get("path");
String userId = form.get("userId");
String shareBy = form.get("SharedBy");
try {
ShareLog log = new ShareLog();
log.domain = domain;
log.path = path;
log.userId = userId;
log.shareBy = shareBy;
log.create_time = new Date();
Ebean.save(log);
}
catch (Throwable e) {
}
return ok();
}
示例10: createList
import play.data.DynamicForm; //導入依賴的package包/類
public Result createList() {
DynamicForm form = Form.form().bindFromRequest();
String contentId = form.data().get("contentId");
String choiceId = form.data().get("choiceId");
String[] choiceList = choiceId.split(",");
Status simpleResult = null;
for (String choice : choiceList) {
simpleResult = (Status)saveResult(new ActivityResult(), contentId, choice);
if (simpleResult.getWrappedSimpleResult().header().status() != 200) {
return simpleResult;
}
}
return ok();
}
示例11: login
import play.data.DynamicForm; //導入依賴的package包/類
public Result login() {
String header = request().getHeader("Origin");
header = (header == null ? "*" : header);
response().setHeader("Access-Control-Allow-Origin", header);
response().setHeader("Access-Control-Allow-Credentials", "true");
response().setHeader("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE,OPTIONS");
DynamicForm form = Form.form().bindFromRequest();
String userId = form.get("userId");
String appId = form.get("appId");
session("userId", userId);
session("appId", appId);
//Logger.info("from login: userId: " + userId + " appId: " + appId);
return ok();
}
示例12: errorsAsJson
import play.data.DynamicForm; //導入依賴的package包/類
@Test
public void errorsAsJson() {
running(fakeApplication(), new Runnable() {
@Override
public void run() {
Lang lang = new Lang(new play.api.i18n.Lang("en", ""));
Map<String, List<ValidationError>> errors = new HashMap<String, List<ValidationError>>();
List<ValidationError> error = new ArrayList<ValidationError>();
error.add(new ValidationError("foo", RequiredValidator.message, new ArrayList<Object>()));
errors.put("foo", error);
DynamicForm form = new DynamicForm(new HashMap<String, String>(), errors, F.None());
JsonNode jsonErrors = form.errorsAsJson(lang);
assertThat(jsonErrors.findPath("foo").iterator().next().asText()).isEqualTo(play.i18n.Messages.get(lang, RequiredValidator.message));
}
});
}
示例13: getSearchParams
import play.data.DynamicForm; //導入依賴的package包/類
public static Map<String, String> getSearchParams() {
Map<String, String> searchParams = new HashMap<String, String>();
DynamicForm form = Form.form().bindFromRequest(request());
String username = form.get(USERNAME);
username = username != null ? username.trim().toLowerCase() : null;
searchParams.put(USERNAME, username);
String queuename = form.get(QUEUE_NAME);
queuename = queuename != null ? queuename.trim().toLowerCase() : null;
searchParams.put(QUEUE_NAME, queuename);
searchParams.put(SEVERITY, form.get(SEVERITY));
searchParams.put(JOB_TYPE, form.get(JOB_TYPE));
searchParams.put(ANALYSIS, form.get(ANALYSIS));
searchParams.put(FINISHED_TIME_BEGIN, form.get(FINISHED_TIME_BEGIN));
searchParams.put(FINISHED_TIME_END, form.get(FINISHED_TIME_END));
searchParams.put(STARTED_TIME_BEGIN, form.get(STARTED_TIME_BEGIN));
searchParams.put(STARTED_TIME_END, form.get(STARTED_TIME_END));
return searchParams;
}
示例14: getHelp
import play.data.DynamicForm; //導入依賴的package包/類
/**
* Returns the help based on the version
*
* @param version The version for which help page has to be returned
* @return The help page based on the version
*/
private static Result getHelp(Version version) {
DynamicForm form = Form.form().bindFromRequest(request());
String topic = form.get("topic");
Html page = null;
String title = "Help";
if (topic != null && !topic.isEmpty()) {
// check if it is a heuristic help
page = ElephantContext.instance().getHeuristicToView().get(topic);
// check if it is a metrics help
if (page == null) {
page = getMetricsNameView().get(topic);
}
if (page != null) {
title = topic;
}
}
if (version.equals(Version.NEW)) {
return ok(helpPage.render(title, page));
}
return ok(oldHelpPage.render(title, page));
}
示例15: createTimeOff
import play.data.DynamicForm; //導入依賴的package包/類
@RequiresAuthentication(clientName = "default")
public Result createTimeOff() throws Exception {
// Load user from session
CommonProfile profile = getUserProfile();
int userId = Integer.parseInt(profile.getId());
// Bind request parameters
DynamicForm form = Form.form().bindFromRequest();
String comment = form.get("comment");
TimeOffType type = TimeOffType.valueOf(form.get("type"));
DateTime from = DateTimeUtils.stringToDateTime(form.get("from"));
DateTime to = DateTimeUtils.endOfDay(DateTimeUtils.stringToDateTime(form.get("to")));
// Call business logic
createTimeOffForGivenType(userId, type, from, to, comment);
return redirect(routes.TimeOffController.index());
}