You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mansour <ma...@yahoo.com> on 2007/06/13 05:54:59 UTC

updating a DIV with ajax submit

I am able to submit, and I can see the results back. However, the 
results are not inserted into the DIV and replacing the old contents. 
It's inserted just before the old contents.



<div id="tasksDIV"><s:include value="tasks.jsp" /></div>


<s:submit type="image" src="/context/images/fdisk.gif"
    href="%{ajaxSubmit}"     theme="ajax"  notifyTopics="/updateOrSave" 
targets="tasksDIV" />



The new resulting page becomes like this

<div id="tasksDIV"> (The New Contents Here) <s:include value="tasks.jsp" 
/></div>


Any idea?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: updating a DIV with ajax submit

Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning Mansour

you will need to initialise your Ajax div tag with your own Placeholder
to quote the doc before asynchronously retrieving contents of href attribute 
initialise your Div Tag with Placeholder data..
(in this example the Response from 
href="http://www.weather.com/weather?zip=97239 will asynchornously populate 
our Ajax Div 'weather' Tag )

<saf:div theme="ajax" id="weather" 
href="http://www.weather.com/weather?zip=97239">
    Placeholder...
</saf:div>
http://struts.apache.org/2.0.6/docs/ajax-div-template.html
You can also autopopulate the div tag based on any other control (we use 
select) whos einteractions update a particular (listened) Topic e.g.

<saf:head theme="ajax" />

<script type="text/javascript">
    function updateReports(id) {
       var reportDiv= window['reportDivId'];
       reportDiv.href = '/../reportListRemote.action?selectedId='+id;
       reportDiv.bind();
    }
    dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null, 
"updateReports");
</script>/*dojo.event.topic.getTopic ties the 1st paramter of requested 
topic to previously published topic of 'updateReportsListTopic'*//*The 
subscribe 2nd param 'updateReports' indicates JS function to update when new 
events are reported*/<form ... >
<saf:select .... onchange="javascript: 
dojo.event.topic.publish("updateReportsListTopic", this.value); " />
<saf:div id="reportDivId" theme="ajax" href="/.../reportListRemote.action" >
  Loading reports...
</saf:div>
</form>

HTH
M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Mansour" <ma...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, June 15, 2007 10:19 PM
Subject: Re: updating a DIV with ajax submit


>I can  see expected out put coming back. And when I view the page source 
>it's even there in the right place but not rendered on the browser!
> On both FF and IE
>
>
>
>
>
> Mansour wrote:
>> Seriously, no one can answer this one?
>>
>> OK, the DIV is not updating at all now. Do i need to use JS to manually 
>> set the content of the DIV ?
>> Shouldn't it update auto magically?
>>
>> Mansour wrote:
>>> I am able to submit, and I can see the results back. However, the 
>>> results are not inserted into the DIV and replacing the old contents. 
>>> It's inserted just before the old contents.
>>>
>>>
>>>
>>> <div id="tasksDIV"><s:include value="tasks.jsp" /></div>
>>>
>>>
>>> <s:submit type="image" src="/context/images/fdisk.gif"
>>>    href="%{ajaxSubmit}"     theme="ajax"  notifyTopics="/updateOrSave" 
>>> targets="tasksDIV" />
>>>
>>>
>>>
>>> The new resulting page becomes like this
>>>
>>> <div id="tasksDIV"> (The New Contents Here) <s:include value="tasks.jsp" 
>>> /></div>
>>>
>>>
>>> Any idea?
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: updating a DIV with ajax submit

Posted by Mansour <ma...@yahoo.com>.
I solved the problem. I don't know why but it resolved. Never mind.
Here the old code:

<div id="tasksDIV"><s:include value="tasks.jsp" /></div>

and task.jsp contains this:


<table id="row">
    <thead>
        <tr>
            <th>Service Name</th>
            <th>Unit Count</th>
            <th>cost</th>
            <th>Date Completed</th>
         </tr>
    </thead>
    <tbody>
<s:form id="tasks">

.......  

</s:iterator>
</s:form>
</tbody>
</table>


For some reason this was not updating the contents of the tbody and 
never dispalyed.
When I moved the form tag to surround the whole tasks page it worked 
fine. SO this is the new code:

<s:form id="tasks">

<table id="row">
    <thead>
.....
</s:iterator>

</tbody>
</table>
</s:form>






Musachy Barroso wrote:
> Well, that's all Struts will do, insert the html in  the target element
>
> musachy
>
> On 6/15/07, Mansour <ma...@yahoo.com> wrote:
>>
>>
>> Jeff Amiel wrote:
>> > I assume the value of  %{ajaxSubmit} is a struts action...?
>> > And you are sure it is actually putting NEW content in the div after
>> > the image is clicked on?
>> >
>> Yes, the value of %{ajaxSubmit} is an action.
>>
>> <table>
>>     <s:url id="ajaxSubmit" value="/updateTaskList.action" />
>>     <s:submit id="save_btn"
>>         type="image" src="/fe/pages/images/fdisk.gif" 
>> href="%{ajaxSubmit}"
>>         theme="ajax" notifyTopics="/updateOrSave" targets="tasksDIV"
>>         formId="tasks"  />
>> </table>
>>
>> And yes, the html is inserted in DIV. I checked it with FF DOM 
>> inspector.
>>
>> >
>> >
>> > On 6/15/07, Mansour <ma...@yahoo.com> wrote:
>> >> I can  see expected out put coming back. And when I view the page
>> source
>> >> it's even there in the right place but not rendered on the browser!
>> >> On both FF and IE
>> >>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: updating a DIV with ajax submit

