• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Formatters类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中play.data.format.Formatters的典型用法代码示例。如果您正苦于以下问题:Java Formatters类的具体用法?Java Formatters怎么用?Java Formatters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Formatters类属于play.data.format包,在下文中一共展示了Formatters类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: beforeInjection

import play.data.format.Formatters; //导入依赖的package包/类
/**
 * The initializations which are supposed to take place before anythingelse.
 */
protected void beforeInjection() {
    // Register the data types
    DataType.add(IFrameworkConstants.User, "framework.services.account.IUserAccount", false, false);
    DataType.add(IFrameworkConstants.SystemLevelRoleType, "models.framework_models.account.SystemLevelRoleType", false, false);
    // Register the play framework date formatter
    Formatters.register(Date.class, new AnnotationDateTypeFormatter());
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:11,代码来源:FrameworkModule.java


示例2: checkAddPerson

import play.data.format.Formatters; //导入依赖的package包/类
@Test
public void checkAddPerson() {
    // Easier to mock out the form factory inputs here
    MessagesApi messagesApi = mock(MessagesApi.class);
    Validator validator = mock(Validator.class);
    FormFactory formFactory = new FormFactory(messagesApi, new Formatters(messagesApi), validator);

    // Don't need to be this involved in setting up the mock, but for demo it works:
    PersonRepository repository = mock(PersonRepository.class);
    Person person = new Person();
    person.id = 1L;
    person.name = "Steve";
    when(repository.add(any())).thenReturn(supplyAsync(() -> person));

    // Set up the request builder to reflect input
    final Http.RequestBuilder requestBuilder = new Http.RequestBuilder().method("post").bodyJson(Json.toJson(person));

    // Add in an Http.Context here using invokeWithContext:
    final CompletionStage<Result> stage = invokeWithContext(requestBuilder, () -> {
        HttpExecutionContext ec = new HttpExecutionContext(ForkJoinPool.commonPool());

        // Create controller and call method under test:
        final PersonController controller = new PersonController(formFactory, repository, ec);
        return controller.addPerson();
    });

    // Test the completed result
    await().atMost(1, SECONDS).until(() ->
        assertThat(stage.toCompletableFuture()).isCompletedWithValueMatching(result ->
            result.status() == SEE_OTHER, "Should redirect after operation"
        )
    );
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:34,代码来源:UnitTest.java


示例3: checkAddPerson

import play.data.format.Formatters; //导入依赖的package包/类
@Test
public void checkAddPerson() {
    // Easier to mock out the form factory inputs here
    MessagesApi messagesApi = mock(MessagesApi.class);
    Validator validator = mock(Validator.class);
    FormFactory formFactory = new FormFactory(messagesApi, new Formatters(messagesApi), validator);

    // Don't need to be this involved in setting up the mock, but for demo it works:
    PersonRepository repository = mock(PersonRepository.class);
    Person person = new Person();
    person.id = 1L;
    person.name = "Steve";
    when(repository.add(any())).thenReturn(supplyAsync(() -> person));

    // Set up the request builder to reflect input
    final Http.RequestBuilder requestBuilder = new Http.RequestBuilder().method("post").bodyJson(Json.toJson(person));

    // Add in an Http.Context here using invokeWithContext:
    // XXX extending JavaHelpers is a cheat to get at JavaContextComponents easily, put this into helpers
    JavaContextComponents components = createContextComponents();
    final CompletionStage<Result> stage = Helpers.invokeWithContext(requestBuilder, components, () -> {
        HttpExecutionContext ec = new HttpExecutionContext(ForkJoinPool.commonPool());

        // Create controller and call method under test:
        final PersonController controller = new PersonController(formFactory, repository, ec);
        return controller.addPerson();
    });

    // Test the completed result
    await().atMost(1, SECONDS).until(() ->
        assertThat(stage.toCompletableFuture()).isCompletedWithValueMatching(result ->
            result.status() == SEE_OTHER, "Should redirect after operation"
        )
    );
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:36,代码来源:UnitTest.java


示例4: getSpeakers

import play.data.format.Formatters; //导入依赖的package包/类
/**
 * @return the list of user (because all the user can be speakers)
 */
public static List<String> getSpeakers() {
	List<User> 			list 	= 	User.find.where()
										.isNotNull("email")
										.orderBy("firstName asc")
										.findList();
			
	List<String> 		result 	= 	new ArrayList<String>( list.size() );
	
	for ( User currentUser : list ) {
		result.add( Formatters.print( currentUser ) );
	}
	
	return result;
}
 
开发者ID:sqlilabs,项目名称:WorkshopManager,代码行数:18,代码来源:UserRepository.java


示例5: players

import play.data.format.Formatters; //导入依赖的package包/类
@Restrict(@Group(Roles.ROLE_ADMIN))
public static Result players() {

	UserManagementService ums = new UserManagementImpl();
	final User loggedUser = ums.getLoggedUser(session());
	loggedUser.getRoles().isEmpty();

	Formatters.register(SecurityRole.class, new SecurityRoleFormatter());
	Form<User> filledForm = userForm.fill(loggedUser);

	return ok(views.html.admin.players.render(
			getUMS().getSessionLanguage(session()), User.find.all(),
			SecurityRole.find.all()));
}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:15,代码来源:Players.java


示例6: pathNpoints

import play.data.format.Formatters; //导入依赖的package包/类
public static Result pathNpoints() {

		Formatters.register(Point.class, new PointFormatter());

		if (GameHall.playground == null)
			GameHall.playground = PlaygroundUtils.getExistingPlaygrounds().get(2);

		return ok(views.html.admin.forms.render(getUMS()
				.getSessionLanguage(session()), GameHall.playground,
				PlaygroundUtils.getExistingPlaygrounds(), getPathEditForms(),
				pathNpointCreateForm));
	}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:13,代码来源:Playgrounds.java


示例7: profile

import play.data.format.Formatters; //导入依赖的package包/类
@SubjectPresent
public static Result profile() {
	final User localUser = getLocalUser(session());
	Formatters.register(SecurityRole.class, new SecurityRoleFormatter());
	Form<User> filledForm = userForm.fill(localUser);
	return ok(views.html.common.profile.render(localUser, filledForm,
			getConfiguredLanguages()));
}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:9,代码来源:Application.java


示例8: onStart

import play.data.format.Formatters; //导入依赖的package包/类
@Override
public void onStart(Application arg0) {	
	// add a formater which takes your field and convert it to the proper object
   	// this will be called automatically when you call bindFromRequest()
	Formatters.register(User.class, new UserFormatter());
}
 
开发者ID:sqlilabs,项目名称:WorkshopManager,代码行数:7,代码来源:Global.java


示例9: saveProfile

import play.data.format.Formatters; //导入依赖的package包/类
@SubjectPresent
	public static Result saveProfile() {
		
		Formatters.register(SecurityRole.class, new SecurityRoleFormatter());		
		
		// get data from HTTP request
		Form<User> filledForm = userForm.bindFromRequest();

		// in error case 400 bad request
		if (filledForm.hasErrors()) {
			final User localUser = getLocalUser(session());
			return badRequest(views.html.common.profile.render(localUser,
					filledForm, getConfiguredLanguages()));
		} else {
			// update user entity
			User newUserData = filledForm.get();
			final User authUser = getLocalUser(session());
			
			// update authUser does not work
			authUser.email = newUserData.email;
			authUser.name = newUserData.name;
			authUser.firstName = newUserData.firstName;
			authUser.lastName = newUserData.lastName;
			authUser.language = newUserData.language;
			authUser.description = newUserData.description;
			authUser.birthDate = newUserData.birthDate;
//			authUser.lastLogin = newUserData.lastLogin;
//			authUser.active = newUserData.active;
//			authUser.emailValidated = newUserData.emailValidated;
			
			// roles
			// change strange BeanList deferred behaviour > does not work
			authUser.roles.size();
			authUser.roles.clear();
			Ebean.saveManyToManyAssociations(authUser, User.ROLES);
			if(newUserData.roles!=null)
				for(SecurityRole newSecRole : newUserData.roles)				
					authUser.roles.add(newSecRole);
			Ebean.saveManyToManyAssociations(authUser, User.ROLES);
			
//			authUser.linkedAccounts = newUserData.linkedAccounts;
//			authUser.permissions = newUserData.permissions;			

			Ebean.save(Arrays.asList(new User[] { authUser }));
			
			// redirect
			return redirect(controllers.common.routes.Application.profile());
		}

	}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:51,代码来源:Application.java



注:本文中的play.data.format.Formatters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VariableResolverFactory类代码示例发布时间:2022-05-22
下一篇:
Java AreaMarker类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap