Vaadin portlet 模式更改
我有一个 Liferay Vaadin portlet,有两种模式:编辑和查看模式。我在 portlet 中看到的第一件事是带有标签的 viewContent :“未配置”,如果 portlet 未配置。现在,如果我在编辑模式下配置 portlet,我会看到我在配置中所做的内容,到目前为止它有效但现在,如果我注销或重新启动浏览器(退出并重新启动),我会看到未配置的 viewContent ,带有标签(“未配置”)
代码:
Window window; // Main Window
VerticalLayout viewContent; // View Mode Content
VerticalLayout editContent; // Edit Mode Content(Configs)
Label viewText;
Button b;
Panel panel;
Embedded PictureA;
public void init() {
window = new Window("");
setMainWindow(window);
viewContent = new VerticalLayout();
editContent = new VerticalLayout();
PictureA = new Embedded("", new ExternalResource(PictureAURL));
PictureA.setType(Embedded.TYPE_IMAGE);
panel = new Panel();
panel.setStyleName(Reindeer.PANEL_LIGHT);
// viewContent
viewText = new Label("Not Configured" , Label.CONTENT_XHTML);
viewContent.addComponent(viewText);
window.setContent(viewContent);
// EditContent
b = new Button("PictureA");
b.addListener(this):
editContent.addComponent(b);
}
public void buttonClick(ClickEvent event) {
if (event.getSource == b) {
viewContent.revomeComponent(viewText);
panel.addComponent(PictureA);
viewContent.addComponent(panel);
}
}
@Override
public void handleRenderRequest(RenderRequest request,
RenderResponse response, Window window) {
}
@Override
public void handleActionRequest(ActionRequest request,
ActionResponse response, Window window) {
}
@Override
public void handleEventRequest(EventRequest request,
EventResponse response, Window window) {
}
@Override
public void handleResourceRequest(ResourceRequest request,
ResourceResponse response, Window window) {
// Switch the view according to the portlet mode
if (request.getPortletMode() == PortletMode.EDIT)
window.setContent(editContent);
else if (request.getPortletMode() == PortletMode.VIEW)
window.setContent(viewContent);
}
情况:如果我单击按钮“PictureA”,标签为“未配置”正在被删除,并且带有嵌入图片的面板正在被添加到 viewContent 中。
唯一的问题是它没有被保存:/也许我忘记了什么?
I have a Liferay Vaadin portlet with two modes : Edit and View mode. The first thing I see in the portlet is the viewContent with a Label : "Not Configured , if the portlet is not configured. Now if I configure the portlet in the Editmode I see the stuff I have made in the configuration, It works so far but now if I log out or restart the Browser (exit and start again) I see the not configured viewContent with the Label ("Not Configured")
Code :
Window window; // Main Window
VerticalLayout viewContent; // View Mode Content
VerticalLayout editContent; // Edit Mode Content(Configs)
Label viewText;
Button b;
Panel panel;
Embedded PictureA;
public void init() {
window = new Window("");
setMainWindow(window);
viewContent = new VerticalLayout();
editContent = new VerticalLayout();
PictureA = new Embedded("", new ExternalResource(PictureAURL));
PictureA.setType(Embedded.TYPE_IMAGE);
panel = new Panel();
panel.setStyleName(Reindeer.PANEL_LIGHT);
// viewContent
viewText = new Label("Not Configured" , Label.CONTENT_XHTML);
viewContent.addComponent(viewText);
window.setContent(viewContent);
// EditContent
b = new Button("PictureA");
b.addListener(this):
editContent.addComponent(b);
}
public void buttonClick(ClickEvent event) {
if (event.getSource == b) {
viewContent.revomeComponent(viewText);
panel.addComponent(PictureA);
viewContent.addComponent(panel);
}
}
@Override
public void handleRenderRequest(RenderRequest request,
RenderResponse response, Window window) {
}
@Override
public void handleActionRequest(ActionRequest request,
ActionResponse response, Window window) {
}
@Override
public void handleEventRequest(EventRequest request,
EventResponse response, Window window) {
}
@Override
public void handleResourceRequest(ResourceRequest request,
ResourceResponse response, Window window) {
// Switch the view according to the portlet mode
if (request.getPortletMode() == PortletMode.EDIT)
window.setContent(editContent);
else if (request.getPortletMode() == PortletMode.VIEW)
window.setContent(viewContent);
}
Situation: if I click on the Button "PictureA" the label "Not Configured" is being deleted and the panel with the embedded picture is being added to the viewContent.
The only problem is that its not being saved :/ Any ideas? Maybe I forgot something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您没有将配置保存在任何地方。当会话结束(关闭浏览器)并重新打开您的应用程序 init 时,将再次执行并恢复原始的“未配置”状态。
例如,您可以将其存储到 portlet 首选项中。在handleResourceRequest 方法中,您必须获取PortletPreferences 的句柄:
要将状态保存在按钮单击处理程序中,请执行以下操作:
此外,您还希望恢复handleResourceRequest 方法中已有的状态。做类似的事情:
Yes, you are not saving the configuration anywhere. When the session ends (closing the browser) and reopened your application init is executed again and original "not configured" state is restored.
You can store it into portlet preferences for example. In the handleResourceRequest method you must grab the handle to PortletPreferences:
To save the state in in the button click handler do:
Also you want to restore the state already in the handleResourceRequest method. Do something like: