tags:

views:

10

answers:

2

Hi

Is it possible to add ajax to the struts2 tags ,textfeild or checkbox in jsp page using DOJO ? if yes how ?

Or if not what library should i use to apply ajax to single textField ?

Thanks

A: 

Take a look at the Struts2 jQuery Plugin.

This contains an AJAX Textfield Tag for Struts2.

jogep
A: 

To use DOJO, First of all add the DOJO tag directive like this

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

and then add the following line in the head part of your JSP

<sx:head debug="false" cache="false" compressed="true" />

Then listen the event from the struts tag on which you want to apply the ajax as follows

<s:radio label="Radio" name="rad" list="list2"  
                onchange="show_details();" ></s:radio>

catch this event in javascript and publish the topic as follows

<script>
    function show_details() {
        dojo.event.topic.publish("show_detail");
    }
</script>

And listen the published topic on the same JSP by struts div tag

<sx:div showLoadingText="false" id="details" href="DetailAction" theme="ajax"
    listenTopics="show_detail" formId="frm_demo"></sx:div>

The argument "show_detail" in the script call and div tag's listenTopics attribute should match exactally. That div will listen the topic and pick up the href attribute and matches with the action in struts.xml

<action name="DetailAction" class="ajaxdemo.action.DetailAction">
            <result>/Detail.jsp</result>
</action>

It will call your action class ajaxdemo.action.DetailAction

and selects the values according to the value given by radio button and renders the following JSP Detail.jsp

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

<s:if test="lstList != null">
    <s:select list="lstList"></s:select>
</s:if>

and places the out put where you have defined your div tag in your main JSP

You can also view the detail example on java-tale.blogspot.com

Jitendra