I am creating a portlet where in the view and edit modes apply. I want a situation whereby and update switches the portlet from the edit mode to the view mode. Below is my code snippet
@ManagedBean(name = "portletBackingBean")
@ViewScoped
public class FirstPortlet extends GenericFacesPortlet implements Serializable {
private transient Logger logger = LoggerFactory.getLogger(getClass());
private void doActionResponse(PortletMode mode){
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext =
facesContext.getExternalContext();
ActionResponse actionresponce = (ActionResponse) externalContext.getResponse();
try {
actionresponce.setPortletMode(mode);
} catch (PortletModeException e) {
// TODO Auto-generated catch block
LiferayFacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Error setting property"));
}
}
private String userName;
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
//submitting the values
public void doSubmit(){
if(this.userName != null) {
logger.debug("value of property in backing bean set to " + getUserName());
doActionResponse(PortletMode.VIEW);
}
}
So far all is well, but then the portlet renders in view mode, the value of #{portletBackingBean.userName}
is null.
Please is there a more elegant way of doing this
Thanks in advance