Showing results for 
Search instead for 
Did you mean: 

Accessing javascript from the dynpage

Former Member
0 Kudos


I am creating the JSP from within the dynpage. So in the doProcessBeforeOut() I am creating the tableviews and assiging components into it.

I need to create a javascript that would display a confirmation message before the user deletes a record. On the SAP website, there is a sample code that helps do that. Although I followed the example, the code doesn't seem to be able to access and read the javascript file.


In the dynpage:


IPortalComponentRequest request = (IPortalComponentRequest) getRequest();

String jsResource = request.getWebResourcePath() + "/";

this.getPageContext().getDocument().addHeadResource(ResourceType.JAVASCRIPT, "test", jsResource);

In the confirmation.js file: just for now, and to simplify it further I am just displaying an allert


function warn(){

alert("will be deleted")


In the dynpage again: where I am defining the button component


Button btnDelete = new Button("btnDelete");



//then I am adding the button to the form

btnDelete.setClientEvent(EventTrigger.ON_CLICK, "warn()");

Did anybody face the same problem? If yes, what would you suggest to do?


Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If you want a quick solution then add the javascript by add the following lines.

String script = "<script>function warn(){alert("will be deleted")}</script>";

Rest of your code is fine.

Message was edited by: Prakash Singh

Answers (1)

Answers (1)

Former Member
0 Kudos


Your following line is incorrect.

String jsResource = request.getWebResourcePath() + "/";

it should be

String jsResource = request.getWebResourcePath() + "/scripts/confirmation.js";

you should also use the onClientClick attribute of the button. The setClientEven shoud work fine as well.


Former Member
0 Kudos

the jsResourse was in fact as you have suggested and didn't work, thats why I changed it to the way it is now, I thought maybe it could not locate the confirmation.js file. But even with the changes you have suggested, it doesn't do anything. I click on Delete button and nothing happens and when I view the source code of the page, I can't find any reference to the method warn().

Any suggestions?