cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the value of aspect?

jlbarrera
Champ in-the-making
Champ in-the-making
I want get the value of aspect. How i can make this?
Thanks!
13 REPLIES 13

jlbarrera
Champ in-the-making
Champ in-the-making
if i have a "Node", and this Node has the aspect localizable, how can get the value of this aspect?
I am debugging, but i don't find in anywhere the value of this aspect.

Some ideas?

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Have you tried looking at the node in the node inspector found on the admin console within the web client.

It should show you in some detail the aspects and property values of the nodes currently in the repository.

Hope this helps,
Roy

jlbarrera
Champ in-the-making
Champ in-the-making
But not in the web client…

I'm creating a new class that extends of BrowseBean, and whitin the this class i'm modify the List<Node> that return the getContent() method. I need get the value of aspect localizable the all Nodes.

ummm…

Thank you. some ideas?

kevinr
Star Contributor
Star Contributor
Ah i see what you mean. It's easy enough to use the NodeService to get the property you want. There is not as such a "value" of an aspect - an aspect can add any number of additional property values and/or additional associations to a node. There may well be more than one property value or association added when you apply an aspect. The "localizable" aspect you mention does only have a single value added as per the model:

      <aspect name="cm:localizable">
         <title>Localizable</title>
         <properties>
            <property name="cm:locale">
               <title>Locale</title>
               <!– need to have means to identify root instance of appropriate category –>
               <type>d:category</type>
            </property>
         </properties>
      </aspect>
So to access the "cm:locale" property you would write the following code in your BrowseBean method:

   NodeRef categoryRef = (NodeRef)this.nodeService.getProperty(nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "locale"));
You should test for a null value as that would mean either the aspect has not been applied or the property is empty (which is a valid case as it is not a mandatory property).

Hope this helps,

Kevin

jlbarrera
Champ in-the-making
Champ in-the-making
OK thank  you very much. you understand me.

But..there are other problem  :?

In this sentence:
this.nodeService.getProperty(this.nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "locale"));

i recived a NullPointerException

I have declared nodeService:
protected NodeService nodeService;

but i think that nodeService is Null !

Then..How can inicialited nodeService?

Thanks, and sorry  for my english

abichet
Champ in-the-making
Champ in-the-making
hi,
you can try this :
FacesContext context = FacesContext.getCurrentInstance();
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();

regards

kevinr
Star Contributor
Star Contributor
I have declared nodeService:
protected NodeService nodeService;

but i think that nodeService is Null !

When you define a bean, if you wish the services to be automatically setup for you, then you must add your bean definition to the JSF config file:
\root\projects\web-client\source\web\WEB-INF\faces-config-beans.xml
Look for "BrowseBean" for an example. If you are extending the existing BrowseBean code then you will not need to add another "protected NodeService nodeService;" line as the base class already has one - but you will still need to add your bean to the JSF config as i say.

Thanks,

Kevin

jlbarrera
Champ in-the-making
Champ in-the-making
Firts: I can't execute the code of  "abichet" because i can't find:
javax.servlet.ServletContext 

??!!!

Second:I have my class that extends of BrowseBean in other package (because i don't want change the alfresco source), and i changed the <managed-bean-class> within
<managed-bean-name>BrowseBean</managed-bean-name>

in faces-config-beans.xml for my class.

well…nodeService is null   why?

if you say that i dont't need add

protected NodeService nodeService;

in my class…How inicialited nodeService? or..How i can access to nodeService in BrowseBean?

All this could be more easy if i modified directly the alfresco's source, but i prefer create my own class.

Some ideas or there are not more ideas  :wink:

thanks for help my

kevinr
Star Contributor
Star Contributor
If your class overrides BrowseBean and you can correctly set the class in the <managed-bean-class> then you can access the protected nodeService member variable that is on the base class e.g. on BrowseBean. It should be setup automatically if this is done correctly.

Thanks,

Kevin