Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to rerender a jsf component using javascript

843844Oct 4 2008 — edited Feb 3 2010
Hi,

I need to rerender a jsf component from javascript, and also need to get values from backing bean through javascript, this is my jsf code......
<h:outputText id="abc" value="#{myBean.value}"/>
and i need that "value" in javascript to change and i have to rerender the value in the page, so please suggest me in this problem...

Thanks in advance

Comments

843844
Look for an Ajaxical JSF framework. For example Ajax4jsf, which is part of RichFaces.
843844
it is possible if ajax4jsf is used, but i need to rerender using javascript.......
is there any possibility to rerender the jsf component from the javascript.......?

this is my code......
<h:outputLabel value="delete" onclick="deleteRecord()"/>
<h:datatable id="records" value="myBean.records" var="record">
.........
.......
</h:datatable>
and javascript
function deleteRecord() {
         if(window.confirm("Are you sure you want to delete?")) {
                  // here i need to rerender the records(id) table
         }
}
843844
Pure JS runs at the client side, not at the server side (where JSF runs), so the answer is no.
843844
I mean, can the managed bean object method be called from javascript......
843844
Invoke a request to the server. Submit a form synchronously using form.submit() or fire an ajaxical request asynchronously using XmlHttpRequest and write a Filter and JSF ViewHandler which intercepts the ajaxical request -but this way you're reinventing the wheel which Ajax4jsf already did.
800775
If I am right in understanding your problem, then you do your functionality by simply calling a javascript function on the onlclick
event of your commandButton.
Then in the javascript function call a java function like this ::
java.lang.System.out.println( message );
// Basically FullPackagename.Classname.methodName();
//remember the method should not throw any kind of exception.

Then in the method called, access your managed bean (take from session or request or application scope in which u have kept it)
and call whatever you want.
843844
You're completely wrong.
800775
I don't understand the reason why u said wrong.
This code works perfectly fine ::
<script type="text/javascript">
function callJavaMethod() {
alert("Calling java Method");
var temp = java.lang.Math.random()*100000;
alert(temp);
}
</script>
843844
You don't understand the actual problem. He wanted to invoke a backing bean method at the server, not some lousy standard JDK code at the client.
843844
If managed bean method can be called from javascript, i need to rerender the jsf component also....
i think it is not possible to rerender the jsf component from javascript, but i can get the data from server using XmlHTTPRequest and i can rerender the part of the page using innerHTML property, but i want to alert the jsf component to rerender itself from the javascript, this is what i want to do....
843844
I keep repeating: use an Ajaxical JSF framework, such as Ajax4jsf. It has already done it all for you.

If you don't want to use it for some reasons then create one yourself. But I doubt if you get success since you already ask this level of question here. Learn HTTP. Learn HTML. Learn JS. Learn DOM. Learn XML (or JSON). Learn Ajax. Learn JSP. Learn Servlets/Filters. Learn JSF. Then do the math.
843844
I have the same problem.

I'm using Ajax4jsf and, even so, i dont know how to do it.
Wich and how components i must use.

Thanks for your help.
843844
[<a4j:support />|http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/support.html].
843844
Something in my page calls some jScript function (cannot be other way) to send some infomation to the server and the server sends back an answer.
I can send the data, but i can get the answer back only if include an alert(''); inside the javascript function.... it seems that the the function reach return line before the button rerender itself...... any ideas (Sorry for the english)
....
</a4j:form>
....

<h:inputText  id="input" value="#{SomeBean.variable1}" />
<a4j:commandButton  id="button" action="#{someBean.someMethod}" value="#{SomeBean.answer}" reRender="button" />
.........


<script>

....
function jsFunction(dummyString) {
	   
        document.getElementById('formInitialize:input').value = urlencode(dummyString);
	document.getElementById(formInitialize:button').click();

	answer = document.getElementById("formInitialize:button").value;
	return answer;
	    
	}
</script>
</a4j:form>
....
PhHein
valdivaldi, hi and welcome. Please don't post to long dead threads and don't hijack other people's threads.

I'm locking now.
1 - 15
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 3 2010
Added on Oct 4 2008
15 comments
2,703 views