Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 执行托管bean操作方法后显示警报()_Jsf_Alert_Facelets - Fatal编程技术网

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" />