struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ManiKanta G <manikanta.g...@sifycorp.com>
Subject Re: [S2] Ajax error
Date Wed, 10 Sep 2008 12:08:29 GMT
Thanks Dave.

Yes, from action class I m returning entire jsp page.

Action class:

    public class TimeServer extends ActionSupport {
       
        private Date date = null;
       
        public String execute() throws InterruptedException  {
            System.out.println("Request received...");
            date = new Date();
            return SUCCESS;
        }

        public Date getDate() {
            return date;
        }
    }

Config:
    <package name="ajaxdemo" extends="struts-default">
    <action name="TimePage" >
        <result>/pages/listtime.jsp</result>
    </action>
        <action name="Time" 
class="com.timeserver.struts2.action.TimeServer">
            <result>/pages/listtime.jsp</result>
        </action>
    </package>

initially I m requesting TimePage.action.

 >> I'd guess that its result is returning an entire page, rather than 
an HTML fragment, which is what you'd probably want.
How can I return HTML fragment? you mean another jsp page which contains 
only that html fragment? If it is the case I may have to create many 
small jsps, which may in the order of 100s. Or you talking about some 
thing else?

And is there any way to substitute the <s:submit...> with <s:a..>. I've 
tried with this, but only submit is making request to action.

Thanks for resource links.

Regards,
ManiKanta G


Dave Newton wrote:
> --- On Wed, 9/10/08, ManiKanta G wrote:
>   
>>     ...
>>     <head>
>>         <s:head theme="ajax"/>
>>     </head>
>>
>>     <body>
>>         Current time from server
>>         <s:div cssStyle="border: 1px solid red;"
>>                theme="ajax" id="timeDiv">
>>             <s:date name="date"/>
>>         </s:div>
>>         <br>
>>         <s:form action="Time">
>>             <s:submit theme="ajax" targets="timeDiv" 
>>                       notifyTopics="time"/>
>>         </s:form>
>>     </body>
>>     ......
>>
>> It is getting time from server asynchronously, but the
>> <s:div ...> is 
>> displaying the whole page again inside it.
>>
>> What am I doing wrong?
>>     
>
> Hard to say, since you don't provide any information about the "Time" action used by
your <s:form...> tag. I'd guess that its result is returning an entire page, rather
than an HTML fragment, which is what you'd probably want.
>
>   
>> Can some one tell or direct me to some good example about ajax 
>> usage in S2, when to and how to use listenTopic/notifyTopics.
>>     
>
> You use listen topics when you want something (component, JavaScript, etc.) to pay attention
to published events, and notify topics when you want to publish an event.
>
> Your example above could be reduced to (more or less; I have no way to test at the moment):
>
> <s:div id="timeDiv" href="%{#url}"></s:div>
>
> <s:form action="Time">
>   <s:submit theme="ajax" targets="timeDiv"/>
> </s:form>
>
> Where #url is the URL of an action that returns the current date, probably the same as
the form action.
>
> As for documentation:
>
> S2.1: http://struts.apache.org/2.x/docs/ajax-tags.html
> S2.0: http://struts.apache.org/2.0.11/docs/ajax-tags.html
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>   




********** DISCLAIMER **********
Information contained and transmitted by this E-MAIL is proprietary to 
Sify Limited and is intended for use only by the individual or entity to 
which it is addressed, and may contain information that is privileged, 
confidential or exempt from disclosure under applicable law. If this is a 
forwarded message, the content of this E-MAIL may not have been sent with 
the authority of the Company. If you are not the intended recipient, an 
agent of the intended recipient or a  person responsible for delivering the 
information to the named recipient,  you are notified that any use, 
distribution, transmission, printing, copying or dissemination of this 
information in any way or in any manner is strictly prohibited. If you have 
received this communication in error, please delete this mail & notify us 
immediately at admin@sifycorp.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message