aspose file tools*
The moose likes JSF and the fly likes Jsf rerender using javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Jsf rerender using javascript" Watch "Jsf rerender using javascript" New topic
Author

Jsf rerender using javascript

Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
Hello,

I'm trying to fire a request to a JSP page so it will then submit itself to the server. Is there a way to trigger the server submit via javascript.

I've looked everywhere and can't find an answer, only one that i saw was iceFaces related.

Prefereably looking for a partial submit though a standard submit would be fine.

Thanks,

Leigh
[ April 30, 2008: Message edited by: Leigh Taylor ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61216
    
  66

form.submit() doesn't do it for you?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
I'm not sure. I've included the code to make sure we are on the same page. Is there a good javascript documentation library that you know of so i can familiarise myself with some of the javascript operations?



Thanks,

Leigh

[ April 23, 2008: Message edited by: Leigh Taylor ]
[ April 23, 2008: Message edited by: Leigh Taylor ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61216
    
  66

Your code snippet doesn't help me understand your question. But if you just trying to get a form to submit under script control, the form.submit() method is the way to do it.

With regards to JavaScript docs, T=the JavaRanch Bunkhouse is a great place to start to find books on such subjects.
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
Thanks for your patience Bear.

The form.submit() does indeed do a full scale submit but did not yield the results i was hoping for. Maybe you could point me in the right direction in regards to what i need as i have found no information on something i felt would be common place.

In JSF it will call the getters and setters of the backing bean when the element has been rerendered or modified. I have set a hidden value via my javascript though as far as the JSP is concerned nothing has happened. I would like to trigger the page to 'recheck' itself so it can realise that one of its values has been modified, therefore calling the valueChangeListener on the element and setting the new value in the backing bean.

Is there a way to reRender an element via javascript or if nothing that specific, can the page 'recheck' itself in a sense?

BTW, looks like some good reads in the bunkhouse and the reviews have helped me find a couple of books i think would be useful. Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61216
    
  66

Sounds like you need some JSF-specific help at this point. I've moved this along to the JSF forum where the JSF-savvy can hopefully help you out.
Cindy Smith
Greenhorn

Joined: Nov 26, 2007
Posts: 18
Leigh,
let me see if I understand what is happening.

You have a hidden field with a valueChangeListener. The hidden field is bound to a property in the backing bean.

When you change the value of the hidden field through JavaScript the valueChangeListener is not being invoked. Is this the scenario?
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
Hi Cindy,

Thats exactly what's happening. I'm no pro when it comes to jsf or javascript but thought if i could rerender the hidden field then i could hopefully fire the valueChangeListener or at the very least set the value to the backing bean.
Cindy Smith
Greenhorn

Joined: Nov 26, 2007
Posts: 18
I would try adding this.form.submit( ); to the end of the function you provided above. This should force the hidden field value to be set in the backing bean. But you said you tried this w/o success.

It would be nice if you could place a onChange="this.form.submit( );" in the hidden field tag.

Make sure your have the correct name of the field. JSF can add stuff to your field id and getElementById() may not find it. Check the html generated if not sure.

Could you also post the code for the hidden field tag and a skeleton of your listener?
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
Hi Cindy,

Yeah the form.submit causes the whole page to reset. As i'm displaying a map it resets the whole map and even then doesn't set the values in the backing bean.

Would love to reRender the element from javascript though am having no luck.



I used an inputHidden in this example so that i can easily see the field value being change. I also understand my a4j support is replicating the valueChangeListener though was just seeing if anything was being called, of which it isn't.

The value does change on every click so cannot understand why the valueChangeListener is not being called except for the fact the page may have to 'recheck' itself which i don't know how to invoke.

My java code consists of System.out code to see if the methods are being called.

Thanks,

Leigh
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
The code 'selectedFeatureForm.submit();'

Does actually set the backing bean and call the listener though it still 'resets' the map (though leaves the other fields as they were). I assume this is because the 'body on load="initMap()"' gets called again.
Anyway to avoid this?

[ April 30, 2008: Message edited by: Leigh Taylor ]
[ April 30, 2008: Message edited by: Leigh Taylor ]
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
Found an answer to my problem and thought i'd post it on here.

The selectedFeatureForm.submit(); reloads the whole page and as there is no instance saved of the map (which is client side) the map gets reset.

As i was using RichFaces i could modify my jsf to use a4j forms and thus an attribute 'ajaxSubmit'. So when the submit it called it won't do an entire page submit.


 
Consider Paul's rocket mass heater.
 
subject: Jsf rerender using javascript