Gowthamraj Somanathan Gowthamraj Somanathan - 2 months ago 11
Java Question

Jquery dialog textboxes value binding is not working

i am not able to get textbox value from jquery dialog, below is my code

$("#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 Code

<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 Code

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


I am able to call the button method from jsf page.
But I am getting null values for all the three textboxes in my java code. please help me.

Answer

Remove

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

Change your button like this:

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

(I suppose jquery is able to find all related ids)