HOW TO MANAGE AUTO GENERATED COLUMNS
sadiquekatihar Sep 18, 2010 12:20 PMi have an entity class generate by seam generate command for CRUD APPLICATION.and there its correspondence id column is in my JSF page .
in this entity there is primary key id i want to use this column as a auto generated value. and i want to remove the id column from JSF facelete page that should be auto generate by application.
can any one suggest me how i customize my code for this.
here is my entity, session and jsf code.
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
/**
* AuthenticationInformation generated by hbm2java
*/
@Entity
@Table(name = "authentication_information")
public class AuthenticationInformation implements java.io.Serializable {
private int id;
private Person person;
private String openid;
private String openidProvider;
private String firstName;
private String lastName;
private String phoneNumber;
private String email;
private String password;
private Date createDate;
private Date lastUpdtDate;
private String createUserId;
private String lastUpdtUserId;
private String activationKey;
private Long createdOn;
private Boolean active;
public AuthenticationInformation() {
}
public AuthenticationInformation(int id, Person person) {
this.id = id;
this.person = person;
}
public AuthenticationInformation(int id, Person person, String openid,
String openidProvider, String firstName, String lastName,
String phoneNumber, String email, String password, Date createDate,
Date lastUpdtDate, String createUserId, String lastUpdtUserId,
String activationKey, Long createdOn, Boolean active) {
this.id = id;
this.person = person;
this.openid = openid;
this.openidProvider = openidProvider;
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.email = email;
this.password = password;
this.createDate = createDate;
this.lastUpdtDate = lastUpdtDate;
this.createUserId = createUserId;
this.lastUpdtUserId = lastUpdtUserId;
this.activationKey = activationKey;
this.createdOn = createdOn;
this.active = active;
}
@Id
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "person_sequence_number", nullable = false)
@NotNull
public Person getPerson() {
return this.person;
}
public void setPerson(Person person) {
this.person = person;
}
@Column(name = "openid", length = 50)
@Length(max = 50)
public String getOpenid() {
return this.openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
@Column(name = "openid_provider", length = 50)
@Length(max = 50)
public String getOpenidProvider() {
return this.openidProvider;
}
public void setOpenidProvider(String openidProvider) {
this.openidProvider = openidProvider;
}
@Column(name = "first_name", length = 50)
@Length(max = 50)
@Pattern(regex = "^[a-zA-Z\\d_]{4,12}$",message = "{invalid_screen_name}")
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name = "last_name", length = 50)
@Length(max = 50)
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name = "phone_number", length = 50)
@Length(max = 50)
public String getPhoneNumber() {
return this.phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Column(name = "email", length = 50)
@Length(max = 50)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "password", length = 50)
@Length(max = 50)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Temporal(TemporalType.DATE)
@Column(name = "create_date", length = 13)
public Date getCreateDate() {
return this.createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
@Temporal(TemporalType.DATE)
@Column(name = "last_updt_date", length = 13)
public Date getLastUpdtDate() {
return this.lastUpdtDate;
}
public void setLastUpdtDate(Date lastUpdtDate) {
this.lastUpdtDate = lastUpdtDate;
}
@Column(name = "create_user_id", length = 50)
@Length(max = 50)
public String getCreateUserId() {
return this.createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId;
}
@Column(name = "last_updt_user_id", length = 50)
@Length(max = 50)
public String getLastUpdtUserId() {
return this.lastUpdtUserId;
}
public void setLastUpdtUserId(String lastUpdtUserId) {
this.lastUpdtUserId = lastUpdtUserId;
}
@Column(name = "activation_key", length = 50)
@Length(max = 50)
public String getActivationKey() {
return this.activationKey;
}
public void setActivationKey(String activationKey) {
this.activationKey = activationKey;
}
@Column(name = "active")
public Boolean getActive() {
return this.active;
}
public void setActive(Boolean active) {
this.active = active;
}
@Column(name = "created_on", precision = 17, scale = 17)
public Long getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(Long createdOn) {
this.createdOn = createdOn;
}
}
//////////////////////////////////
package session.timi.dot.ca.gov;
import entity.timi.dot.ca.gov.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.annotations.Transactional;
import static org.jboss.seam.international.StatusMessage.Severity.INFO;
import static org.jboss.seam.international.StatusMessage.Severity.ERROR;
import entity.timi.dot.ca.gov.*;
import org.jboss.seam.annotations.Logger;
import java.io.IOException;
import java.security.MessageDigest;
import java.text.MessageFormat;
import java.util.Map;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Pattern;
import org.jboss.seam.ScopeType;
import org.jboss.seam.core.Events;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.international.StatusMessages;
import static org.jboss.seam.international.StatusMessage.Severity.INFO;
import static org.jboss.seam.international.StatusMessage.Severity.ERROR;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;
//import org.jboss.seam.ui.graphicImage.Image;
import org.jboss.seam.util.Hex;
import entity.timi.dot.ca.gov.*;
@Name("authenticationInformationHome")
public class AuthenticationInformationHome
extends
EntityHome<AuthenticationInformation> {
@Logger private Log log;
@In(required = false) private PasswordSupport passwordSupport;
@In(create=true) private StatusMessages statusMessages;
private boolean agreedToTermsOfUse = false;
@In(create = true)
PersonHome personHome;
public void setAuthenticationInformationId(Integer id) {
setId(id);
}
public Integer getAuthenticationInformationId() {
return (Integer) getId();
}
@Override
protected AuthenticationInformation createInstance() {
AuthenticationInformation authenticationInformation = new AuthenticationInformation();
return authenticationInformation;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
Person person = personHome.getDefinedInstance();
if (person != null) {
getInstance().setPerson(person);
}
}
public boolean isWired() {
if (getInstance().getPerson() == null)
return false;
return true;
}
public AuthenticationInformation getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
@Override
public String persist()
{
// Her you put your code to add stuff to your instance. Remind you should add everything to the object returnded from getInstance(); !!
// so : getInstance().setPassword(passwordSupport.getPassword());
// getInstance().setActivationKey(getMD5Hash(newUser.getLasts....
this.doRegister();
return super.persist();
}
@Transactional
public void doRegister() {
if (!passwordSupport.isConfirmed()) {
statusMessages.addToControlFromResourceBundle("password", ERROR, "password_not_confirmed");
return;
}
if (!agreedToTermsOfUse) {
statusMessages.addToControlFromResourceBundle("termsOfUseLink", ERROR, "please_agree_to_terms");
return;
}
try {
// newUser.setFirstName(this.registrationScreenName);
getInstance().setActive(false);
//newUser.setPassword(passwordSupport.getPasswordHash(this.registrationScreenName));
getInstance().setPassword(passwordSupport.getPassword());
getInstance().setActivationKey(getMD5Hash(getInstance().getLastName()+getInstance().getCreateUserId()+getInstance().getEmail()+getInstance().getFirstName()+System.currentTimeMillis()));
getInstance().setCreatedOn(System.currentTimeMillis());
// String s = "created" + " --" + newUser.getActivationKey() + " --" + newUser.getCreateUserId() + " " + newUser.getEmail() + " " + newUser.getPassword() + " " + newUser.getFirstName() + " " + newUser.getLastName() + " " + newUser.getPerson().getId();
// statusMessages.addToControlFromResourceBundle("registerButton", ERROR, s);
// send the activation email ... as part of this transaction
ExternalContext extCtxt = FacesContext.getCurrentInstance().getExternalContext();
String activationLink = ((javax.servlet.http.HttpServletRequest)extCtxt.getRequest()).getRequestURL().toString();
String newUserLink = activationLink+((activationLink.indexOf("?") != -1)?"&act=":"?act=")+ getInstance().getActivationKey();
Contexts.getEventContext().set("inactiveNewUser", new InactiveNewUser(getInstance().toString(),getInstance().getCreateUserId(),getInstance().getEmail(),newUserLink));
Events.instance().raiseEvent("userRegistered");
// do this last ... just to reset the register form ...
} catch (Exception exc) {
log.error("Registration failed for {0}", exc, String.valueOf(getInstance().getCreateUserId()));
// NOTE: we don't return the Exception message back to the newUser because it may reveal too much information to a hacker
statusMessages.addToControlFromResourceBundle("registerButton", ERROR, "general_reg_error");
}
}
public boolean getAgreedToTermsOfUse() {
return agreedToTermsOfUse;
}
public void setAgreedToTermsOfUse(boolean agreedToTermsOfUse) {
this.agreedToTermsOfUse = agreedToTermsOfUse;
}
protected String getMD5Hash(final String msg) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
return new String(Hex.encodeHex(md5.digest(msg.getBytes("UTF-8"))));
} catch (Exception exc)
{
throw new RuntimeException(exc);
}
}
}
/////////////////////////////
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component"
template="layout/template.xhtml">
<ui:define name="body">
<ice:form id="authenticationInformation" styleClass="edit">
<ice:panelGroup id="editauthenticationInformationGroupId" styleClass="formBorderHighlight">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="iceDatTblColHdr2">
<ice:outputText id="editTextBoxId" value="#{authenticationInformationHome.managed ? 'Edit' : 'Add'} authenticationInformation"/>
</td>
</tr>
</table>
<ice:panelGroup id="editPanelGroupId" styleClass="edit">
<s:decorate id="idField" template="layout/edit.xhtml">
<ui:define name="label">Id</ui:define>
<ice:inputText id="id"
partialSubmit="true"
required="true"
disabled="#{authenticationInformationHome.managed}"
value="#{authenticationInformationHome.instance.id}">
</ice:inputText>
</s:decorate>
<s:decorate id="createDateField" template="layout/edit.xhtml">
<ui:define name="label">Create date</ui:define>
<ice:selectInputDate id="createDate"
renderAsPopup="true"
value="#{authenticationInformationHome.instance.createDate}">
<s:convertDateTime type="date"/>
</ice:selectInputDate>
</s:decorate>
<s:decorate id="createUserIdField" template="layout/edit.xhtml">
<ui:define name="label">Create user id</ui:define>
<ice:inputText id="createUserId"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.createUserId}">
</ice:inputText>
</s:decorate>
<s:decorate id="emailField" template="layout/edit.xhtml">
<ui:define name="label">Email</ui:define>
<ice:inputText id="email"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.email}">
</ice:inputText>
</s:decorate>
<s:decorate id="firstNameField" template="layout/edit.xhtml">
<ui:define name="label">First name</ui:define>
<ice:inputText id="firstName"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.firstName}">
</ice:inputText>
</s:decorate>
<s:decorate id="lastNameField" template="layout/edit.xhtml">
<ui:define name="label">Last name</ui:define>
<ice:inputText id="lastName"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.lastName}">
</ice:inputText>
</s:decorate>
<s:decorate id="lastUpdtDateField" template="layout/edit.xhtml">
<ui:define name="label">Last updt date</ui:define>
<ice:selectInputDate id="lastUpdtDate"
renderAsPopup="true"
value="#{authenticationInformationHome.instance.lastUpdtDate}">
<s:convertDateTime type="date"/>
</ice:selectInputDate>
</s:decorate>
<s:decorate id="lastUpdtUserIdField" template="layout/edit.xhtml">
<ui:define name="label">Last updt user id</ui:define>
<ice:inputText id="lastUpdtUserId"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.lastUpdtUserId}">
</ice:inputText>
</s:decorate>
<s:decorate id="openidField" template="layout/edit.xhtml">
<ui:define name="label">Openid</ui:define>
<ice:inputText id="openid"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.openid}">
</ice:inputText>
</s:decorate>
<s:decorate id="openidProviderField" template="layout/edit.xhtml">
<ui:define name="label">Openid provider</ui:define>
<ice:inputText id="openidProvider"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.openidProvider}">
</ice:inputText>
</s:decorate>
<s:decorate id="passwordField" template="layout/edit.xhtml">
<ui:define name="label">Password</ui:define>
<ice:inputText id="password"
partialSubmit="true"
size="50"
maxlength="50"
value="#{passwordSupport.password}">
</ice:inputText>
</s:decorate>
<s:decorate id="passwordConfirm" template="layout/edit.xhtml">
<ui:define name="label">Retype Password</ui:define>
<ice:inputText id="confirmpassword"
partialSubmit="true"
size="50"
maxlength="50"
value="#{passwordSupport.passwordConfirm}">
</ice:inputText>
</s:decorate>
<s:decorate id="phoneNumberField" template="layout/edit.xhtml">
<ui:define name="label">Phone number</ui:define>
<ice:inputText id="phoneNumber"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.phoneNumber}">
</ice:inputText>
</s:decorate>
<div style="clear:both">
<span class="required">*</span>
required fields
</div>
</ice:panelGroup>
</ice:panelGroup>
<h:panelGroup>
<h:selectBooleanCheckbox id="agreedToTerms" value="#{authenticationInformationHome.agreedToTermsOfUse}"/>
<h:outputText value="Terms :" escape="false"/>
<h:outputLink value="#" id="termsOfUseLink">
<h:outputText value="Terms and condition applied"/>
<!-- <rich:componentControl for="termsOfUse" attachTo="termsOfUseLink" operation="show" event="onclick"/> -->
</h:outputLink><br/> <!-- <rich:spacer height="40"/> -->
</h:panelGroup>
<div class="actionButtons">
<ice:commandButton id="save"
value="Save"
action="#{authenticationInformationHome.persist}"
disabled="#{!authenticationInformationHome.wired}"
rendered="#{!authenticationInformationHome.managed}"/>
<ice:commandButton id="update"
value="Save"
action="#{authenticationInformationHome.update}"
rendered="#{authenticationInformationHome.managed}"/>
<ice:commandButton id="delete"
value="Delete"
action="#{authenticationInformationHome.remove}"
immediate="true"
rendered="#{authenticationInformationHome.managed}"/>
<s:button id="cancelEdit" styleClass="iceCmdBtn"
value="Cancel"
propagation="end"
view="/AuthenticationInformation.xhtml"
rendered="#{authenticationInformationHome.managed}"/>
<s:button id="cancelAddauthenticationInformationHome" styleClass="iceCmdBtn"
value="Cancel"
propagation="end"
view="/#{empty authenticationInformationFrom ? 'AuthenticationInformationList' : authenticationInformationFrom}.xhtml"
rendered="#{!authenticationInformationHome.managed}"/>
</div>
</ice:form>
<ice:form id="form2authenticationInformationHome">
<ice:panelTabSet id="editPanelTabauthenticationInformationHomeId" styleClass="componentPanelTabSetLayout" style="margin-bottom:5px;margin-top:10px;">
<ice:panelTab id="editTabpersonId" label="Person *" >
<div class="association" id="personParent">
<h:outputText id="editpersonTextId" value="There is no person associated with this authenticationInformation."
rendered="#{authenticationInformationHome.instance.person == null}"/>
<ice:dataTable var="person"
value="#{authenticationInformationHome.instance.person}"
rendered="#{authenticationInformationHome.instance.person != null}"
rowClasses="rvgRowOne,rvgRowTwo"
columnClasses="allCols"
id="editpersonTableId">
<ice:column id="$editColumnidId">
<f:facet name="header">Id</f:facet>
#{person.id}
</ice:column>
<ice:column id="$editColumncreateDateId">
<f:facet name="header">Create date</f:facet>
#{person.createDate}
</ice:column>
<ice:column id="$editColumncreateUserIdId">
<f:facet name="header">Create user id</f:facet>
#{person.createUserId}
</ice:column>
<ice:column id="$editColumnlastUpdtDateId">
<f:facet name="header">Last updt date</f:facet>
#{person.lastUpdtDate}
</ice:column>
<ice:column id="$editColumnlastUpdtUserIdId">
<f:facet name="header">Last updt user id</f:facet>
#{person.lastUpdtUserId}
</ice:column>
<ice:column id="editColumnpersonLinkId">
<f:facet name="header">Action</f:facet>
<s:link view="/Person.xhtml"
id="viewperson"
value="View"
propagation="none">
<f:param name="personId"
value="#{person.id}"/>
</s:link>
</ice:column>
</ice:dataTable>
<div class="actionButtons">
<s:button value="Select person"
id="selectParent"
view="/PersonList.xhtml">
<f:param name="from" value="AuthenticationInformationCreate"/>
</s:button>
</div>
</div>
</ice:panelTab>
</ice:panelTabSet>
</ice:form>
</ui:define>
</ui:composition>
in this entity there is primary key id i want to use this column as a auto generated value. and i want to remove the id column from JSF facelete page that should be auto generate by application.
can any one suggest me how i customize my code for this.
here is my entity, session and jsf code.
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
/**
* AuthenticationInformation generated by hbm2java
*/
@Entity
@Table(name = "authentication_information")
public class AuthenticationInformation implements java.io.Serializable {
private int id;
private Person person;
private String openid;
private String openidProvider;
private String firstName;
private String lastName;
private String phoneNumber;
private String email;
private String password;
private Date createDate;
private Date lastUpdtDate;
private String createUserId;
private String lastUpdtUserId;
private String activationKey;
private Long createdOn;
private Boolean active;
public AuthenticationInformation() {
}
public AuthenticationInformation(int id, Person person) {
this.id = id;
this.person = person;
}
public AuthenticationInformation(int id, Person person, String openid,
String openidProvider, String firstName, String lastName,
String phoneNumber, String email, String password, Date createDate,
Date lastUpdtDate, String createUserId, String lastUpdtUserId,
String activationKey, Long createdOn, Boolean active) {
this.id = id;
this.person = person;
this.openid = openid;
this.openidProvider = openidProvider;
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.email = email;
this.password = password;
this.createDate = createDate;
this.lastUpdtDate = lastUpdtDate;
this.createUserId = createUserId;
this.lastUpdtUserId = lastUpdtUserId;
this.activationKey = activationKey;
this.createdOn = createdOn;
this.active = active;
}
@Id
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "person_sequence_number", nullable = false)
@NotNull
public Person getPerson() {
return this.person;
}
public void setPerson(Person person) {
this.person = person;
}
@Column(name = "openid", length = 50)
@Length(max = 50)
public String getOpenid() {
return this.openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
@Column(name = "openid_provider", length = 50)
@Length(max = 50)
public String getOpenidProvider() {
return this.openidProvider;
}
public void setOpenidProvider(String openidProvider) {
this.openidProvider = openidProvider;
}
@Column(name = "first_name", length = 50)
@Length(max = 50)
@Pattern(regex = "^[a-zA-Z\\d_]{4,12}$",message = "{invalid_screen_name}")
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name = "last_name", length = 50)
@Length(max = 50)
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name = "phone_number", length = 50)
@Length(max = 50)
public String getPhoneNumber() {
return this.phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Column(name = "email", length = 50)
@Length(max = 50)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "password", length = 50)
@Length(max = 50)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Temporal(TemporalType.DATE)
@Column(name = "create_date", length = 13)
public Date getCreateDate() {
return this.createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
@Temporal(TemporalType.DATE)
@Column(name = "last_updt_date", length = 13)
public Date getLastUpdtDate() {
return this.lastUpdtDate;
}
public void setLastUpdtDate(Date lastUpdtDate) {
this.lastUpdtDate = lastUpdtDate;
}
@Column(name = "create_user_id", length = 50)
@Length(max = 50)
public String getCreateUserId() {
return this.createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId;
}
@Column(name = "last_updt_user_id", length = 50)
@Length(max = 50)
public String getLastUpdtUserId() {
return this.lastUpdtUserId;
}
public void setLastUpdtUserId(String lastUpdtUserId) {
this.lastUpdtUserId = lastUpdtUserId;
}
@Column(name = "activation_key", length = 50)
@Length(max = 50)
public String getActivationKey() {
return this.activationKey;
}
public void setActivationKey(String activationKey) {
this.activationKey = activationKey;
}
@Column(name = "active")
public Boolean getActive() {
return this.active;
}
public void setActive(Boolean active) {
this.active = active;
}
@Column(name = "created_on", precision = 17, scale = 17)
public Long getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(Long createdOn) {
this.createdOn = createdOn;
}
}
//////////////////////////////////
package session.timi.dot.ca.gov;
import entity.timi.dot.ca.gov.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.annotations.Transactional;
import static org.jboss.seam.international.StatusMessage.Severity.INFO;
import static org.jboss.seam.international.StatusMessage.Severity.ERROR;
import entity.timi.dot.ca.gov.*;
import org.jboss.seam.annotations.Logger;
import java.io.IOException;
import java.security.MessageDigest;
import java.text.MessageFormat;
import java.util.Map;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Pattern;
import org.jboss.seam.ScopeType;
import org.jboss.seam.core.Events;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.international.StatusMessages;
import static org.jboss.seam.international.StatusMessage.Severity.INFO;
import static org.jboss.seam.international.StatusMessage.Severity.ERROR;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;
//import org.jboss.seam.ui.graphicImage.Image;
import org.jboss.seam.util.Hex;
import entity.timi.dot.ca.gov.*;
@Name("authenticationInformationHome")
public class AuthenticationInformationHome
extends
EntityHome<AuthenticationInformation> {
@Logger private Log log;
@In(required = false) private PasswordSupport passwordSupport;
@In(create=true) private StatusMessages statusMessages;
private boolean agreedToTermsOfUse = false;
@In(create = true)
PersonHome personHome;
public void setAuthenticationInformationId(Integer id) {
setId(id);
}
public Integer getAuthenticationInformationId() {
return (Integer) getId();
}
@Override
protected AuthenticationInformation createInstance() {
AuthenticationInformation authenticationInformation = new AuthenticationInformation();
return authenticationInformation;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
Person person = personHome.getDefinedInstance();
if (person != null) {
getInstance().setPerson(person);
}
}
public boolean isWired() {
if (getInstance().getPerson() == null)
return false;
return true;
}
public AuthenticationInformation getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
@Override
public String persist()
{
// Her you put your code to add stuff to your instance. Remind you should add everything to the object returnded from getInstance(); !!
// so : getInstance().setPassword(passwordSupport.getPassword());
// getInstance().setActivationKey(getMD5Hash(newUser.getLasts....
this.doRegister();
return super.persist();
}
@Transactional
public void doRegister() {
if (!passwordSupport.isConfirmed()) {
statusMessages.addToControlFromResourceBundle("password", ERROR, "password_not_confirmed");
return;
}
if (!agreedToTermsOfUse) {
statusMessages.addToControlFromResourceBundle("termsOfUseLink", ERROR, "please_agree_to_terms");
return;
}
try {
// newUser.setFirstName(this.registrationScreenName);
getInstance().setActive(false);
//newUser.setPassword(passwordSupport.getPasswordHash(this.registrationScreenName));
getInstance().setPassword(passwordSupport.getPassword());
getInstance().setActivationKey(getMD5Hash(getInstance().getLastName()+getInstance().getCreateUserId()+getInstance().getEmail()+getInstance().getFirstName()+System.currentTimeMillis()));
getInstance().setCreatedOn(System.currentTimeMillis());
// String s = "created" + " --" + newUser.getActivationKey() + " --" + newUser.getCreateUserId() + " " + newUser.getEmail() + " " + newUser.getPassword() + " " + newUser.getFirstName() + " " + newUser.getLastName() + " " + newUser.getPerson().getId();
// statusMessages.addToControlFromResourceBundle("registerButton", ERROR, s);
// send the activation email ... as part of this transaction
ExternalContext extCtxt = FacesContext.getCurrentInstance().getExternalContext();
String activationLink = ((javax.servlet.http.HttpServletRequest)extCtxt.getRequest()).getRequestURL().toString();
String newUserLink = activationLink+((activationLink.indexOf("?") != -1)?"&act=":"?act=")+ getInstance().getActivationKey();
Contexts.getEventContext().set("inactiveNewUser", new InactiveNewUser(getInstance().toString(),getInstance().getCreateUserId(),getInstance().getEmail(),newUserLink));
Events.instance().raiseEvent("userRegistered");
// do this last ... just to reset the register form ...
} catch (Exception exc) {
log.error("Registration failed for {0}", exc, String.valueOf(getInstance().getCreateUserId()));
// NOTE: we don't return the Exception message back to the newUser because it may reveal too much information to a hacker
statusMessages.addToControlFromResourceBundle("registerButton", ERROR, "general_reg_error");
}
}
public boolean getAgreedToTermsOfUse() {
return agreedToTermsOfUse;
}
public void setAgreedToTermsOfUse(boolean agreedToTermsOfUse) {
this.agreedToTermsOfUse = agreedToTermsOfUse;
}
protected String getMD5Hash(final String msg) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
return new String(Hex.encodeHex(md5.digest(msg.getBytes("UTF-8"))));
} catch (Exception exc)
{
throw new RuntimeException(exc);
}
}
}
/////////////////////////////
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component"
template="layout/template.xhtml">
<ui:define name="body">
<ice:form id="authenticationInformation" styleClass="edit">
<ice:panelGroup id="editauthenticationInformationGroupId" styleClass="formBorderHighlight">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="iceDatTblColHdr2">
<ice:outputText id="editTextBoxId" value="#{authenticationInformationHome.managed ? 'Edit' : 'Add'} authenticationInformation"/>
</td>
</tr>
</table>
<ice:panelGroup id="editPanelGroupId" styleClass="edit">
<s:decorate id="idField" template="layout/edit.xhtml">
<ui:define name="label">Id</ui:define>
<ice:inputText id="id"
partialSubmit="true"
required="true"
disabled="#{authenticationInformationHome.managed}"
value="#{authenticationInformationHome.instance.id}">
</ice:inputText>
</s:decorate>
<s:decorate id="createDateField" template="layout/edit.xhtml">
<ui:define name="label">Create date</ui:define>
<ice:selectInputDate id="createDate"
renderAsPopup="true"
value="#{authenticationInformationHome.instance.createDate}">
<s:convertDateTime type="date"/>
</ice:selectInputDate>
</s:decorate>
<s:decorate id="createUserIdField" template="layout/edit.xhtml">
<ui:define name="label">Create user id</ui:define>
<ice:inputText id="createUserId"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.createUserId}">
</ice:inputText>
</s:decorate>
<s:decorate id="emailField" template="layout/edit.xhtml">
<ui:define name="label">Email</ui:define>
<ice:inputText id="email"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.email}">
</ice:inputText>
</s:decorate>
<s:decorate id="firstNameField" template="layout/edit.xhtml">
<ui:define name="label">First name</ui:define>
<ice:inputText id="firstName"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.firstName}">
</ice:inputText>
</s:decorate>
<s:decorate id="lastNameField" template="layout/edit.xhtml">
<ui:define name="label">Last name</ui:define>
<ice:inputText id="lastName"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.lastName}">
</ice:inputText>
</s:decorate>
<s:decorate id="lastUpdtDateField" template="layout/edit.xhtml">
<ui:define name="label">Last updt date</ui:define>
<ice:selectInputDate id="lastUpdtDate"
renderAsPopup="true"
value="#{authenticationInformationHome.instance.lastUpdtDate}">
<s:convertDateTime type="date"/>
</ice:selectInputDate>
</s:decorate>
<s:decorate id="lastUpdtUserIdField" template="layout/edit.xhtml">
<ui:define name="label">Last updt user id</ui:define>
<ice:inputText id="lastUpdtUserId"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.lastUpdtUserId}">
</ice:inputText>
</s:decorate>
<s:decorate id="openidField" template="layout/edit.xhtml">
<ui:define name="label">Openid</ui:define>
<ice:inputText id="openid"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.openid}">
</ice:inputText>
</s:decorate>
<s:decorate id="openidProviderField" template="layout/edit.xhtml">
<ui:define name="label">Openid provider</ui:define>
<ice:inputText id="openidProvider"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.openidProvider}">
</ice:inputText>
</s:decorate>
<s:decorate id="passwordField" template="layout/edit.xhtml">
<ui:define name="label">Password</ui:define>
<ice:inputText id="password"
partialSubmit="true"
size="50"
maxlength="50"
value="#{passwordSupport.password}">
</ice:inputText>
</s:decorate>
<s:decorate id="passwordConfirm" template="layout/edit.xhtml">
<ui:define name="label">Retype Password</ui:define>
<ice:inputText id="confirmpassword"
partialSubmit="true"
size="50"
maxlength="50"
value="#{passwordSupport.passwordConfirm}">
</ice:inputText>
</s:decorate>
<s:decorate id="phoneNumberField" template="layout/edit.xhtml">
<ui:define name="label">Phone number</ui:define>
<ice:inputText id="phoneNumber"
partialSubmit="true"
size="50"
maxlength="50"
value="#{authenticationInformationHome.instance.phoneNumber}">
</ice:inputText>
</s:decorate>
<div style="clear:both">
<span class="required">*</span>
required fields
</div>
</ice:panelGroup>
</ice:panelGroup>
<h:panelGroup>
<h:selectBooleanCheckbox id="agreedToTerms" value="#{authenticationInformationHome.agreedToTermsOfUse}"/>
<h:outputText value="Terms :" escape="false"/>
<h:outputLink value="#" id="termsOfUseLink">
<h:outputText value="Terms and condition applied"/>
<!-- <rich:componentControl for="termsOfUse" attachTo="termsOfUseLink" operation="show" event="onclick"/> -->
</h:outputLink><br/> <!-- <rich:spacer height="40"/> -->
</h:panelGroup>
<div class="actionButtons">
<ice:commandButton id="save"
value="Save"
action="#{authenticationInformationHome.persist}"
disabled="#{!authenticationInformationHome.wired}"
rendered="#{!authenticationInformationHome.managed}"/>
<ice:commandButton id="update"
value="Save"
action="#{authenticationInformationHome.update}"
rendered="#{authenticationInformationHome.managed}"/>
<ice:commandButton id="delete"
value="Delete"
action="#{authenticationInformationHome.remove}"
immediate="true"
rendered="#{authenticationInformationHome.managed}"/>
<s:button id="cancelEdit" styleClass="iceCmdBtn"
value="Cancel"
propagation="end"
view="/AuthenticationInformation.xhtml"
rendered="#{authenticationInformationHome.managed}"/>
<s:button id="cancelAddauthenticationInformationHome" styleClass="iceCmdBtn"
value="Cancel"
propagation="end"
view="/#{empty authenticationInformationFrom ? 'AuthenticationInformationList' : authenticationInformationFrom}.xhtml"
rendered="#{!authenticationInformationHome.managed}"/>
</div>
</ice:form>
<ice:form id="form2authenticationInformationHome">
<ice:panelTabSet id="editPanelTabauthenticationInformationHomeId" styleClass="componentPanelTabSetLayout" style="margin-bottom:5px;margin-top:10px;">
<ice:panelTab id="editTabpersonId" label="Person *" >
<div class="association" id="personParent">
<h:outputText id="editpersonTextId" value="There is no person associated with this authenticationInformation."
rendered="#{authenticationInformationHome.instance.person == null}"/>
<ice:dataTable var="person"
value="#{authenticationInformationHome.instance.person}"
rendered="#{authenticationInformationHome.instance.person != null}"
rowClasses="rvgRowOne,rvgRowTwo"
columnClasses="allCols"
id="editpersonTableId">
<ice:column id="$editColumnidId">
<f:facet name="header">Id</f:facet>
#{person.id}
</ice:column>
<ice:column id="$editColumncreateDateId">
<f:facet name="header">Create date</f:facet>
#{person.createDate}
</ice:column>
<ice:column id="$editColumncreateUserIdId">
<f:facet name="header">Create user id</f:facet>
#{person.createUserId}
</ice:column>
<ice:column id="$editColumnlastUpdtDateId">
<f:facet name="header">Last updt date</f:facet>
#{person.lastUpdtDate}
</ice:column>
<ice:column id="$editColumnlastUpdtUserIdId">
<f:facet name="header">Last updt user id</f:facet>
#{person.lastUpdtUserId}
</ice:column>
<ice:column id="editColumnpersonLinkId">
<f:facet name="header">Action</f:facet>
<s:link view="/Person.xhtml"
id="viewperson"
value="View"
propagation="none">
<f:param name="personId"
value="#{person.id}"/>
</s:link>
</ice:column>
</ice:dataTable>
<div class="actionButtons">
<s:button value="Select person"
id="selectParent"
view="/PersonList.xhtml">
<f:param name="from" value="AuthenticationInformationCreate"/>
</s:button>
</div>
</div>
</ice:panelTab>
</ice:panelTabSet>
</ice:form>
</ui:define>
</ui:composition>