Re: Conditional HTTP 404 response, only with validation?

Splash Forums PrettyFaces Users Conditional HTTP 404 response, only with validation? Re: Conditional HTTP 404 response, only with validation?

#20883

PrettyFaces allows to send custom HTTP response codes using the PrettyContext class. Here is a simple example that shows how I solve the validation issue in my projects:

<url-mapping id="report">
<pattern value="/report/#{reportBean.id}/details" />
<view-id>...</view-id>
<action>#{reportBean.loadData}</action>
</url-mapping>

@Named
@RequestScoped
public class ReportBean {

private Long id;

@Inject
private ReportDao reportDao;

@URLAction
public void loadData() {

Report report = reportDao.getById(id);
if(report == null) {
PrettyContext.getCurrentInstance().sendError(404);
return;
}

// more stuff here

}

/* Getters + Setters */

}

I hope this helps! :)