留言板

Customer @Annotation does not work in backing bean

thumbnail
Eric Chow,修改在7 年前。

Customer @Annotation does not work in backing bean

Junior Member 帖子: 79 加入日期: 05-2-25 最近的帖子
Hello,

I tried to create an annotation for using in JSF backing bean but it seems not render or not take effect.

Does the Liferay 7 support annotation?



Best regards,
Eric
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Hi Eric,

can you ellaborate about which annotation do you want to use and the purpose of the same?

Thanks.
thumbnail
Eric Chow,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Junior Member 帖子: 79 加入日期: 05-2-25 最近的帖子
Hi Juan,

I just want to use annotation to inject the ResourceBundle into the JSF backing bean. But it seems not inject anything into that property.
Or I miss something. Please help.

Best regards,
Eric



@Qualifier
@Retention(RUNTIME)
@Target({ TYPE, METHOD, FIELD, PARAMETER })
public @interface AppMessageBundle {
}



public class AppMessageBundleProvider {
	private ResourceBundle bundle;

	@Produces
	@AppMessageBundle
	public ResourceBundle getBundle() {

		
		if (this.bundle == null) {
			FacesContext context = FacesContext.getCurrentInstance();
			Locale locale = context.getViewRoot().getLocale();
			bundle = ResourceBundle.getBundle("i18n", locale);
		}

		return this.bundle;
	}
	
	
}




@ManagedBean(name="circularBean")
@ViewScoped
public class CircularHandler {

	@Inject
	@AppMessageBundle
	protected ResourceBundle bundle;
}
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Eric Chow:
Hi Juan,

I just want to use annotation to inject the ResourceBundle into the JSF backing bean. But it seems not inject anything into that property.
Or I miss something. Please help.

Best regards,
Eric



@Qualifier
@Retention(RUNTIME)
@Target({ TYPE, METHOD, FIELD, PARAMETER })
public @interface AppMessageBundle {
}



public class AppMessageBundleProvider {
	private ResourceBundle bundle;

	@Produces
	@AppMessageBundle
	public ResourceBundle getBundle() {

		
		if (this.bundle == null) {
			FacesContext context = FacesContext.getCurrentInstance();
			Locale locale = context.getViewRoot().getLocale();
			bundle = ResourceBundle.getBundle("i18n", locale);
		}

		return this.bundle;
	}
	
	
}




@ManagedBean(name="circularBean")
@ViewScoped
public class CircularHandler {

	@Inject
	@AppMessageBundle
	protected ResourceBundle bundle;
}


So you are talking about CDI, not "simple" annotations.

Please can you try our CDI demo portlet and check if it works?
thumbnail
Eric Chow,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Junior Member 帖子: 79 加入日期: 05-2-25 最近的帖子
Hi Juan,

Those annotations "@Named, @ViewedScope , etc" are worked fine and I am using in my projects.

But my problem is that it does not work if I want to implement my own annotation for using in the backing bean.

It can't be inject my own implementation annotation into the backing bean. Please refer to my code in my previous post.


Best regards,
Eric
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Can you attach a simple sample portlet so we can try to reproduce?

Thanks!
thumbnail
Eric Chow,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Junior Member 帖子: 79 加入日期: 05-2-25 最近的帖子
Juan Gonzalez:
Can you attach a simple sample portlet so we can try to reproduce?

Thanks!



Hi Juan,

Sorry not reply for a long time. I just prepared a portlet. Please test it.

Best regards,
Eric
thumbnail
Eric Chow,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Junior Member 帖子: 79 加入日期: 05-2-25 最近的帖子
Hi Juan,

Did you test the portlet about the CDI in the backing bean?


Best regards,
Eirc
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Unfortunately not. Will try to check it ASAP.
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Hi Eric.

I could make your custom annotations working using mentioned cdi-portlet demo as a base.

As what I saw in the provided web.xml, seems you're using this portlet in a Jboss app server. In case your JBoss provides a CDI implementation, you should import the needed CDI libraries using jboss-deployment-structure like made here: jboss-deployment-structure.xml.

Additionally, you should add a filter in web.xml (and remove PortletServlet, as it's being added automatically by Liferay). Take a look at the web.xml for JBoss in demo portlet for more info.

In order to make this easier, I would recommend using jsf-cdi portlet as a base for your first portlet so you can avoid this known issues when configuration isn't appropiate. Remember to use "jboss" Maven profile when building so all files are configured for JBoss.

Hope it helps!
thumbnail
Eric Chow,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Junior Member 帖子: 79 加入日期: 05-2-25 最近的帖子
Hi Juan,

Thanks for your testing. I am not using JBoss server but tested it in Liferay 7.0 + Tomcat.

The resource bundle cannot be injected into the backing bean? It always return null!

Best regards,
Eric
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Customer @Annotation does not work in backing bean

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Eric Chow:
Hi Juan,

Thanks for your testing. I am not using JBoss server but tested it in Liferay 7.0 + Tomcat.

The resource bundle cannot be injected into the backing bean? It always return null!

Best regards,
Eric


Same sucessfull results in Liferay 7 + Tomcat.

As I said, please use our jsf-cdi applicant demo portlet as a base and write here your doubts/results.

Thanks!