import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
import org.mxchange.jcontacts.contact.gender.Gender;
+import org.mxchange.jcontacts.contact.utils.ContactUtils;
import org.mxchange.jcountry.data.Country;
+import org.mxchange.jjobs.beans.helper.JobsAdminWebRequestController;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jusercore.events.user.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.update.AdminUserDataUpdatedEvent;
/**
* A user bean (controller)
@Any
private Event<AdminAddedUserEvent> addedUserEvent;
+ /**
+ * Admin helper instance
+ */
+ @Inject
+ private JobsAdminWebRequestController adminHelper;
+
/**
* Birth day
*/
}
}
+ @Override
+ public String changeContactData () {
+ // Get contact instance
+ Contact contact = this.adminHelper.getContact();
+
+ // Check if contact instance is in helper and valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("adminHelper.contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Invalid id
+ throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+ }
+
+ // Update all data in contact
+ this.updateContactData(contact);
+
+ // Call EJB for updating contact data
+ Contact updatedContact = this.contactBean.updateContactData(contact);
+
+ // Update list
+ this.updateList(updatedContact);
+
+ // Fire event
+ this.updatedContactDataEvent.fire(new AdminUserDataUpdatedEvent(updatedContact));
+
+ // Return to contact list (for now)
+ return "admin_list_contact"; //NOI18N
+ }
+
@Override
public void copyContactToController (final Contact contact) {
// The contact instance must be valid
if (null == contact) {
// Throw NPE again
- throw new NullPointerException("this.user.userContact is null");
+ throw new NullPointerException("contact is null"); //NOI18N
} else if (contact.getContactId() < 1) {
// Not valid
- throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId()));
+ throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
}
// Set all fields: contact
public void init () {
}
+ /**
+ * Updates all data in contact instance.
+ * <p>
+ * @param contact Contact instance
+ */
+ private void updateContactData (final Contact contact) {
+ // Contact instance should be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Invalid id
+ throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+ }
+
+ // Update all fields
+ contact.setContactGender(this.getGender());
+ contact.setContactFirstName(this.getFirstName());
+ contact.setContactFamilyName(this.getFamilyName());
+ contact.setContactStreet(this.getStreet());
+ contact.setContactHouseNumber(this.getHouseNumber());
+ contact.setContactZipCode(this.getZipCode());
+ contact.setContactCity(this.getCity());
+ contact.setContactCountry(this.getCountry());
+
+ // Update contact's cellphone number
+ ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
+
+ // Is there a phone number?
+ if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Debug message
+ System.out.println(MessageFormat.format("updateContactData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N
+
+ // Yes, then update as well
+ contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode());
+ contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber());
+ }
+
+ // Is there a fax number?
+ if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Debug message
+ System.out.println(MessageFormat.format("updateContactData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N
+
+ // Yes, then update as well
+ contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode());
+ contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber());
+ }
+ }
+
}
@Inject
private JobsAdminUserWebRequestController adminUserController;
+ /**
+ * Contact instance
+ */
+ private Contact contact;
+
/**
* User instance
*/
public JobsAdminWebRequestHelper () {
}
+ @Override
+ public void copyContactToController () {
+ // Log message
+ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
+
+ // Validate user instance
+ if (this.getContact() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.contact is null"); //NOI18N
+ } else if (this.getContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+ } else if (this.getContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
+ }
+
+ // Set all fields: user
+ this.adminContactController.copyContactToController(this.getContact());
+
+ // Log message
+ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
+ }
+
@Override
public void copyUserToController () {
// Validate user instance
// Set all fields: user
this.adminUserController.setUserName(this.getUser().getUserName());
- // Get contact instance (shortens stuff)
- Contact contact = this.getUser().getUserContact();
+ // Log message
+ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
+ }
- // Call contact controller
- this.adminContactController.copyContactToController(contact);
+ @Override
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ @Override
+ public void setContact (final Contact contact) {
+ this.contact = contact;
}
@Override
xmlns:f="http://xmlns.jcp.org/jsf/core"
>
+ <f:metadata>
+ <f:viewParam name="contactId" value="#{adminHelper.contact}" converter="UserConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CONTACT_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyContactToController()}" />
+ </f:metadata>
+
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
<ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_EDIT_CONTACT}</ui:define>
</ui:define>
<ui:define name="content">
- Here goes your content.
+ <h:outputText styleClass="errors" value="#{msg.ERROR_CONTACT_ID_NOT_FOUND}" rendered="#{empty adminHelper.contact}" />
+
+ <h:form id="admin_edit_user" rendered="#{not empty adminHelper.user}">
+ <div class="table">
+ <div class="table_header">
+ #{msg.ADMIN_EDIT_CONTACT_TITLE}
+ </div>
+
+ <div class="para notice">
+ #{msg.ADMIN_PERSONAL_DATA_MINIMUM_NOTICE}
+ </div>
+
+ <ui:include src="/WEB-INF/templates/admin/contact/admin_form_contact_data.tpl">
+ <ui:param name="mode" value="edit" />
+ </ui:include>
+
+ <div class="table_footer">
+ <h:commandButton class="reset" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
+ <h:commandButton class="submit" type="submit" id="register" value="#{msg.BUTTON_ADMIN_EDIT_CONTACT}" action="#{adminUserController.changeContactData()}" />
+ </div>
+ </div>
+ </h:form>
</ui:define>
</ui:composition>
</html>