persistence@glassfish.java.net

RE: Split a filed in entity bean?

From: allpurpose <allpurpose.lu_at_gmail.com>
Date: Tue, 29 Jul 2008 07:21:16 -0700 (PDT)

Thanks a lot.
I am not sure if it is good to modify the entity bean which is generated
automatically by Toplink Mapping from the database? I think I need a wraper
for the entity bean or to extend the entity bean, just don't know where to
start.



djclarke wrote:
>
> One idea is to use 3 attributes and calculate the string within the domain
> class:
>
> @Entity
> public class Customer {
>
> private int id;
> private String name;
> private String firstName;
> private String lastName;
>
> @Id
> public int getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public String getName() {
> return name;
> }
>
> public void setName(String fullName) {
> this.name = fullName;
>
> if (fullName == null) {
> this.firstName = null;
> this.lastName = null;
> } else {
> String[] names = fullName.split(",");
> if (names.length != 2) {
> throw new IllegalStateException("Cannot parse names: " + fullName);
> }
> this.firstName = names[1];
> this.lastName = names[0];
> }
> }
>
> @Transient
> public String getFirstName() {
> return firstName;
> }
>
> public void setFirstName(String firstName) {
> this.firstName = firstName;
> this.name = getLastName() + "," + getFirstName();
> }
>
> @Transient
> public String getLastName() {
> return lastName;
> }
>
> public void setLastName(String lastName) {
> this.lastName = lastName;
> this.name = getLastName() + "," + getFirstName();
> }
>
> }
>
> Alternatively you can look at using a TransformationMapping, which we have
> annotation support for in EclipseLink.
>
> Doug
>
> -----Original Message-----
> From: allpurpose [mailto:allpurpose.lu_at_gmail.com]
> Sent: Tuesday, July 29, 2008 1:23 AM
> To: persistence_at_glassfish.dev.java.net
> Subject: Split a filed in entity bean?
>
>
>
> Hi,
> I am using JSF Sun RI and Toplink for ORM for web app.
>
> Would you tell me if there is a way to split a field in an entity bean and
> bind to 2 seperate web components? For example, customer entity mapping to
> an DB table customer which has name, address.... I retrieve a list of
> customers and need to split name into first name, last name and bind them
> seperately to 2 htmlOutputText? Also how to concatenate firstname and
> lastname entered back to name and persist customer object back to DB? Can
> this be achieved by only the entity bean and page backing bean?
>
> Not sure if this is the right place to ask. Thanks.
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Split-a-filed-in-entity-bean--tp18705557p18705557.html
> Sent from the java.net - glassfish persistence mailing list archive at
> Nabble.com.
>
>

-- 
View this message in context: http://www.nabble.com/Split-a-filed-in-entity-bean--tp18705557p18713285.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.