Question

In Liferay, the Configuration Action class is defined in liferay-portlet.xml The problem is, if I use any spring dependency injection, it's not working.

<portlet>
    <portlet-name>search</portlet-name>
    <icon>/icon.png</icon>
    <configuration-action-class>com.mypack.MyConfigurationAction</configuration-action-class>
    <header-portlet-css>/css/main.css</header-portlet-css>
    <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
    <css-class-wrapper>search-portlet</css-class-wrapper>
    <add-default-resource>true</add-default-resource>
</portlet>

Action Class implementation

public class MyConfigurationAction extends DefaultConfigurationAction {

    private @Value("${test.property1}") String property1;
    private @Value("${test.property2}") String property2;
}

How do I inject these properties into this Action class, without using ClassPathXmlApplicationContext and hard coding spring.xml file in the class

Était-ce utile?

La solution

There are two ways to save preferences in portlet development[in liferay],

  1. Through liferay specific way, which uses liferay-portlet.xml entry . cant be managed with spring.

  2. JSR-286[portal agnostic], portlet EDIT mode.

While developing portlet with Spring MVC framework, its advisable to use portlet EDIT mode.

In Spring MVC portlet framework, you can map portlet requests by portlet mode.

For Example: Create controller class as below which will map to EDIT mode requests.

@Controller
@RequestMapping("EDIT")
public class PreferencesController

with two methods, one method with annotation @RenderMapping, responsible for view and other method with annotation @ActionMapping/@RequestMapping responsible for storing preferences.

Hope this would help.

Autres conseils

Try this

portlet.xml

<supports>
.....
<portlet-mode>edit</portlet-mode>
</supports>

Controller class

@Controller
@RequestMapping(value = "EDIT")
 public class XYZ{
}

HTH

First of all, "Configuration" is NOT "Edit" mode. If you enable Edit mode (as suggested by others), you'll get "Preferences" button in your portlet menu. It is a Liferay feature that you can override as per your requirement.

I have Not tried this myself but you can try to use @Autowired to AutoWire your MyConfigurationAction class (and possibly use @Required annotation if needed?). Don't forget to put <context:annotation-config/> in your applicationContext.xml file, if not already done.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top