Calling backing Bean and Javascript Function simultaneously - javascript

Can anyone please help me in finding the solution?
I have a h:commandButton which calls a action and fires actionListener after that.
But due to change in requirements I have removed the action attribute and added onclick Javacript function which calls a customized dialog. So now, the actionListener is not being fired where i have set some values using the button value.
Please tell me if there is any alternative in solving this.

U can use the below code inside the jquery
document.form[0].sumbit();
this line will submit the form to back end bean

Related

How to add more then one event to the jsf tag graphicImage

How can I add more then one event to the jsf tag graphicImage? I would like to distinguish between left-mouse, right-mouse and double-click.
The idea was to do something as follows:
<h:graphicImage value="/image.jpg" onclick="doClick()" ondblclick="doDblClick()"/>
I'am suggesting use jquery in similar way as it is shown in this answer. This can help you recognize which mouse button was pressed and then call concrete function.

How to know when asp.net ajax request has completed?

I have an asp.net web form with a button, label, scriptmanager and updatepanel controls. When I click the button, the label changes using ajax. How can I detect the change in the label using javascript?
You need to use add_endRequest,
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
function endRequestHandler(sender, args)
{
alert("ended");
}
You are using ajax to change or update something on some event. If it changes naturally your output will be changed. If it is some kind of change that doesn't change output but change any attribute then
1. Install firebug addon2.use it when firing your ajax function.
3. On console mode you will see any change of error which you are expecting from the code
You can use update progress for this purpose.
Here is a good example for update progresshttp://www.devmanuals.com/tutorials/ms/aspdotnet/updateprogress.html

Usage issue with HTMLAjaxCommandButton

I am using HTMLAjaxCommandButton with methodexpression set for action. When this button is clicked, corresponding action gets invoked but what I'm trying now is to submit the form before the binded method gets invoked. For that purpose, I was using setOnClick method of HTMLAjaxCommandButton to provide Javascript for form submission. This is working fine in firefox but has issues in Chrome. Reason being action expression also gets converted to Ajax call present in onClick method on Button. So, effectively now we have two methods getting called up from onClick. Chrome do not like this!
Anyone has idea about it or a better way to deal with this scenario.
Issue is resolved. I removed setAjaxSingle and setImmediate for HtmlAjaxCommandButton. Now, everything works fine. We don't need to have javascript for form submission.

Going back to a JSP page after a prticular action is being done.

I have a JSP page. Let's say page1.jsp. I have some java script code written in Script tags where in i call particular function inside which i just simply do window.location to some URL(http://localhost:8080/ATT/jsp/page2.jsp) where a particular action is being performed. Now once an action is completed on page2.jsp i want to come back on page1.jsp without any user click event or any other event. Should i do window.location(http://localhost:8080/ATT/jsp/page1.jsp) or is there any other approach i can follow. Please suggest me an answer. thanks.
You can use .sendRedirect()
response.sendRedirect(redirectURL);
Example:
response.sendRedirect("http://localhost:8080/ATT/jsp/page1.jsp");
You only other option is history.back()

What is the meaning of __doPostBack function, and when is it used?

I had problem triggering server side button click events so I found a solution on the net that I should do something like
<input type="submit" name="button" id="loginButton" value="Submit"
class="button-orange" alt="Register" title="Register" runat = "server" onclick ="this.disabled=true;__doPostBack('loginButton','')"/>
I did it, and it worked, but I would like to know what is going on!
Check this article:
Understanding the JavaScript __doPostBack Function
This method is used to submit (post back) a form to the server and allows ASP.NET framework to call appropriate event handlers attached to the control that raised the post back.
You usually (in simple scenarios) don't use the method directly - it is internally used by the controls you drop on the page.
The parameters passed to this function are stored in a hidden field and picked up by ASP.NET framework on the server-side in order to find the control that raised the post back.
simply said, it is used mainly by controls with AutoPostBack property
http://www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx
if you want to implement autopostback for your custom control, then you need to implement IPostBackDataHandler
The solution might be working but it's not a real fix.. better way will be to find why the button events are not triggering and fix the core of the problem.
Now to answer your questions.. PostBack is the term used to describe when the form is being submitted (posted) back to the same page. Simple as that.
Ordinary submit button would have been enough, but part of PostBack is the ability to identify which control triggered it, meaning what button or link was clicked.
To do such a thing ASP.NET is automatically adding hidden fields to the form and when clicking on element that should cause PostBack, JavaScript code is used to update the values of those hidden fields to the proper values indicating what was clicked - the argument you pass.
The name Microsoft chose to give to the JS function doing the above is __doPostBack - it's just a name of a function, ordinary JavaScript function that ASP.NET automatically writes to the browser.
Hope things are bit more clear now.

Categories