2012-08-28 28 views
0

我想重寫首選項的值,但沒有任何重寫。 有誰知道如何解決這個問題?如何更改首選項以便每個窗口顯示不同的內容?

的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 
+0

您是否以擁有管理員權限的用戶身份登錄? – mod

回答

1

你需要調用的setValue,然後儲存您PortletPreferences對象。請注意,首選項只能存儲在操作階段。 visit

相關問題