One of our developers wrote a portlet that uses the doView method to render relevant content. However, we are receiving NPE's if the user goes to a page under a valid route of that portlet with no valid record.
An example is:
/<location>/<postcode>/<propertyname>
/london/w1/10-downing-street - VALID
/london/w1/sdsd-downing-streetsss - INVALID
The slug will pull the record from the db as it's unique but if it's invalid it throws an NPE on fillRenderRequestAttributes and we need it to throw a status 404.
Code
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
fillRenderRequestAttributes(renderRequest, renderResponse);
if(_log.isDebugEnabled())
{
_log.debug("DoView");
}
try
{
super.doView(renderRequest, renderResponse);
}
catch(Exception e)
{
_log.debug("Broken");
e.printStackTrace();
}
}
I assume we need a try/catch around fillRenderRequestAttributes and in the catch we need to throw a 404? How can this be done? Any examples would be helpful.