Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge branch 'play-2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennifer Hickey and Maria Shaldibina committed Feb 23, 2013
2 parents b4b39da + ac87019 commit 5802654
Show file tree
Hide file tree
Showing 308 changed files with 548 additions and 385 deletions.
Expand Up @@ -12,7 +12,7 @@
<plugin>
<groupId>de.akquinet.innovation.play2</groupId>
<artifactId>play2-maven-plugin</artifactId>
<version>1.0.1</version>
<version>1.2.1</version>
<extensions>true</extensions>
</plugin>
</plugins>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -5,6 +5,7 @@
import play.*;
import play.mvc.*;
import play.data.*;
import static play.data.Form.*;
import play.db.jpa.*;

import views.html.*;
Expand All @@ -15,14 +16,14 @@
* Manage a database of computers
*/
public class Application extends Controller {

/**
* This result directly redirect to application home.
*/
public static Result GO_HOME = redirect(
routes.Application.list(0, "name", "asc", "")
);

/**
* Handle default path requests, redirect to computers list
*/
Expand All @@ -47,7 +48,7 @@ public static Result list(int page, String sortBy, String order, String filter)
)
);
}

/**
* Display the 'edit form' of a existing Computer.
*
Expand All @@ -62,9 +63,9 @@ public static Result edit(Long id) {
editForm.render(id, computerForm)
);
}

/**
* Handle the 'edit form' submission
* Handle the 'edit form' submission
*
* @param id Id of the computer to edit
*/
Expand All @@ -78,7 +79,7 @@ public static Result update(Long id) {
flash("success", "Computer " + computerForm.get().name + " has been updated");
return GO_HOME;
}

/**
* Display the 'new computer form'.
*/
Expand All @@ -89,9 +90,9 @@ public static Result create() {
createForm.render(computerForm)
);
}

/**
* Handle the 'new computer form' submission
* Handle the 'new computer form' submission
*/
@Transactional
public static Result save() {
Expand All @@ -103,7 +104,7 @@ public static Result save() {
flash("success", "Computer " + computerForm.get().name + " has been created");
return GO_HOME;
}

/**
* Handle computer deletion
*/
Expand All @@ -113,6 +114,7 @@ public static Result delete(Long id) {
flash("success", "Computer has been deleted");
return GO_HOME;
}


}

Expand Up @@ -3,7 +3,6 @@
import java.util.*;
import javax.persistence.*;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;

Expand All @@ -12,15 +11,15 @@
/**
* Company entity managed by JPA
*/
@Entity
@Entity
public class Company {

@Id
public Long id;

@Constraints.Required
public String name;

public static Company findById(Long id) {
return JPA.em().find(Company.class, id);
}
Expand All @@ -35,3 +34,4 @@ public static Map<String,String> options() {
}

}

Expand Up @@ -3,7 +3,6 @@
import java.util.*;
import javax.persistence.*;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;

Expand All @@ -12,33 +11,33 @@
/**
* Computer entity managed by JPA
*/
@Entity
@Entity
@SequenceGenerator(name = "computer_seq", sequenceName = "computer_seq")
public class Computer {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "computer_seq")
public Long id;

@Constraints.Required
public String name;

@Formats.DateTime(pattern="yyyy-MM-dd")
public Date introduced;

@Formats.DateTime(pattern="yyyy-MM-dd")
public Date discontinued;

@ManyToOne(cascade = CascadeType.MERGE)
public Company company;

/**
* Find a company by id.
*/
public static Computer findById(Long id) {
return JPA.em().find(Computer.class, id);
}

/**
* Update this computer.
*/
Expand All @@ -51,7 +50,7 @@ public void update(Long id) {
this.id = id;
JPA.em().merge(this);
}

/**
* Insert this new computer.
*/
Expand All @@ -64,14 +63,14 @@ public void save() {
this.id = id;
JPA.em().persist(this);
}

/**
* Delete this computer.
*/
public void delete() {
JPA.em().remove(this);
}

/**
* Return a page of computer
*
Expand All @@ -95,50 +94,51 @@ public static Page page(int page, int pageSize, String sortBy, String order, Str
.getResultList();
return new Page(data, total, page, pageSize);
}

/**
* Used to represent a computers page.
*/
public static class Page {

private final int pageSize;
private final long totalRowCount;
private final int pageIndex;
private final List<Computer> list;

public Page(List<Computer> data, long total, int page, int pageSize) {
this.list = data;
this.totalRowCount = total;
this.pageIndex = page;
this.pageSize = pageSize;
}

public long getTotalRowCount() {
return totalRowCount;
}

public int getPageIndex() {
return pageIndex;
}

public List<Computer> getList() {
return list;
}

public boolean hasPrev() {
return pageIndex > 1;
}

public boolean hasNext() {
return (totalRowCount/pageSize) >= pageIndex;
}

public String getDisplayXtoYofZ() {
int start = ((pageIndex - 1) * pageSize + 1);
int end = start + Math.min(pageSize, list.size()) - 1;
return start + " to " + end + " of " + totalRowCount;
}

}

}

Expand Up @@ -2,35 +2,35 @@

@import helper._

@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.render) }
@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.render) }

@main {

<h1>Add a computer</h1>

@form(routes.Application.save()) {

<fieldset>

@inputText(computerForm("name"), '_label -> "Computer name")
@inputText(computerForm("introduced"), '_label -> "Introduced date")
@inputText(computerForm("discontinued"), '_label -> "Discontinued date")

@select(
computerForm("company.id"),
options(Company.options),
computerForm("company.id"),
options(Company.options),
'_label -> "Company", '_default -> "-- Choose a company --",
'_showConstraints -> false
)


</fieldset>

<div class="actions">
<input type="submit" value="Create this computer" class="btn primary"> or
<a href="@routes.Application.list()" class="btn">Cancel</a>
<input type="submit" value="Create this computer" class="btn primary"> or
<a href="@routes.Application.list()" class="btn">Cancel</a>
</div>

}

}
}
Expand Up @@ -2,38 +2,38 @@

@import helper._

@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.render) }
@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.render) }

@main {

<h1>Edit computer</h1>

@form(routes.Application.update(id)) {

<fieldset>

@inputText(computerForm("name"), '_label -> "Computer name")
@inputText(computerForm("introduced"), '_label -> "Introduced date")
@inputText(computerForm("discontinued"), '_label -> "Discontinued date")

@select(
computerForm("company.id"),
options(Company.options),
computerForm("company.id"),
options(Company.options),
'_label -> "Company", '_default -> "-- Choose a company --",
'_showConstraints -> false
)

</fieldset>

<div class="actions">
<input type="submit" value="Save this computer" class="btn primary"> or
<a href="@routes.Application.list()" class="btn">Cancel</a>
<input type="submit" value="Save this computer" class="btn primary"> or
<a href="@routes.Application.list()" class="btn">Cancel</a>
</div>

}

@form(routes.Application.delete(id), 'class -> "topRight") {
<input type="submit" value="Delete this computer" class="btn danger">
}

}

0 comments on commit 5802654

Please sign in to comment.