database access

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
soeursourire
Member II

database access

Hi everybody!

I am writing to you for help about access to users entered in the database. I added an attribute "country" in MyNewUserWizard class (sub-class of NewUserWizard) and added it as aspect and prop and I would like to display this attribute for each user on the page users.jsp. How can I do?

It seems that fullname homeSpace etc.. are obtained from the final class repository:

<a:richList id="users-list" binding="#{UsersBean.usersRichList}" viewMode="details" pageSize="10"
styleClass="recordSet" headerStyleClass="recordSetHeader" rowStyleClass="recordSetRow" altRowStyleClass="recordSetRowAlt" width="100%"value="#{UsersBean.users}" var="r" initialSortColumn="userName" initialSortDescending="true">
[…]
<hSmiley SurprisedutputText value="#{r.fullName}" />

                             
so how can I access the attribute "country" as I cannot create sub class of this final class repository?

Thanks in advance for your help!
15 Replies
turgayz
Member II

Re: database access

Hi,
I didn't understand what you mean by "final class repository", can you describe it?

I guess if everything is in place, you should be able to access the property with

<hSmiley SurprisedutputText value="#{r.country}" />

Hope this helps, if not, please show the code.
soeursourire
Member II

Re: database access

Effectively by doing that I do not have error message anymore but in  users.jsp page this is appearing:

MISSING: department :MISSING

and if I want to modify the properties of a user I do not have the values in the person-properties page anymore (the name last name etc are not appearing)…
soeursourire
Member II

Re: database access

It seems that my attribute (property) "country" is not well defined as it does not appear in Node Browser. Please would you mind telling me what I am doing wrong here:

-I added an aspect and property in CustomModel:
<aspects>
      <aspect name="custom:Myperson">
         <title>Country</title>
         <properties>
            <property name="custom:country">
               <type>d:text</type>
            </property>
         </properties>
      </aspect>
   </aspects>

-Then I added to ContentModel:
static final QName PROP_COUNTRY = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "country");
static final QName ASPECT_Myperson = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Myperson");

-And then I modify finish() in NewUserWizard by adding this code:

after this code:
props.put(MyContentModel.PROP_HOMEFOLDER, newHomeFolderRef);
props.put(MyContentModel.PROP_EMAIL, super.getEmail());
props.put(EthicFlow_ContentModel.PROP_ORGID, super.getCompanyId());
this.nodeService.setProperties(nodeRef, props);

I add this code:
Map<QName, Serializable> myprops = new HashMap<QName, Serializable>(5);
myprops.put(MyContentModel.PROP_COUNTRY, this.country);
this.nodeService.addAspect(nodeRef, MyContentModel.ASPECT_Myperson,myprops);
soeursourire
Member II

Re: database access

Should I add this property Country in PersonService? And if yes what is the best way to do it:
- adding a sub-class of PersonServiceImpl
- adding a new bean MyPersonService
- importing this bean in Application-context
- using MyPersonService instead of PersonService in my classes
??

Thanks for help
gavinc
Member II

Re: database access

I can see a couple of potential problems…

You have defined (quite rightly) the aspect in it's own namespace i.e. custom:Myperson. However when you create the static members in ContentModel you use the default cm: namespace:

static final QName PROP_COUNTRY = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "country");
static final QName ASPECT_Myperson = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Myperson");

You need to use the URI for your namespace that you would have defined in your model:

static final QName ASPECT_Myperson = QName.createQName("your uri", Myperson);

Then to refer to your property in the list you will need to use the following syntax:

<hSmiley SurprisedutputText value='#{r["custom:Myperson"]}' />

Hope this helps
soeursourire
Member II

Re: database access

So if I well understand I will have the following in MyContentModel.java:

static final QName PROP_COUNTRY = QName.createQName("custom.model", "country");
static final QName ASPECT_Myperson = QName.createQName("custom.model", "Myperson");

and in my jsp page I need to add this taglib:
<%@ taglib uri="custom.model" prefix="custom" %>

and this access:
<hSmiley SurprisedutputText value="#{r["custom:country"]}"/>

But what is this custom.model where is it defined and how can I define it, should I create a file custom.model and put it in WEB-INF like repo.tld or alfresco.tld? I am lost..
gavinc
Member II

Re: database access

I presumed you had defined a custom model as explained in http://www.alfresco.org/mediawiki/index.php/Data_Dictionary_Guide#Content_Models to define the property and the aspect you are adding?

custom.model is the namespace you define for your model it doesn't have anything to do with taglibs so you won't need <%@ taglib uri="custom.model" prefix="custom" %> in your page.

One thing to be careful of is the quotes in your example, make sure it is as follows i.e. use single quotes around the whole expression.

<hSmiley SurprisedutputText value='#{r["custom:country"]}'/>
soeursourire
Member II

Re: database access

Thanks a lot. I guess it was the problem and I added my aspect in web-client-config.xml

However I still have MISSING:Country:MISSING appearing in my users.jsp and I still do not have the attribute country in Node Browser from Administration Console for people…. Should I modify PersonService?
gavinc
Member II

Re: database access

Hi,

MISSING:Country:MISSING means that you have not added an entry in webclient.properties for an I18N string.

No, you shouldn't need to change PersonService, the property should be visible with what you have done.