我已经使用重定向机制开发了整个JSF项目,并且效果很好。由于我想提高性能,因此我认为前进机制是一种很好的方法。由于我遇到了一些问题,因此我需要一些帮助。我将展示如何在应用程序中使用导航:
@Named(value = "customersView")
@RequestScoped
public class CustomersView implements Serializable {
public String onNewElement() {
return "create?faces-redirect=true";
}
public String onEditElement(Customer seleceted) {
this.selected = seleceted;
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("customer", seleceted);
return "create?faces-redirect=true";
}
这是我的list.xhtml
文件:
<p:menuButton style="float:right;" icon="ui-icon-person-add"
value="Add customer">
<p:menuitem value="New" icon="ui-icon-create"
outcome="#{customersView.onNewElement()}" />
然后,我具有处理创建客户的组件:
@Named
@javax.faces.view.ViewScoped
public class CreateCustomerView implements Serializable {
@Inject
CustomerController customerController;
private Customer customer;
private boolean edit;
@PostConstruct
public void init() {
edit = FacesContext.getCurrentInstance().getExternalContext().getFlash().containsKey("customer");
if (edit) {
this.customer = (Customer) FacesContext.getCurrentInstance().getExternalContext().getFlash()
.get("customer");
FacesContext.getCurrentInstance().getExternalContext().getFlash().keep("customer");
} else {
this.customer = new Customer();
}
this.municipalities = new MunicipalityParser().parse();
this.provinces = new ArrayList<>();
for (Municipality municipality : municipalities) {
if (!provinces.contains(municipality.getProvince())) {
provinces.add(municipality.getProvince());
}
}
}
public String onCompletedSave() {
customerController.store(customer);
try {
new CardCreator().createCard(customer);
} catch (IOException e) {
e.printStackTrace();
}
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
"The customer " + customer.getSurnameAndName() + " has been saved correctly",
"Coorect!"));
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
return "list?faces-redirect=true";
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
如何以最简单的方式切换到转发机制?
这是主菜单:
<pu:menu widgetVar="me">
<p:menuitem id="um_dashboard" value="Home" icon=""
outcome="/s/dashboard" />
<p:submenu id="registries" label="My menu" icon="">
<p:menuitem id="customers" value="Customers"
outcome="/s/customers/list" />
<p:menuitem id="children" value="Children"
outcome="/s/children/list" />
<p:menuitem id="schools" value="Scuole" outcome="/s/schools/list" />
</p:submenu>
是否可以为此实现这种机制?