2014-10-28 91 views
-1

我不能夠從jQuery的對話框中獲得文本框的值,下面是我的代碼jQuery的對話框文本框的值綁定不工作

$("#printbutton").click(function() { 
     $("#print").dialog("open"); 
    }); 

$("#print").dialog({ 
     autoOpen : false, 
     modal : true, 
     resizable : false, 
     draggable : false, 
     show : { 
      effect : "fade" 
     }, 
     hide : { 
      effect : "fade" 
     }, 
     open: function (type, data) { 
      $(this).parent().appendTo("form"); 
     } 
    }); 

JSF代碼

<h:form> 
    <h:panelGroup layout="block" id="print"> 
    <h:inputText value="#{bean.text1}" id="text1"/> 
    <h:inputText value="#{bean.text2}" id="text2"/> 
    <h:inputText value="#{bean.text3}" id="text3"/> 
    <h:commandButton action="#{bean.button} id="printbutton"> 
    </h:panelGroup> 
</h:form> 

的Java代碼

String text1; 
String text2; 
String text3; 

public String getText1() { 
    return text1; 
} 

public void setText1(String text1) { 
    this.text1 = text1; 
} 

public String getText2() { 
    return text2; 
} 

public void setText2(String text2) { 
    this.text2 = text2; 
} 

public String getText3() { 
    return text3; 
} 

public void setText3(String text3) { 
    this.text3 = text3; 
} 

public void button(){ 
    System.out.println(text1); 
    System.out.println(text2); 
    System.out.println(text3); 
} 

我可以從jsf頁面調用按鈕方法。 但我得到我的Java代碼中的所有三個文本框的空值。請幫幫我。

+0

你是什麼讓'null'值的含義爲你的文本框?託管bean的範圍是什麼?我們如何重現您目前的問題? – 2014-10-28 16:15:18

+0

你看過stdout(控制檯)嗎?你有沒有看到任何來自你的texboxes的文字? – 2014-10-28 16:21:43

+0

我正在使用會話範圍來獲取文本框的值。但我得到空值。 – 2014-10-29 17:10:35

回答

1

刪除

$("#printbutton").click(function() { 
     $("#print").dialog("open"); 
    }); 

更改按鈕,這樣的:

<h:commandButton action="#{bean.button} 
       id="printbutton" 
       oncomplete="$('#print').dialog('open');" 
/> 

(我想jQuery是能夠找到所有相關的IDS)

+0

感謝您的回答.... @ Multisync – 2016-07-16 12:06:03