Home Struts Struts Struts2.2.1 Tags Struts2.2.1 Ajax div tag example.

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 Ajax div tag example.
Posted on: January 20, 2011 at 12:00 AM
Advertisement
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>

<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>

</body>

</html>

2_ div.jsp

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

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

<html>

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

<script type="text/javascript">

function toggleAlert(){

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

}

function toggleDisabled(e1)

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

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

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

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

</script></head>

<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>

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

<div id="formdata">

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

<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>

</s:form></div>

<sx:div

href="%{devResult}"

errorText="Error in loaging"

loadingText="reloading"

updateFreq="3000"/>

</body>

</html>

3_ showInDiv.jsp

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

<html>

<head><title>Ajax_Div_Tag_Example</title>

</head>

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

<% Date today= new Date();

out.println(today); %>

</body>

</html>

4_ resultPage.jsp

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

<html>

<head><title>Ajax_Div_Tag_Example</title>

</head>

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

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

</body>

</html>

5_ AjaxDivAction.java

package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;

public class AjaxDivAction extends ActionSupport{

private String name;

private String age;

public String getAge() {

return age;

}

public void setAge(String age) {

this.age = age;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String execute() {

return SUCCESS; } }

6_ struts.xml

<struts>

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

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

<action name="divpage">

<result>div.jsp</result>

</action>

<action name="devResult" >

<result >showInDiv.jsp</result>

</action>

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

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

</action></package>

</struts>

Output

Download Source Code

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


DMCA.com