我想在运行时从代码更改我的 SmartGWT 应用程序的主题
我可以在 SmartGWT 展示中看到这个功能,但在 SmartGWT 展示中我看不到任何代码。
我现在正在做的是
这是我的 XML 类
<?xml version="1.0" encoding="UTF-8"?>
<inherits name="com.smartgwt.SmartGwtNoTheme"/>
<inherits name="com.smartclient.theme.graphite.Graphite"/>
<inherits name="com.smartclient.theme.blackops.BlackOps"/>
<inherits name="com.smartclient.theme.enterprise.Enterprise"/>
<inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlue"/>
这是我的 HTML 类片段
<title>My Web</title>
<script>
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for ( var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}
// Determine what skin file to load
var currentSkin = readCookie('skin');
if (currentSkin == null){
currentSkin = "Enterprise";
}
alert(currentSkin);
</script>
<script type="text/javascript">
document.write("<" + "script src=testtheme/sc/skins/"
+ currentSkin + "/load_skin.js><"+"/script>");
</script>
这是我的 Java 类
SelectItem selectItem = new SelectItem("skin", "Choose Skin");
DynamicForm df = new DynamicForm();
hpnlMain.add(df);
df.setItems(selectItem);
selectItem.setWidth(130);
java.util.LinkedHashMap<String, String> valueMap = new java.util.LinkedHashMap<String, String>();
valueMap.put("Enterprise", "Enterprise");
valueMap.put("EnterpriseBlue", "EnterpriseBlue");
valueMap.put("TreeFrog", "TreeFrog");
valueMap.put("BlackOps", "BlackOps");
valueMap.put("Graphite", "Graphite");
selectItem.setValueMap(valueMap);
String currentSkin = Cookies.getCookie("skin");
if (currentSkin == null) {
currentSkin = "Enterprise";
}
selectItem.setDefaultValue(currentSkin);
selectItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
// TODO Auto-generated method stub
Cookies.setCookie("skin", event.getValue().toString());
Window.Location.reload();
}
});
预期的结果是,当我选择任何皮肤形式SelectItem
时,应该应用该皮肤,但我没有效果。
请查看我的 HTML 文件中的这一行
<script type="text/javascript">
document.write("<" + "script src=testtheme/sc/skins/"
+ currentSkin + "/load_skin.js><"+"/script>");
在这里我不确定确切的路径是什么,我的类路径中有 smatgwt-skins.jar
谢谢