vraptor-form

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

Categories

Categories

ORM Data
GroupId

GroupId

br.com.caelum.vraptor
ArtifactId

ArtifactId

vraptor-form
Last Version

Last Version

4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

vraptor-form
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

http://github.com/asouza/vraptor-form

Download vraptor-form

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-form/ -->
<dependency>
    <groupId>br.com.caelum.vraptor</groupId>
    <artifactId>vraptor-form</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-form/
implementation 'br.com.caelum.vraptor:vraptor-form:4.0.0'
// https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-form/
implementation ("br.com.caelum.vraptor:vraptor-form:4.0.0")
'br.com.caelum.vraptor:vraptor-form:jar:4.0.0'
<dependency org="br.com.caelum.vraptor" name="vraptor-form" rev="4.0.0">
  <artifact name="vraptor-form" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.caelum.vraptor', module='vraptor-form', version='4.0.0')
)
libraryDependencies += "br.com.caelum.vraptor" % "vraptor-form" % "4.0.0"
[br.com.caelum.vraptor/vraptor-form "4.0.0"]

Dependencies

compile (8)

Group / Artifact Type Version
br.com.caelum : vraptor jar 4.0.0.Final
org.jboss.weld.servlet : weld-servlet jar 2.1.1.Final
org.jboss.weld.se : weld-se-core jar 2.1.1.Final
ognl : ognl jar 3.0.8
org.objenesis : objenesis jar 2.1
log4j : log4j jar 1.2.17
org.slf4j : slf4j-log4j12 jar 1.7.5
org.hibernate : hibernate-validator Optional jar 5.0.0.Final

provided (5)

Group / Artifact Type Version
org.mortbay.jetty : servlet-api jar 3.0.20100224
org.glassfish.web : javax.el jar 2.2.4
javax.validation : validation-api jar 1.1.0.Final
javax.servlet : jstl jar 1.2
javax.servlet.jsp : jsp-api jar 2.2

test (4)

Group / Artifact Type Version
junit : junit jar 4.8.2
org.mockito : mockito-core jar 1.8.5
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

#VRaptor-form

#Installing

Add to your pom:

    <dependency>
    	<groupId>br.com.caelum.vraptor</groupId>
    	<artifactId>vraptor-form</artifactId>
    	<version>4.0.0-SNAPSHOT</version>
    </dependency>
    

#Basic validation and mass assignment protection

@Controller
public class UsersController {
  @Inject
	private Form<User> userForm;
	  
	public void add(User user) {  
	  userForm.bind(user);
	  userForm.navigate().onErrorUsePageOf(HomeController.class).index();
	  
	  //rest of the code here
  }
}

If you need to protect against Mass assignment, you can use hasBlackListedFields or hasOnlyAllowedFields.

    public void add(User user) {  
      userForm.bind(user);
      
  		if (userForm.hasBlackListedFields("user.admin")) {
  			userForm.reject("invalid.params", "Invalid paramters came from your form");
  		}
      
      
      userForm.navigate().onErrorUsePageOf(HomeController.class).index();
  
      //rest of the code here
    }

#Errors in your view

    <c:if test="${form.hasErrors()}">
    	<div class="alert alert-danger">
    		<button type="button" class="close" data-dismiss="alert">&times;</button>
    		<c:forEach items="${form.allErrors}" var="error">
    			<b><fmt:message key="${error.category}" /></b> - ${error.message}
    		</c:forEach>
    	</div>
    </c:if>

If you need, you can access specific field errors:

  ${userForm.get("login").getErrors()}

Versions

Version
4.0.0