Vaadin portlet 模式更改

发布于 2024-12-08 18:28:56 字数 2122 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦屿孤独相伴 2024-12-15 18:28:56

是的,您没有将配置保存在任何地方。当会话结束(关闭浏览器)并重新打开您的应用程序 init 时,将再次执行并恢复原始的“未配置”状态。

例如,您可以将其存储到 portlet 首选项中。在handleResourceRequest 方法中,您必须获取PortletPreferences 的句柄:

this.prefs = request.getPreferences();

要将状态保存在按钮单击处理程序中,请执行以下操作:

this.prefs.setValues("myapp.configured", new String[] {"true"});
this.prefs.store();

此外,您还希望恢复handleResourceRequest 方法中已有的状态。做类似的事情:

boolean configured = Boolean.parseBoolean(this.prefs.getValues("myapp.configured", new String[] { "false" })[0]);

if (configured && PictureA.getParent() == null) {
    // PictureA is not visible, but it should be.
    viewContent.removeComponent(viewText);
    panel.addComponent(PictureA);
    viewContent.addComponent(panel);
}

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:

this.prefs = request.getPreferences();

To save the state in in the button click handler do:

this.prefs.setValues("myapp.configured", new String[] {"true"});
this.prefs.store();

Also you want to restore the state already in the handleResourceRequest method. Do something like:

boolean configured = Boolean.parseBoolean(this.prefs.getValues("myapp.configured", new String[] { "false" })[0]);

if (configured && PictureA.getParent() == null) {
    // PictureA is not visible, but it should be.
    viewContent.removeComponent(viewText);
    panel.addComponent(PictureA);
    viewContent.addComponent(panel);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文