Struts2.2.1 Ajax div tag example.
Posted on: January 20, 2011 at 12:00 AM
In this example, you will see the use of Ajax div tag of struts 2.2.1.

Struts2.2.1 Ajax div tag example.

In this section, we will introduce you to about the Ajax div tag. The div tag when used with Ajax refreshes the content of a particular section without refreshing the entire page.

 1- index.jsp

<html>ADS_TO_REPLACE_1

<head><title>Ajax_Div_Tag_Example</title></head>

<body><h1>Ajax_Div_Tag_Example</h1><hr>

<a href="divpage.action">Ajax_Div_Tag_Example</a><br>ADS_TO_REPLACE_2

</body>

</html>

2_ div.jsp

<%@taglib uri="/struts-tags" prefix="s" %>

<%@taglib uri="/struts-dojo-tags" prefix="sx" %>ADS_TO_REPLACE_3

<html>

<head><title>Ajax_Div_Tag_Example</title><sx:head/>

<script type="text/javascript">ADS_TO_REPLACE_4

function toggleAlert(){

toggleDisabled(document.getElementById("formdata"));

}ADS_TO_REPLACE_5

function toggleDisabled(e1)

{try {e1.disabled=e1.disabled? false: true;} 

catch (E){if(e1.childNodes&& e1.childNodes.length>0){ADS_TO_REPLACE_6

for(var x=0;e1.childNodes,length;x++){

toggleDisabled(el.childNodes[x]);   }  } } }

</script></head>ADS_TO_REPLACE_7

<body><h1>Ajax_Div_Tag_Example</h1><hr>

<s:url id="devResult" action="devResult.action"> </s:url>

<sx:div href="%{devResult}" label="Value of another page in div"></sx:div>ADS_TO_REPLACE_8

<sx:div id="div2" executeScripts="true">Value</sx:div>

<div id="formdata">

<s:form action="resultAction.action">ADS_TO_REPLACE_9

<s:textfield name="name" label="Name"></s:textfield>

<s:textfield name="age" label="Age"></s:textfield>

<sx:submit targets="div2" value="toggleAlert()" onclick="toggleAlert()" ></sx:submit>ADS_TO_REPLACE_10

</s:form></div>

<sx:div

href="%{devResult}"ADS_TO_REPLACE_11

errorText="Error in loaging"

loadingText="reloading"

updateFreq="3000"/>ADS_TO_REPLACE_12

</body>

</html>

3_ showInDiv.jsp

<%@page import="java.util.Date"%>

<html>ADS_TO_REPLACE_13

<head><title>Ajax_Div_Tag_Example</title>

</head>

<body>Hi friends, this is another page data.<br>ADS_TO_REPLACE_14

<% Date today= new Date();

out.println(today); %>

</body>ADS_TO_REPLACE_15

</html>

4_ resultPage.jsp

<%@taglib uri="/struts-tags" prefix="s" %>

<html>

<head><title>Ajax_Div_Tag_Example</title>ADS_TO_REPLACE_16

</head>

<body><hr>Name : <s:property value="name"/><br>

Age : <s:property value="age"/><hr>ADS_TO_REPLACE_17

</body>

</html>

5_ AjaxDivAction.java

package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_18

public class AjaxDivAction extends ActionSupport{

private String name;

private String age;ADS_TO_REPLACE_19

public String getAge() {

return age;

}ADS_TO_REPLACE_20

public void setAge(String age) {

this.age = age;

}ADS_TO_REPLACE_21

public String getName() {

return name;

}ADS_TO_REPLACE_22

public void setName(String name) {

this.name = name;

}ADS_TO_REPLACE_23

public String execute() {

return SUCCESS; } }

6_ struts.xml

<struts>

<constant name="struts.devMode" value="false" />ADS_TO_REPLACE_24

<package name="roseindia" extends="struts-default">

<action name="divpage">

<result>div.jsp</result>ADS_TO_REPLACE_25

</action>

<action name="devResult" >

<result >showInDiv.jsp</result>ADS_TO_REPLACE_26

</action>

<action name="resultAction" class="roseindia.action.AjaxDivAction">

<result name="success">resultPage.jsp</result>ADS_TO_REPLACE_27

</action></package>

</struts>

Output

ADS_TO_REPLACE_28

Download Source CodeADS_TO_REPLACE_29

Related Tags for Struts2.2.1 Ajax div tag example.:

Advertisements

Ads

 
Advertisement null

Ads