Vladimir,
Price is a property of a domain object.
The whole code:
package dom.simple;
import javax.jdo.annotations.Column;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.identity.LongIdentity;
import org.apache.isis.applib.annotation.Bounded;
import org.apache.isis.applib.annotation.MemberOrder;
import org.apache.isis.applib.annotation.Title;
import org.apache.isis.applib.util.ObjectContracts;
@PersistenceCapable(identityType=IdentityType.APPLICATION,
objectIdClass=LongIdentity.class)
@Bounded
public class Category implements Comparable<Category> {
private Long id;
private String name;
private Double price;
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.NATIVE)
@Column(allowsNull="false")
@MemberOrder(sequence="1")
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Column(allowsNull="false")
@MemberOrder(sequence="2")
@Title(sequence="1")
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(allowsNull="false")
@MemberOrder(sequence="3")
public Double getPrice() {
return this.price;
}
public void setPrice(Double price) {
this.price = price;
}
public String validatePrice(Double price) {
if (price >= 0) {
return null;
} else {
return "The price must not be negative!";
}
}
@Override
public int compareTo(Category category) {
return ObjectContracts.compare(this, category, "id");
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Category other = (Category) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public String toString() {
return ObjectContracts.toString(this, "id,name,price");
}
}
Thank you.
Gabriel Malimpensa.
2015-05-30 11:41 GMT-03:00 Vladimir Nišević <[email protected]>:
> Hi ,Gabriel, is the price a property of domain object or action? Show us a
> whole class.
>
> Check
> http://isis.apache.org/how-tos/how-to-02-100-How-to-validate-user-input-for-a-property.html
> or
> http://isis.apache.org/how-tos/how-to-02-120-How-to-validate-an-action-parameter-argument.html
>
> lG,Vladimir
>
>
> > Am 30.05.2015 um 16:00 schrieb Gabriel Malimpensa <
> [email protected]>:
> >
> > Sorry for insist in this question, but I have tried many things and I
> can't
> > resolve. I have used the validate method for attributes in other systems
> I
> > have made, but this one I really don't know what is happening. Maybe
> > (propably) it's something stupid... =D
> >
> > Thank you for support.
> >
> > Gabriel Malimpensa.
> > São Carlos, São Paulo, Brazil.
> >
> > 2015-05-27 21:43 GMT-03:00 Gabriel Malimpensa <[email protected]>:
> >
> >> Hi.
> >>
> >> I've created a validate method for an attribute but when I insert the
> >> entity that contains such attribute, the validate is not called by the
> >> interface. I don't know what is wrong. Someone can help?
> >>
> >> Code:
> >> public String validatePrice(Double price) {
> >> if (price >= 0) {
> >> return null;
> >> } else {
> >> return "The price must not be negative!";
> >> }
> >> }
> >>
> >> Thanks.
> >>
> >> Gabriel Malimpensa.
> >> São Carlos, São Paulo, Brazil.
> >>
> >>
>