如何更改首选项以使每个窗口显示不同的内容?

时间:2012-08-28 07:57:43

标签: jboss preferences portlet jsr286 jboss-portal

我试图覆盖偏好值,但没有覆盖。 有谁知道如何解决这个问题?

portlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
    <portlet>
        <portlet-name>cool_portlet</portlet-name>
        <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>view</portlet-mode>
        </supports>
        <supported-locale>en</supported-locale>
        <resource-bundle>com.app.portlet.cool_portlet</resource-bundle>
        <portlet-info>
            <title>Cool Portlet</title>
        </portlet-info>     
        <portlet-preferences>
            <preference>
                <name>KEY</name>
                <value>TEST</value>
                <read-only>false</read-only>
            </preference>
        </portlet-preferences>
    </portlet>
</portlet-app>

portlet的instances.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE deployments PUBLIC "-//JBoss Portal//DTD Portlet Instances 2.6//EN" "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
<deployments>
   <deployment>
      <instance>
         <instance-id>coolPortlet_IMPORT_newInstance</instance-id>
         <portlet-ref>cool_portlet</portlet-ref>
          <preferences>
              <name>KEY</name>
              <value>IMPORT</value>
          </preferences>
      </instance>
   </deployment>
    <deployment>
        <instance>
            <instance-id>coolPortlet_EXPORT_newInstance</instance-id>
            <portlet-ref>cool_portlet</portlet-ref>
            <preferences>
                <name>KEY</name>
                <value>EXPORT</value>
            </preferences>
        </instance>
    </deployment>
</deployments>

cool_portlet-object.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE deployments PUBLIC "-//JBoss Portal//DTD Portlet Instances 2.6//EN" "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
<deployments>
    <deployment>
        <parent-ref>comportal.import</parent-ref>
        <if-exists>overwrite</if-exists>
        <window>
            <window-name>impWindow</window-name>
            <content>
                <content-type>portlet</content-type>
                <content-uri>coolPortlet_IMPORT_newInstance</content-uri>
            </content>
            <region>center</region>
            <height>1</height>
            <supported-window-states>
                <window-state>normal</window-state>
                <window-state>maximized</window-state>
                <window-state>minimized</window-state>
            </supported-window-states>
            <initial-window-state>normal</initial-window-state>
        </window>
    </deployment>
    <deployment>
        <parent-ref>comportal.export</parent-ref>
        <if-exists>overwrite</if-exists>
        <window>
            <window-name>expWindow</window-name>
            <content>
                <content-type>portlet</content-type>
                <content-uri>coolPortlet_EXPORT_newInstance</content-uri>
            </content>
            <region>center</region>
            <height>1</height>
            <supported-window-states>
                <window-state>normal</window-state>
                <window-state>maximized</window-state>
                <window-state>minimized</window-state>
            </supported-window-states>
            <initial-window-state>normal</initial-window-state>
        </window>
    </deployment>
</deployments>

MainController.java

@RequestMapping(value = "VIEW")
@Controller(value = "mainController")
public class MainController {
    @RenderMapping
    public String init(@RequestParam(value = "key", required = false) String key, Model model, PortletRequest request) throws Exception {
        PortletPreferences preferences = request.getPreferences();
        String preferencesKey = preferences.getValue("KEY", "Not Found!!!");
        System.out.println("KEY is : " + preferencesKey);
        model.addAttribute("preferencesKey", preferencesKey);
        return "index";
    }
}

输出:

13:49:54,860 INFO  [STDOUT] KEY is : TEST
13:50:21,088 INFO  [STDOUT] KEY is : TEST

1 个答案:

答案 0 :(得分:1)

您需要调用setValue然后存储PortletPreferences对象。请注意,首选项只能存储在操作阶段。 visit