I am doing this in JSF 2.0. I have implemented add and view pages with same controller. I don't know if it's best practise to use same controller, is it? As in this example it uses single page for all add,edit, view but I have different pages. So when migrating from view page to edit page I want to preserve value but I can't. How to preserve value between different pages in same controller? The output consoles shows the value of edit changes from true to false which I change to true in editLegendType function.
@ManagedBean
@ViewScoped
public class LegendController implements Serializable {
LegendDTO legendDTO = new LegendDTO();
String selectedLegend;
boolean edit;
public LegendController() {
Logger.getLogger(LegendController.class.getName()).warning("The size of list" + edit);
if (!edit) {
legendDTO.getList().add(new Legend());
Logger.getLogger(LegendController.class.getName()).warning("The size of list" + legendDTO.getList().size());
}
}
//All function from here is to legend edit
public String editLegendType(LegendDTO dto) {
edit = true;
legendDTO = dto;
Logger.getLogger(LegendController.class.getName()).warning("The size of list" + edit);
return "addLegend";//from view page to addPage for edit.
}
}