You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Musachy Barroso <mu...@gmail.com> on 2007/05/21 21:58:09 UTC
Re: ajax - Submit a form
Use a regular submit (no ajax) and see if you values are submitted.
musachy
On 5/21/07, Mansour <ma...@yahoo.com> wrote:
>
> I still don't what wrong with this. I fixed few problems but still can
> not get the javascript function to execute when the request is being
> made. It send the request but the values for the form are not populated.
> Hopefully someone can find out what's wrong with my code.
>
>
>
>
> <script type="text/javascript" language="javascript">
> dojo.event.topic.subscribe("/disableAll" , function(data, type, request) {
> showMessage();
> });
> </script>
>
> <table>
> <tr>
> <td><s:a href="javascript://"
> onclick="changeState(true);">edit</s:a>
> <td><s:url id="ajaxSubmit" value="/updateAccount.action" ></s:url>
>
> <s:submit theme="ajax" href="%{ajaxSubmit}" formId="MyData"
> notifyTopics="/disableAllfd" > save </s:submit>
>
> </td>
> </tr>
> </table>
>
>
>
> ---------------------------------------------------------------------
> 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: ajax - Submit a form
Posted by Mansour <ma...@yahoo.com>.
I FOUND IT. Apparently it's not possible to modify the DOM during the
request. But when it's over we can do it:
Here's the code:
<script type="text/javascript" language="javascript">
dojo.event.topic.subscribe("/disableAll" , function(data , type, request) {
if (type == 'load') {
disableInputs(true);
}
});
</script>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ajax - Submit a form
Posted by Mansour <ma...@yahoo.com>.
I am still having this problem. Did any one went through some thing
similar when using ajax to submit a form from a link or a submit Button
and when used notifyTopic ?
The problem is that the form fields are never populated in the action !
Any help ?
Mansour wrote:
> No, I can not see any thing logged. Here' the whole JSP. it should
> give you an idea about what I am doing. I am trying to save/update an
> account and run a JS to disable the inputs.
>
>
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
> <%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
>
> <s:head theme="ajax" debug="true"></s:head>
>
> <script type="text/javascript">
> function disableInputs(flag)
> {
> if (flag == 'null') flag = true;
> var inputs = document.getElementById("data_table");
> inputs = inputs.getElementsByTagName('input');
> for ( i = 0 ;i < inputs.length ; i++ )
> inputs[i].disabled = flag ;
> }
>
> function showMessage(){
> alert('test message!');
> disableInputs(true);
> }
> </script>
>
> <!-- show the account details -->
>
> <table id="data_table" >
> <s:form id="MyData" action="/updateAccount.action" >
> <tr>
> <td><s:label value="AccId:" /></td>
> <td><s:property value="acc.id" />
> <s:hidden name="acc.id" value="${acc.id}" id="acc.id"
> /></td>
> </tr>
>
> <tr>
> <td><s:label value="First Name" /></td>
> <td><s:textfield name="acc.firstName" disabled="true"
> value="${acc.firstName}" /></td>
> </tr>
> <tr>
> <td><s:label value="Last Name: " /></td>
> <td><s:textfield name="acc.lastName" disabled="true"
> value="%{acc.lastName}" /></td>
> </tr>
> <tr>
> <td>
> <s:submit href="/updateAccount.action"
> value="Save from inside the form w/o ajax" > </s:submit>
> </td>
> </tr>
> </s:form>
>
> </table>
>
> <hr />
>
> <script type="text/javascript" language="javascript">
> dojo.event.topic.subscribe("/disableAll" , function(data, type,
> request) {
> showMessage();
> });
> </script>
>
> <table>
> <tr>
> <td><s:a href="javascript://"
> onclick="disableInputs(false);">edit</s:a>
> <td><s:url id="ajaxSubmit" value="/updateAccount.action" ></s:url>
> <s:submit href="%{ajaxSubmit}" notifyTopics="/disableAll"
> theme="ajax" formId="MyData" > save </s:submit>
> </td>
> </tr>
> </table>
>
>
>
> ---------------------------------------------------------------------
> 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: ajax - Submit a form
Posted by Mansour <ma...@yahoo.com>.
No, I can not see any thing logged. Here' the whole JSP. it should give
you an idea about what I am doing. I am trying to save/update an account
and run a JS to disable the inputs.
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<s:head theme="ajax" debug="true"></s:head>
<script type="text/javascript">
function disableInputs(flag)
{
if (flag == 'null') flag = true;
var inputs = document.getElementById("data_table");
inputs = inputs.getElementsByTagName('input');
for ( i = 0 ;i < inputs.length ; i++ )
inputs[i].disabled = flag ;
}
function showMessage(){
alert('test message!');
disableInputs(true);
}
</script>
<!-- show the account details -->
<table id="data_table" >
<s:form id="MyData" action="/updateAccount.action" >
<tr>
<td><s:label value="AccId:" /></td>
<td><s:property value="acc.id" />
<s:hidden name="acc.id" value="${acc.id}" id="acc.id" /></td>
</tr>
<tr>
<td><s:label value="First Name" /></td>
<td><s:textfield name="acc.firstName" disabled="true"
value="${acc.firstName}" /></td>
</tr>
<tr>
<td><s:label value="Last Name: " /></td>
<td><s:textfield name="acc.lastName" disabled="true"
value="%{acc.lastName}" /></td>
</tr>
<tr>
<td>
<s:submit href="/updateAccount.action"
value="Save from inside the form w/o ajax" >
</s:submit>
</td>
</tr>
</s:form>
</table>
<hr />
<script type="text/javascript" language="javascript">
dojo.event.topic.subscribe("/disableAll" , function(data, type, request) {
showMessage();
});
</script>
<table>
<tr>
<td><s:a href="javascript://"
onclick="disableInputs(false);">edit</s:a>
<td><s:url id="ajaxSubmit" value="/updateAccount.action" ></s:url>
<s:submit href="%{ajaxSubmit}" notifyTopics="/disableAll"
theme="ajax" formId="MyData" > save </s:submit>
</td>
</tr>
</table>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ajax - Submit a form
Posted by Musachy Barroso <mu...@gmail.com>.
If you add <s:head debug="true" /> and use the ajax theme, is any error
logged?
musahcy
On 5/21/07, Mansour <ma...@yahoo.com> wrote:
>
> Yes they are submitted provided that the submit button is inside the
> form. Here's my code :
>
>
> <tr>
> <td>
> <s:submit href="/updateAccount.action"
> value="Save from inside the form w/o ajax" >
> </s:submit>
> </td>
> </tr>
> </s:form>
> </table>
> <hr />
>
> <script type="text/javascript" language="javascript">
> dojo.event.topic.subscribe("/disableAll" , function(data, type,
> request) {
> showMessage();
> });
> </script>
>
> <table>
> <tr>
> <td><s:a href="javascript://"
> onclick="disableInputs(false);">edit</s:a>
> <td><s:url id="ajaxSubmit" value="/updateAccount.action" ></s:url>
> <s:submit href="%{ajaxSubmit}" notifyTopics="/disableAll"
> theme="ajax" formId="MyData"> save using ajax </s:submit>
> </td>
> </tr>
> </table>
>
>
>
>
> ---------------------------------------------------------------------
> 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: ajax - Submit a form
Posted by Mansour <ma...@yahoo.com>.
Yes they are submitted provided that the submit button is inside the
form. Here's my code :
<tr>
<td>
<s:submit href="/updateAccount.action"
value="Save from inside the form w/o ajax" >
</s:submit>
</td>
</tr>
</s:form>
</table>
<hr />
<script type="text/javascript" language="javascript">
dojo.event.topic.subscribe("/disableAll" , function(data, type,
request) {
showMessage();
});
</script>
<table>
<tr>
<td><s:a href="javascript://"
onclick="disableInputs(false);">edit</s:a>
<td><s:url id="ajaxSubmit" value="/updateAccount.action" ></s:url>
<s:submit href="%{ajaxSubmit}" notifyTopics="/disableAll"
theme="ajax" formId="MyData"> save using ajax </s:submit>
</td>
</tr>
</table>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org