【问题标题】:Show alert() after executing managed bean action method执行托管 bean 操作方法后显示 alert()
【发布时间】:2015-05-18 17:16:35
【问题描述】:

我有一个命令链接:

<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;
}

如评论所示,我想显示最终用户无法删除该项目的alert()。我怎样才能做到这一点?

【问题讨论】:

    标签: jsf alert facelets


    【解决方案1】:

    让 JSF 根据 bean 属性有条件地呈现所需的脚本。

    例如

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

    警报是 soo 1990。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 2017-06-21
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多