Jahia Dev Forum > Creating a Custom...

0 (0 Good)
0 (0 Bad)

Creating a Custom Annotation for Jahia Actions

by  sashok »  2013/07/22 08:39

Hello Everyone,

 

I have just started developping modules and templates for Jahia 6.6 and I saw that all actions are defined in the META-INF/spring/<module-name>.xml as <bean> tags.

I am not sure if there are better ways to let Spring load our actions in the context. So I have decided to implement my custom @JahiaAction annotation.

This is how the end result looks like:

@JahiaAction(name="formComponentAction1", requireAuthenticatedUser=true)
public class FormComponentAction extends org.jahia.bin.Action ..{

class body...

}

 

And this is how it is done:

META-INF/spring/<module-name>.xml

<context:component-scan base-package="org.jahia.modules.actions" />
<bean class="org.jahia.modules.actions.MyBeanPostProcessor"/>

org.jahia.modules.actions.MyBeanPostProcessor

public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName)
            throws BeansException {
        if(bean.getClass().getAnnotation(JahiaAction.class)!=null){
            String name = bean.getClass().getAnnotation(JahiaAction.class).name();
            if(StringUtils.isEmpty(name)){
                name = beanName;
            }
            boolean requireAuthenticatedUser = bean.getClass().getAnnotation(JahiaAction.class).requireAuthenticatedUser();
            Action jahiaActionBean = (Action) bean;
            jahiaActionBean.setName(name);
            jahiaActionBean.setRequireAuthenticatedUser(requireAuthenticatedUser);
        }
        
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName)
            throws BeansException {
        return bean;
    }
}

org.jahia.modules.actions.JahiaAction

/**
 * Annotation qui permet au Spring de récuperer
 * les beans controlleurs et de les configurer avec
 * les parametres necessaires.
 *
 * {@link Action}
 * @author KIRILOV Alexandre
 *
 */
@Component
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface JahiaAction{
    /**
     * Le nom du controlleur utilisé par Jahia.
     * Default - le nom de la class
     * ex: si on met pas le nom
     * class MyController; name: myController
     *
     * @see Action#setName(String)
     */
    String name() default "";
    /**
     * La variable requireAuthenticatedUser utilisé
     * par Jahia. Default - false
     *
     * @see Action#setRequireAuthenticatedUser(boolean)
     */
    boolean requireAuthenticatedUser() default false;
}

 

I hope this helps !

 

Best Regards,

KIRILOV Alexander

 

  (sashok)

Number of messages  14
Registration date
0 (0 Good)
0 (0 Bad)

Re: Creating a Custom Annotation for Jahia Actions

by  shuber »  2013/07/24 08:30

Thanks a lot for sharing this, it is a very cool integration indeed ! Is this something you'd like to contribute to Jahia eventually ?

Best regards,

  Serge... 

Serge Huber (shuber)

Number of messages  271
Registration date
0 (0 Good)
0 (0 Bad)

Re: Re: Creating a Custom Annotation for Jahia Actions

by  sashok »  2013/07/24 09:42

Hello Serge,

Yes, I would be happy to contribute this to Jahia. Can you please tell me what the procedure is ?

Regards,

Alexander

 

Thanks a lot for sharing this, it is a very cool integration indeed ! Is this something you'd like to contribute to Jahia eventually ?

Best regards,

  Serge... 

  (sashok)

Number of messages  14
Registration date
0 (0 Good)
0 (0 Bad)

Re: Re: Re: Creating a Custom Annotation for Jahia Actions

by  faissah »  2013/07/30 14:44

Hello Alexander,

Thanks you for contributing to Jahia! You would be the first contributor from the community so we are looking at the correct procedure to do it. We will come back to you as soon as we figure out such procedure.

Thanks again,

Fabrice

Fabrice  (faissah)

Number of messages  262
Registration date
0 (0 Good)
0 (0 Bad)

Re: Re: Re: Creating a Custom Annotation for Jahia Actions

by  shuber »  2013/08/21 07:29

Hello Alexander, 

Sorry for the delay, with the holidays it took a little longer to get in touch with the persons involved :) 

For contributions, as we need to make sure there are no legal issues, we first need you to sign a contributor agreement, that is similar to what is used at the Apache Foundation. You can either contribute as an individual (assuming you didn't do the code for a company), or as a company. Here are the two contracts: 

Individual:

 

 
Then the easiest is simply to submit a patch file with your changes on our public Jira here : 
http://jira.jahia.org
 
Let me know if you have any questions.
 
Best regards,
  Serge Huber.

Serge Huber (shuber)

Number of messages  271
Registration date
0 (0 Good)
0 (0 Bad)

Re: Re: Re: Re: Creating a Custom Annotation for Jahia Actions

by  sashok »  2016/02/26 09:34

Bump

 

Can we see this implemented into Jahia soon please :) ? I never had the time to see all the contractual stuff you have provided me with..

Is it possible to commit it on your github repo ?

 

Best Regards,

Alexander KIRILOV

  (sashok)

Number of messages  14
Registration date
0 (0 Good)
0 (0 Bad)

подарок своими руками лучший подарок

by  WilliamCok »  2017/09/03 12:41

подарок своими руками лучший подарок http://cllon.ru
WilliamCok
Number of messages  1
Not registered
Contact
Share
Feedback

Get in touch

Whether you are a current user or if you are just evaluating Jahia, we are here to help.

Contact us

Share this page