Posted by Musachy Barroso <mu...@gmail.com>.
Well, that's all Struts will do, insert the html in  the target element

musachy

On 6/15/07, Mansour <ma...@yahoo.com> wrote:
>
>
> Jeff Amiel wrote:
> > I assume the value of  %{ajaxSubmit} is a struts action...?
> > And you are sure it is actually putting NEW content in the div after
> > the image is clicked on?
> >
> Yes, the value of %{ajaxSubmit} is an action.
>
> <table>
>     <s:url id="ajaxSubmit" value="/updateTaskList.action" />
>     <s:submit id="save_btn"
>         type="image" src="/fe/pages/images/fdisk.gif" href="%{ajaxSubmit}"
>         theme="ajax" notifyTopics="/updateOrSave" targets="tasksDIV"
>         formId="tasks"  />
> </table>
>
> And yes, the html is inserted in DIV. I checked it with FF DOM inspector.
>
> >
> >
> > On 6/15/07, Mansour <ma...@yahoo.com> wrote:
> >> I can  see expected out put coming back. And when I view the page
> source
> >> it's even there in the right place but not rendered on the browser!
> >> On both FF and IE
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

Re: updating a DIV with ajax submit

Posted by Mansour <ma...@yahoo.com>.
Jeff Amiel wrote:
> I assume the value of  %{ajaxSubmit} is a struts action...?
> And you are sure it is actually putting NEW content in the div after
> the image is clicked on?
>
Yes, the value of %{ajaxSubmit} is an action.

<table>
    <s:url id="ajaxSubmit" value="/updateTaskList.action" />
    <s:submit id="save_btn"
        type="image" src="/fe/pages/images/fdisk.gif" href="%{ajaxSubmit}"
        theme="ajax" notifyTopics="/updateOrSave" targets="tasksDIV"
        formId="tasks"  />
</table>

And yes, the html is inserted in DIV. I checked it with FF DOM inspector.

>
>
> On 6/15/07, Mansour <ma...@yahoo.com> wrote:
>> I can  see expected out put coming back. And when I view the page source
>> it's even there in the right place but not rendered on the browser!
>> On both FF and IE
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: updating a DIV with ajax submit

Posted by Jeff Amiel <je...@gmail.com>.
I assume the value of  %{ajaxSubmit} is a struts action...?
And you are sure it is actually putting NEW content in the div after
the image is clicked on?



On 6/15/07, Mansour <ma...@yahoo.com> wrote:
> I can  see expected out put coming back. And when I view the page source
> it's even there in the right place but not rendered on the browser!
> On both FF and IE
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: updating a DIV with ajax submit

Posted by Mansour <ma...@yahoo.com>.
I can  see expected out put coming back. And when I view the page source 
it's even there in the right place but not rendered on the browser!
On both FF and IE





Mansour wrote:
> Seriously, no one can answer this one?
>
> OK, the DIV is not updating at all now. Do i need to use JS to 
> manually set the content of the DIV ?
> Shouldn't it update auto magically?
>
> Mansour wrote:
>> I am able to submit, and I can see the results back. However, the 
>> results are not inserted into the DIV and replacing the old contents. 
>> It's inserted just before the old contents.
>>
>>
>>
>> <div id="tasksDIV"><s:include value="tasks.jsp" /></div>
>>
>>
>> <s:submit type="image" src="/context/images/fdisk.gif"
>>    href="%{ajaxSubmit}"     theme="ajax"  
>> notifyTopics="/updateOrSave" targets="tasksDIV" />
>>
>>
>>
>> The new resulting page becomes like this
>>
>> <div id="tasksDIV"> (The New Contents Here) <s:include 
>> value="tasks.jsp" /></div>
>>
>>
>> Any idea?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: updating a DIV with ajax submit

Posted by Mansour <ma...@yahoo.com>.
Seriously, no one can answer this one?

OK, the DIV is not updating at all now. Do i need to use JS to manually 
set the content of the DIV ?
Shouldn't it update auto magically?

Mansour wrote:
> I am able to submit, and I can see the results back. However, the 
> results are not inserted into the DIV and replacing the old contents. 
> It's inserted just before the old contents.
>
>
>
> <div id="tasksDIV"><s:include value="tasks.jsp" /></div>
>
>
> <s:submit type="image" src="/context/images/fdisk.gif"
>    href="%{ajaxSubmit}"     theme="ajax"  notifyTopics="/updateOrSave" 
> targets="tasksDIV" />
>
>
>
> The new resulting page becomes like this
>
> <div id="tasksDIV"> (The New Contents Here) <s:include 
> value="tasks.jsp" /></div>
>
>
> Any idea?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org