Get the validation message for a specific component

前端 未结 2 1232
日久生厌
日久生厌 2021-01-14 13:48


        
2条回答
  •  鱼传尺愫
    2021-01-14 14:24

    The problem you will have with what you're planning is that a single component can have more than one message queued. What are you going to do then? For demonstration purposes, you can use

    
    

    EDIT : You should just move the logic into your backing bean:

    1. Implement a method that'll pull the detail from an available FacesMessage list, given a clientId

      public String getComponentMessageDetail(String clientId) {
          String detail = null;
          FacesContext ctxt = FacesContext.getCurrentInstance();
          List componentMessages = ctxt.getMessages(clientId);
      
          if (componentMessages != null && componentMessages.isEmpty() == false) {
              //returns the detail, from only the first message!
              detail = componentMessages.get(0).getDetail();
          }
      
          return detail;
      }
      
    2. Use the utility method in your view

       
      

提交回复
热议问题