• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

To call and load javascript in struts jsp.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is there anyway to load javascript in stuts application JSP.i am using the below javascript stuff.It works well with normal JSP and html, but in struts JSP its not getting called.Is the anyway to achieve in struts.Even body onload function not works with struts.
<script type="text/javascript">
var pager = new Pager('results', 2);
pager.init();
pager.showPageNav('pager', 'pageNavPosition');
pager.showPage(1);
</script>

Thnx in advance.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

What you're saying makes no sense: all the client sees is HTML; if the HTML being generated is correct, it will work. Something else is clearly happening, because countless people use JavaScript in their Struts JSPs all the time. You'll have to provide more details.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manishhh,
Try to avoid onload in all the situations because onload gets loaded only when the page is completely downloaded.
Also if the library files you are using has already used onload you cannot use that again. I prefer you jQuery ready event instead onload. There are very good reasons,
i. it will load when the DOM is ready, will not wait for the page to get downloaded completely.
ii. you can use it as many times you want.
 
Manishhh Srivastva
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is my JSP.I am using ajax to post request.All javascript functions gets called on click.but
<script type="text/javascript">
alert('1111');
var pager = new Pager('results', 2);
pager.init();
pager.showPageNav('pager', 'pageNavPosition');
pager.showPage(1);
</script>
is not wriiten on click of any event.It never gets executes directly.even i dont get the alert...the same code if i keep as a functions and call it with onClick it gets called, but i cant use onClick..i want to load the stuff with JSP itself....It works well with normal JSP....Any ideas will be highly appreciated...I need to implement paging and its needed on JSP page....

Thnx in advance.



<%@ page import="java.util.List "%>
<%@ page import="com.fairpoint.omweb.web.form.CollocatedForm"%>
<%@ page import="com.fairpoint.omweb.persistence.CollocatedList"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested"%>


<html:form styleId="collocatedForm" >
<% System.out.println("111111"); %>
<table>
<tr valign="top">
<td colspan="2"><logic:messagesPresent message="true">
<html:messages id="msg" message="true">
<font color="red"><b><bean:write name="msg" /></b></font>
<br />
</html:messages>
</logic:messagesPresent></td>
</tr>
<% System.out.println("222222222"); %>
<tr>
<td></td>
<td align="center"><b><font color="red">Collocated ACTLs</font></b></td>
<td></td>
</tr>
</table>
<hr width="100%" color="#99CCFF">
<% System.out.println("333333"); %>
<input type="hidden" name="indexCount" id="indexCount" value="0" />
<table id='addtab' border="1">
<tr bgcolor="#5CB3FF">
<!-- <td valign="top" align="left" width="5%"><input type="checkbox" name="checkboxValue" id="checkboxValue" onclick="selectAll();" /></td> -->
<td valign="top" align="left" width="5%">SELECT</td>
<td valign="top" align="left" width="10%"><b>CLLI CODE</b></td>
<td valign="top" align="left" width="10%"><b>CLLI TYPE</b></td>
<td valign="top" align="left" width="10%"><b>CLLI DECODE</b></td>
<td valign="top" align="left" width="10%"><b>ACNA</b></td>
<td valign="top" align="left" width="10%"><b>Last Modified UserName</b></td>
<td valign="top" align="left" width="15%"><b>Last Modified Date</b></td>

</tr>
<% System.out.println("444444"); %>
<bean:define id="collocationListSize" name="collocatedForm"
type="java.util.ArrayList" property="collocationList"></bean:define>
<% System.out.println("Size is:::" +collocationListSize.size());
int colSize = collocationListSize.size();
System.out.println("Size is:::" +colSize); %>
<input type="hidden" name="colSizeId" id="colSizeId" value="<%= colSize%>" />
<% System.out.println("usocListUtilList test : " + collocationListSize.getClass()); %>
<% CollocatedForm form = (CollocatedForm)request.getAttribute("collocatedForm");
System.out.println("1111122222");
List list = form.getCollocationList();
System.out.println("size of list is::::" +list.size());
CollocatedList listofColl =null;
%>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">aaaaaaaa</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">aaaaaaaa</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">aaaaaaaa</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">aaaaaaaa</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">wwwwwwwwwwww</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">hhhhhh</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">00000000000</td>
<td valign="top" align="left" width="5%">cccccccc</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<tr>
<!--<td valign="top" align="left" width="13%"><input type="checkbox" name="selectedList" id="selectedList"/></td>-->

<% System.out.println("01"); %>
<td valign="top" align="left" width="10%">11111</td>
<td valign="top" align="left" width="5%">22222</td>
<td valign="top" align="left" width="10%">ffffffffff</td>
<td valign="top" align="left" width="10%">hhhhhhhhh</td>
<td valign="top" align="left" width="5%">3333333333</td>
<td valign="top" align="left" width="10%">uuuuuuuuuuuuu</td>
<td valign="top" align="left" width="5%">33333</td>

<% System.out.println("02"); %>

</tr>
<% System.out.println("777777777"); %>
</table>
<div id="pageNavPosition"></div>

<script type="text/javascript">
var pager = new Pager('results', 2);
pager.init();
pager.showPageNav('pager', 'pageNavPosition');
pager.showPage(1);
</script>



<% System.out.println("8888888888888"); %>
<% List validFunction = (List)request.getSession().getAttribute("validUser");%>
<% if(validFunction != null){
if(validFunction.contains("COLLOCATED_ACTLS")){ %>
<br>
<input type='button' name='Add' value='Add Row' onclick="addRow('addtab')" />   
<input type='button' name='DeleteRow' value='Delete Row' onclick="deleteCollocatedRow('addtab')" />   
<input type='button' name='Delete' value='Delete' onClick="deleteCollocatedActls();"/>   
<input type="button" id="btnContinue" value="Save/Update" onClick="saveCollocatedActls();" />
<% }} %>
</html:form>
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.

Also, please try to only post relevant snippets--most of what you've posted is not directly related to the question at hand.

You'll still need to be more specific about how the JSP is being loaded, how you load the JavaScript, configuration details, etc. People use JavaScript in Struts-based JSP pages all the time without issue.
 
Prakash Mani - Attur
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manishhh
As i told you before, use jQuery ready funtion to load all the scripts you want to load when the page gets loaded..
Use the following into your script tag..

In addition to the above, download the jquery library file and import it in your page.. use the below link to download jquery library file jQuery lib file
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic