wood burning stoves 2.0*
The moose likes Spring and the fly likes Setting radio button value dynamically and rendering partially after ajax request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Setting radio button value dynamically and rendering partially after ajax request" Watch "Setting radio button value dynamically and rendering partially after ajax request" New topic
Author

Setting radio button value dynamically and rendering partially after ajax request

Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
Hi , i trying with spring mvc and jquery.

what i want to do is render radio button value dynamically and display them with the onchange event of the select box.

What i have done is, i have a spring mvc form which contains a select box. on the onchange event , ajax query using jquery is performed.

In the back end , i have assigned the values for the radio button in a seesion variable . And finally i'm rendering the division containing the radio button . (Trying to do simalar as we do in JSF)


Is there better way to achieve this.

This works well with FF, chrome, opera and safari, but not with IE.
I don't know whethere is should post this in spring forum or jquery as it may be jquery issue as it doesnot work only in IE. My apologies if i posted in the wrong forum , but is this the appropriate way to do.






Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Two things to remember. First all your ${} are rendered on the serverside on the request for the form. It will not be evaluated on Ajax calls once it is on the client side.

I am also surprised that that code worked considering you have


url : "/app/testRadio.htm",

in your Ajax call, but your controller method is mapped to

@RequestMapping(value = "/radioTest", method = RequestMethod.POST)

testRadio != radioTest.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Also, for next time. Use the CODE tags when you post code so the formatting remains. The Code button is above when added a post.

Thanks

Mark
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
Hi Mark,

Thanks for the reply.

Actually i mistyped the code in here, in the controller mapping and I am sorry for that.

And i'll use the CODE tag surely.


I've edited my question with my actual code.



In the above code , after I get the values in the back end and set in the "session variable" with the ajax call , what i have done in the call back is





that is, i've tried to call the same url and show the radio button in the div with the new value that was set in the 'session variable' .

this works fine in FF, chrome , safari and opera but not in IE , am i doing something wrong or is it the javascript problem.

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

So how is



even working after your ajax call anywhere. If you do an ajax call the c:forEach and any ${} won't get evaluated on the client side, that is JSTL that gets evaluated on the server side.

It will work on your very first request for the full page, but any stuff after that it wouldn't get evaluated. Unless somehow you just delete that and the load brings down a fragment of html. But your Controller method for that request in Ajax to return a Boolean. you wouldn't on the client side even have access to the Session object which is stored on the Server side.

That is where I am getting confused in your posted code.

Thanks

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

There still might be other issues with your Javascript with IE. That I am not an expert in, so couldn't figure that out. The JavaScript forum would be a better place to post that. But I still see issues with JSTL and you trying to have it rendered on the client side.

If you can get JSTL to be evaluated on the client side, I would love to know, and I could use that in my application too. But from my understanding that is all serverside evaluation.

Mark
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
Hi Mark,

Thanks for the reply once again.

What i'm trying to do is to re-render the radio button



The above code is hidden initially during the page load.

The ajax call returns the boolean value after setting the 'session variable' and in the call back function i'm trying to refresh the div containing the above code such that it is rerendered, so ${} jstl should work (please correct me in this).


Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Not on the client side will it evaluate. The serverside is the one whole evaluates it and renders it. Once you have that down on the client side that is it, it is over. So you could have it evaluated on the serverside on the original request, but the outer div has it hidden. Do you ajax call and unhide the outer div and whatever was already there, that shows up. But only the content from the original request, not from any new data you might have put in the server side Session object. You could have all that new data come back with the ajax call, then using JavaScript code add html. But not JSTL, JSTL is strictly serverside evaluation.

Mark
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39

So is there any way such that i can populate the radio button in spring form using javascript, would writing the plain html for radio button and placing the html in the division work , but i think i will need to bind the radio button with the back end then.

How can that be done, please provide with me the idea.

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

So is there any way such that i can populate the radio button in spring form using javascript


Yes, I recommend using JQuery than straight JavaScript. But basically you can call a serverside method that returns a fragment of html, then call the .html() method on the div tag using JQuery.

Something along the lines of, but calling the /customerInformation would return html back

This is JQuery code


so you have to return the html fragment already made up on the serverside and have it passed back.

Example Controller code that returns html. It could render a jsp fragment too. But you will have to look that up to do that.


Hope that clears things up for you.

Mark
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
Hi Mark ,

thanks for the reply and suggestions.

I did that using javascript in the call back function, where i wrote the html to generate the radio button , i forgot to consider that simple html also goes with <form:form> tag and it gets binded with the form during form submission.



Many Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Setting radio button value dynamically and rendering partially after ajax request