Re-reading your requirements, it sounds like you want a page initialization code. That is, turn around the flow and don't let entry-points into your page1
call the bean's code, let the bean do that itself:
@ManagedBean @RequestScoped
public class ModifyCDSPageBean {
@Inject @Param(name = TicketConstants.ID_INCIDENT)
private ParamValue<Long> myParam;
@Autowired
private TicketConsoleGTRDao dao;
private List<InfoTravail> travailsList;
@PostConstruct
public void init() {
if (myParam.getValue() != null) {
// do stuff based on the param being set
travailsList = dao.findById(myParam.getValue());
}
}
// getter for travailsList
}
And then include the parameter in your navigation from bean2:
public class Bean2 {
public String save() {
String idIncident = getRequestParameterValue(TicketConstants.ID_INCIDENT);
// do stuff and then return to page1, passing parameter ID_INCIDENT
return String.format("page1?faces-redirect=true&%s=%s",
TicketConstants.ID_INCIDENT, idIncident);
}
If you don't need to execute your view preparation code every time you create ModifyCDSPageBean
(ie, if it's used on other pages, too), look into calling it on your page. If you've got JSF-2.2, try <f:viewAction action="#{modifyCDSPageBean.init}">
or on older versions, <f:event listener="#{modifyCDSPageBean.init()}" type="preRenderView">
.
Note that @PostConstruct
with a @RequestScoped
bean will re-create the bean with each AJAX-request, which is probably not what you want. In that case, try @ViewScoped
.
My code example uses omnifaces' @Param for my lack of knowledge of spring. Maybe they have something similar in the toolkit already (or just call your getRequestParameterValue
from the bean method).