cancel
Showing results for 
Search instead for 
Did you mean: 

How to invoke a onClick call to JSP method from Javascript

Former Member
0 Kudos

Currently developing in the JSP Dynpage model in EP 5, but will also be developing in EP 6, once we get our hands on the installer.

My Question is, with the above environment, how do you force a call to the JSP method from a javascript call, in the case where you are using Client Side eventing, and want to mimic a Button Click, etc...

In the JSP page I have a HTMLB button defined as

<hbj:button id='Load' text="Load WorkBench" onClick="clickLoad" onClientClick="Validate()"/>

and the method clickLoad is in my Dynpage to handle when the user clicks on it.

I also know how to cancel the submit process of the button click in a call from the Validate() function with:

htmlbevent.cancelSubmit=true;

But, if I was in a seperate javascript function that is subscribed to some client event, how would I make the iView call that method clickLoad, as if the user clicked on that button. Also, would like to know how to do this genericly and not just for a button. It was the easiest way to explain it using a button.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Vivek,

If you don't want to button to show, you can hide it in a span with the style-sheet with similar code below:

<SPAN STYLE="visibility: hidden">

<hbj:button id='buttonEvent' text="" onClick="clickEvent"><% strbuttonEventId = yourContext.getParamIdForComponent(buttonEvent); %> </hbj:button>

</SPAN>

You can then trigger the button's onClick event via Javascript call such as:

document.all.<%=strbuttonEventId%>.click();

This should work fine, and i've used the above solution for the trigger of the event.

Former Member
0 Kudos

Thanks Jorge.

Vivek

Former Member
0 Kudos

Jorge,

I did the same as what you have mentioned.

But for some reason I could n't get it done.

I declared strTest as String(also tried as Object) at the top of the JSP.

While in javascript, tried printing strTest in an alert stmt.It printed null for strTest.

Am I missing something here?

Your help will be really appreciated.

Thanks

Former Member
0 Kudos

I got it.

The reason being, I had the javascript code before the hidden button code and that caused the error.

Thanks for your help.

Former Member
0 Kudos

One method that did work was to add an htmlb element into the page, that has an onClick event, such a button. Set it to be invisible via stylesheets, then trigger the client button click via javascript.

You will then be able to have the server side event handler kick in, and do whatever is needed.

Hope that helps.

Former Member
0 Kudos

Jorge,

How can we trigger the client button click via javascript.

Can you please share the code, if you were successfull in doing it.

Thanks,

Former Member
0 Kudos

If I understand your question, you would need the listener iView to invoke submit() on the form of the iView that has the "clickLoad" Dynpage event handler.

Former Member
0 Kudos

Jorge,

I'm curious to know if you were able to get this working based on Will's suggestion to invoke the submit() object. I've been encountering the same issue you are describing and am looking for a solution. I tried Will's solution, but I couldn't get it working. If you got this working, I would be interested in seeing a code example if possible.

Thanks,

Kevin