2017-02-14 25 views
0

我正在使用功能,如果出現驗證錯誤,那麼goto鏈接將生成一個具有焦點()的頁面頂部所需組件的ID。單擊該鏈接時,所需組件將突出顯示。現在它的工作,如果錯誤是在同一個標​​籤。但是第一個選項卡是主動對焦功能,不會將指定的文本框指向第三個選項卡。javascript focus()不適用於從prime1中的tab1到tab2

void encodeGotoLabel(FacesContext context, UIComponent component, ResponseWriter writer, 
      FacesMessage msg) throws IOException { 
      String id = getid(context, msg); 
      if (id != null && !FacesMessage.SEVERITY_INFO.equals(msg.getSeverity()) 
       && !FacesMessage.SEVERITY_FATAL.equals(msg.getSeverity())) { 
       String inputLabel = findInputLabel(context, id); 

       if (inputLabel != null) { 
        ResourceBundle bundle ="bundle"; 

        writer.writeText(" (", null); 
        writer.writeText(bundle.getString("goTo") + " ", null); 
        writer.startElement("a", component); 
        writer.writeAttribute("href", "javascript:document.getElementById('" + id 
         + "').focus();", 
         null); 
        writer.writeText(inputLabel, null); 
        writer.endElement("a"); 
        writer.writeText(")", null); 
       } 
      } 
     } 
+0

也許元素ID是一樣的,所以你只能得到第一個元素。 – user1087079

+2

問題不清楚,你需要什麼? –

+0

你想切換到哪裏有驗證錯誤的選項卡? –

回答

0

此函數循環在一組選項卡,並檢查是否有錯誤,如果是,則切換到它,並專注於必填字段,所有你需要做的就是添加它在你的函數:

var tabs = PF('tabViewWv').getLength(); //tabViewWv is WidgetVar name 
for (var iter = 1; iter <= tabs ; iter++) { 
    if ($('#form\\:tabView\\:tab' + iter).find(':input').hasClass('ui-state-error')) { 
     PF('tabViewWv').select(iter - 1); 
     return false; 
    } 
} 
相關問題