JSF 2.0: How to skip JSR-303 bean validation?

前端 未结 4 2297
我在风中等你
我在风中等你 2020-12-13 22:05

How to skip JSR-303 Bean validation with JSF, when a button is clicked?

A bit lengthy question to explain a few approaches... Consider a list in a form:



        
4条回答
  •  余生分开走
    2020-12-13 22:22

    Situation: In the page code there is a big form with a lot of input fields. There are several buttons each pointing to separate action in the separate bean.

    A solution that worked for me...

    1. In the page code: add immediate="true" to the button and provide an id for the input fields that You want to use in the bean.
     
    
    
     
    
    1. In the bean doStuff method get the parametes by the name fragment couse before the input name JSF put some other identifiers and the resulting parameter name may look like this: someFormId:j_idt54:someHtmlInputId
    Map params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    if (params != null) {
      for (String k: params.keySet())
          if (k.indexOf("someHtmlInputId") != -1)
              params.get(k); // This is Your input parameter value waiting to be processed ;)
    }
    

提交回复
热议问题