Greetings,

I want to know how to handle the Jquery, JSon data in the wicket. What is
the best way to do it.
I have created simple form which sends the json data across to server and
replies back to the form.
I am not sure how to handle the request and response in wicket. I am using
Json-lib 2.1 for jdk1.5
Can anybody analyze the below program and suggest me what is wrong.

demo.html
<head>
        <script src="scripts/jquery-1.2.1.js" type="text/javascript"
charset="utf-8"></script>       
        <script type="text/javascript" charset="utf-8">
                $(document).ready(function() {
                        $("#testForm").submit(sendForm);
                });
                
                function sendForm(e) {
                        e.preventDefault();
                        var data = {
                                field1: $("#field1").val(),
                                field2: $("#field2").val(),
                                field3: $("#field3").val(),
                        };
                        
                        $("#sent .content").html(data.toSource());
                        $.post("demo", "message=[" + data.toSource() + "];", 
receiveForm,
"json");
                };              
        
                 function receiveForm(data) {
                        $("#field1").val(data.field1);
                        $("#field2").val(data.field2);
                        $("#field3").val(data.field3);
                        
                        $("#received .content").html(data.toSource());
                };
        </script>
        
</head>
<body>

<form wicket:id="testForm"  >
        <h1 id="form">Form</h1>
        
        <label for="field1">Field One:</label>
        <input type="text" id="field1" />
        
        <label for="field2">Field Two:</label>
        <input type="text" id="field2" />
        
        <label for="field3">Field Three:</label>
        <input type="text" id="field3" />
        
        <input type="submit" id="submitter" value="Post the data" />
</form>

<div id="sent" class="readout">
        <h1 id="sent_data:">Sent Data:</h1>
        <div class="content">
                
        </div>
</div>
<div id="received" class="readout">

        <h1 id="received_data">Received Data:</h1>
        <div class="content">
                
        </div>
</div>
</body>
</html>

Here is the wicket program to handle this 

demo.java
public class Demo extends BasePage {
        public Demo() {
                
                Form form = new Form("testForm",new 
CompoundPropertyModel(this));
                add(form);
                form.add(new AjaxFormSubmitBehavior(form,"onsubmit"){
                        private static final long serialVersionUID = 1L;        
                

                        protected void onSubmit(AjaxRequestTarget target) {
                                Request request = getRequest();
                                String data = request.getParameter("data");     
                
                                try {
                                        JSONObject jsonData = new JSONObject();
                                        JSONObject selectedNode = 
jsonData.getJSONObject(data);                                 
                                } catch (Exception e) {
                                        throw new RuntimeException("Failed to 
parse selected node from reply: "
+ data);
                                } 
                                //target.addComponent(received)// Add to the 
response data
                        }
                });
        }
}


~Pen
-- 
View this message in context: 
http://www.nabble.com/howto-JSON-Wicket-works--tf4865188.html#a13922782
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to