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?
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: