Jsf 执行托管bean操作方法后显示警报()
我有一个命令链接:Jsf 执行托管bean操作方法后显示警报(),jsf,alert,facelets,Jsf,Alert,Facelets,我有一个命令链接: <h:commandLink value="Delete" onclick="return confirm('Are you sure?');" action="#{bean.deleteDestination(destination, '/destination/show')}" /> 它调用此托管bean操作方法: public String deleteDestination(Destination selected, String
<h:commandLink value="Delete"
onclick="return confirm('Are you sure?');"
action="#{bean.deleteDestination(destination, '/destination/show')}" />
它调用此托管bean操作方法:
public String deleteDestination(Destination selected, String action) {
List<Flight> flights = getEjbFlightFacade().findFlightWithDestination(selected);
if (flights.isEmpty()) {
getEjbDestinationFacade().remove(selected);
setDestinations(getEjbDestinationFacade().findAll());
}
else {
// Here need to show an alert() that user can't remove the item.
}
return action;
}
public String deleteDestination(已选择目的地,字符串操作){
List flights=getEjbFlightFacade().findFlightWithDestination(选中);
if(flights.isEmpty()){
getEjbDestinationFacade().remove(选中);
setDestinations(getEjbDestinationFacade().findAll());
}
否则{
//这里需要显示一个警报(),说明用户无法删除该项。
}
返回动作;
}
如注释所示,我想显示一个
警报()
,说明最终用户无法删除该项。如何实现这一点?让JSF基于bean属性有条件地呈现所需的脚本
例如
警报为soo 1990
this.undeleteable = true;
<h:outputScript rendered="#{bean.undeleteable}">
alert("You can't delete it.");
</h:outputScript>
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("You can't delete it."));
<h:messages globalOnly="true" />