AnsweredAssumed Answered

Adding custom property to Person/User

Question asked by albertomv on Nov 23, 2007
Latest reply on Dec 14, 2007 by kevinr
Hello!

I'm trying to add a new property to users/people in Alfresco and customising the Web Client to support it.

As I've read in http://issues.alfresco.com/browse/AWC-1665, there is currently no way to customise declaratively the NewUserWizard as with other wizards through Property Sheets. ¿Am I right?

I'd appreciate if someone could show me any way to do this or comment the approach I explain below. Thanks

I've tried the following approach, which works, but it's highly "invasive":


First I created "my.custom.UserWizard" which extends. "org.alfresco.web.bean.wizard.NewUserWizard"


….
<managed-bean>
      <description>
         The bean that backs up the New User Wizard
      </description>
      <managed-bean-name>NewUserWizard</managed-bean-name>
    <managed-bean-class>my.custom.UserWizard</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
      …..


and added there a new property:


private Boolean myProp = null;
static final QName PROP_MYPROP = QName.createQName(
         NamespaceService.CONTENT_MODEL_1_0_URI, "myProp");   

Redefined some methods:

First init():

super.init();
this.myProp=false;

Then populate():

super.populate();
// set values for edit mode
Map<String, Object> props = getPerson().getProperties();
this.myProp = (Boolean) props.get("myProp");

And finally finish():

String outcome = super.finish();
      if (outcome == null)
         return null;
      outcome = FINISH_OUTCOME;
UserTransaction tx = null;

      try {
         FacesContext context = FacesContext.getCurrentInstance();
         tx = Repository.getUserTransaction(context);
         tx.begin();

         // update the existing node in the repository
         if(this.editMode){
            NodeRef nodeRef = getPerson().getNodeRef();
            this.nodeService.setProperty(nodeRef, PROP_MYPROP, this.myProp);
         }else{
            NodeRef person =this.personService.getPerson(this.getUserName());
            this.nodeService.setProperty(person, PROP_MYPROP, this.myProp);
         }

         // commit the transaction
         tx.commit();

         // reset the richlist component so it rebinds to the users list
         invalidateUserList();
      } catch (Throwable e) {
         // rollback the transaction
         try {
            if (tx != null) {
               tx.rollback();
            }
         } catch (Exception tex) {
         }
                        //Treat the error
         outcome = null;
      }

      return outcome;
   }

Then, I added some code into person-properties.jsp:

<tr>
<td><h:outputText value="My Prop?" />:</td>
<td><h:selectBooleanCheckbox value="#{NewUserWizard.myProp}"/></td>
</tr>

and changed contentModel.xml:

<property name="cm:myProp">
        <type>d:boolean</type>
</property>

I don't like this approach because I'd like all the properties of a person to be edited/created in the same transaction, and not having to deal with Faces Navigation issues if one transaction success and the other fails.

I don't like neither changing contentModel.xml nor depending on person-properties.jsp as I'd like to pack this changes into an AMP and installing it on an alfresco.war (with the possibility of upgrading the war!)

Thanks!

Outcomes