Skip to content

Commit 9683d6a

Browse files
author
Reza Rahman
committed
Adding validation
1 parent 2dce115 commit 9683d6a

5 files changed

Lines changed: 69 additions & 41 deletions

File tree

actionbazaar/src/main/java/com/actionbazaar/domain/Bid.java

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,68 +37,76 @@
3737
* only if the new code is made subject to such option by the copyright
3838
* holder.
3939
*/
40-
4140
package com.actionbazaar.domain;
4241

4342
import java.io.Serializable;
44-
4543
import javax.persistence.Entity;
4644
import javax.persistence.GeneratedValue;
4745
import javax.persistence.Id;
4846
import javax.persistence.Table;
47+
import javax.validation.constraints.Min;
48+
import javax.validation.constraints.NotNull;
49+
import javax.validation.constraints.Size;
4950
import javax.xml.bind.annotation.XmlRootElement;
5051

5152
@Entity
5253
@Table(name = "BIDS")
5354
@XmlRootElement
5455
public class Bid implements Serializable {
55-
private static final long serialVersionUID = 1L;
5656

57-
@Id
58-
@GeneratedValue
59-
private Long id;
57+
private static final long serialVersionUID = 1L;
58+
59+
@Id
60+
@GeneratedValue
61+
private Long id;
6062

61-
private String bidder;
63+
@NotNull(message = "Bidder name must not be null")
64+
@Size(min = 5, max = 15, message = "Bidder name must be between 5 and 15 characters")
65+
private String bidder;
6266

63-
private String item;
67+
@NotNull(message = "Item name must not be null")
68+
@Size(min = 5, max = 110, message = "Item name must be between 5 and 110 characters")
69+
private String item;
6470

65-
private Double amount;
71+
@NotNull(message = "Bid amount must not be null")
72+
@Min(value = 0, message = "Bid amount must not be negative")
73+
private Double amount;
6674

67-
public Long getId() {
68-
return id;
69-
}
75+
public Long getId() {
76+
return id;
77+
}
7078

71-
public void setId(Long id) {
72-
this.id = id;
73-
}
79+
public void setId(Long id) {
80+
this.id = id;
81+
}
7482

75-
public String getBidder() {
76-
return bidder;
77-
}
83+
public String getBidder() {
84+
return bidder;
85+
}
7886

79-
public void setBidder(String bidder) {
80-
this.bidder = bidder;
81-
}
87+
public void setBidder(String bidder) {
88+
this.bidder = bidder;
89+
}
8290

83-
public String getItem() {
84-
return item;
85-
}
91+
public String getItem() {
92+
return item;
93+
}
8694

87-
public void setItem(String item) {
88-
this.item = item;
89-
}
95+
public void setItem(String item) {
96+
this.item = item;
97+
}
9098

91-
public Double getAmount() {
92-
return amount;
93-
}
99+
public Double getAmount() {
100+
return amount;
101+
}
94102

95-
public void setAmount(Double amount) {
96-
this.amount = amount;
97-
}
103+
public void setAmount(Double amount) {
104+
this.amount = amount;
105+
}
98106

99-
@Override
100-
public String toString() {
101-
return "Bid [id=" + id + ", bidder=" + bidder + ", item=" + item
102-
+ ", amount=" + amount + "]";
103-
}
104-
}
107+
@Override
108+
public String toString() {
109+
return "Bid [id=" + id + ", bidder=" + bidder + ", item=" + item
110+
+ ", amount=" + amount + "]";
111+
}
112+
}

actionbazaar/src/main/java/com/actionbazaar/interfaces/web/AddBid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public class AddBid implements Serializable {
2525
public String onAdd() {
2626
bidService.addBid(bid);
2727

28-
return "confirm_bid.jsf";
28+
return "confirm_add_bid.jsf";
2929
}
3030
}

actionbazaar/src/main/webapp/add_bid.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<h:body>
99
<h1>Add Bid</h1>
1010
<h:form id="bidForm">
11+
<h:messages errorStyle="color: red"/>
1112
<h:panelGrid columns="2">
1213
<h:outputLabel for="item">Item name:</h:outputLabel>
1314
<h:inputText id="itemTextField" value="#{bid.item}" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:h="http://java.sun.com/jsf/html">
5+
<h:head>
6+
<title>Action Bazaar</title>
7+
</h:head>
8+
<h:body>
9+
<h1>Bid Added</h1>
10+
<h:panelGrid columns="2">
11+
<h:outputLabel for="item">Item name:</h:outputLabel>
12+
<h:outputText id="itemField" value="#{bid.item}" />
13+
<h:outputLabel for="bidder">Bidder name:</h:outputLabel>
14+
<h:outputText id="bidderField" value="#{bid.bidder}" />
15+
<h:outputLabel for="amount">Bid amount:</h:outputLabel>
16+
<h:outputText id="amountField" value="#{bid.amount}" />
17+
</h:panelGrid>
18+
</h:body>
19+
</html>

actionbazaar/src/test/java/com/actionbazaar/interfaces/web/AddBidTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static Archive<?> createDeployment() {
3838
AddBid.class)
3939
.addAsWebInfResource("test-web.xml", "web.xml")
4040
.addAsWebResource("add_bid.xhtml", "add_bid.xhtml")
41-
.addAsWebResource("confirm_bid.xhtml", "confirm_bid.xhtml")
41+
.addAsWebResource("confirm_add_bid.xhtml", "confirm_add_bid.xhtml")
4242
.addAsWebInfResource("test-faces-config.xml",
4343
"faces-config.xml")
4444
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")

0 commit comments

Comments
 (0)