I am building portlets on vaadin 7 and wanted to provide configuration info by means of portlet modes. However, the control does not seem to enter the handleResourceRequest method at all.
The display remains the view mode display even in the edit mode.
Please help me understand how I can get the control to enter the handleResourceRequest in the first place.
I have put in the appropriate support tags in portlet.xml file - without which the edit mode would not even show up.
Thanks,
public class MyPortletUI extends UI implements PortletListener{
....
@Override
public void handleResourceRequest(ResourceRequest request,
ResourceResponse response, UI uI) {
System.out.println("==== HandleResourceRequest ====");
if (request.getPortletMode() == PortletMode.EDIT){
setContent(getEditContent());
System.out.println("==== Edit Mode ====");
}
else if (request.getPortletMode() == PortletMode.VIEW) {
setContent(getViewContent());
System.out.println("==== View Mode ====");
}
this.environment = request.getPreferences();
}
Thanks for you reply. I changed it as per your sample.
@Override
protected void init(VaadinRequest request) {
System.out.println("==== Entering Init ====");
if (request instanceof VaadinPortletRequest){
final VaadinPortletRequest r = (VaadinPortletRequest) request;
final PortletMode m = r.getPortletRequest().getPortletMode();
if(m == PortletMode.EDIT){
System.out.println("==== Entering EDIT Mode ====");
setContent(getEditContent());
}else {
System.out.println("==== Entering VIEW Mode ====");
setContent(getViewContent());
}
}
}
However, changing to the edit mode has no impact. Infact the init method above never gets
called when edit mode is entered. So, I always see the view regardless of what mode the portlet
is in..
The two URLS
http://localhost:8080/web/guest/ipc?p_p_id=SenscioUsersTable_WAR_adminportlet001SNAPSHOT&p_p_lifecycle=0&p_p_state=normal&p_p_mode=edit&p_p_col_id=column-1&p_p_col_count=2
http://localhost:8080/web/guest/ipc?p_p_id=SenscioUsersTable_WAR_adminportlet001SNAPSHOT&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=2
Turns out this works on Tori because it overrides preserveUIOnRefresh to return false in VaadinPortletService (this initializes a new Vaadin UI on browser refresh).
You can either do that or use your original solution and handle the check on handleRenderRequest(). Add the PortletListener to VaadinSession like so: