You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Olivier THIERRY <ol...@gmail.com> on 2007/04/26 17:02:22 UTC

How to fill a div from an Ajax call when a onchange event is fired ?

Hi,

I used to use Struts 1.x and I just begin to use Struts 2.x
I am very interested with the Ajax feature, but I can't make it work ...

What I need to do looks very classical to me :
- The user types an employee code in a text box
- When the onchange event is fired, I call a Struts action with Ajax
- This action retrieves the firstname and the name of the employee. I want
these informations to be displayed into a div.

I found a similar example in the Struts documentation (bottom of this page :
http://struts.apache.org/2.0.6/docs/ajax-div-template.html ), but I can't
make it work ...

When the onchange event is fired, I have the following Javascript error :

FATAL exception raised: TypeError: infosDemandeurDiv has no properties

Could someone tell me what I did wrong, or if there is an easier method to
do what I want ?

Here is the head section of my jsp :

<head>
    <title>Demande d'absence</title>
    <s:head theme="ajax" debug="true" />
    <script type="text/javascript">
        function updateInfosDemandeur(matricule) {
           var infosDemandeurDiv = window['infosDemandeur'];
           infosDemandeurDiv.href =
'/../employes/getInfosEmploye.action?matricule='
+ matricule;
           infosDemandeurDiv.bind ();
        }
        dojo.event.topic.getTopic("updateInfosDemandeurTopic").subscribe(null,
"updateInfosDemandeur");
    </script>
</head>

... and an extract of the form section ...

    <s:form action="submitCreerDemandeAbsence">
        <s:textfield     name="demandeAbsence.matriculeDemandeur"
                        label="Matricule"
                        onchange="
dojo.event.topic.publish('updateInfosDemandeurTopic',
this.value);" />
        <s:div id="infosDemandeur" theme="ajax" loadingText="Loading
..."></s:div>
        <s:submit type="button" theme="ajax" />
    </s:form>

Thanks in advance

Olivier

Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Olivier THIERRY <ol...@gmail.com>.
As some people asked me by private message, a few words to explain how I
could make it work.
I hope it will help other Struts users ;)

The original need : when the user types an elmployee code, I want to
retrieve his name and firstname and display it in a div.

My action class is as followin (it works with Spring ioc) :
It calls a service class to retrieve employee infos

public class InfosEmployeAction {

    private ServiceEmploye serviceEmploye;
    public ServiceEmploye getServiceEmploye() {
        return serviceEmploye;
    }
    public void setServiceEmploye(ServiceEmploye serviceEmploye) {
        this.serviceEmploye = serviceEmploye;
    }

    private VOEmploye employe;
    public VOEmploye getEmploye() {
        return employe;
    }
    public void setEmploye(VOEmploye employe) {
        this.employe = employe;
    }

    private String matricule;
    public String getMatricule() {
        return matricule;
    }
    public void setMatricule(String matricule) {
        this.matricule = matricule;
    }

    public String  execute() throws Exception {
        if (getMatricule() == null || getMatricule().length() == 0) {
            this.setEmploye(null);
        }
        else {
            this.setEmploye
(getServiceEmploye().getEmployeByMatricule(getMatricule()));
        }
        return "success";
    }

}

An extract from the JSP page from where I call the action :

    <s:url id="urlInfosEmploye" action="getInfosEmploye"
namespace="/employes" />
    <s:form action="submitCreerDemandeAbsence" id="form1">
        <s:textfield     id="matriculeDemandeur"
                        name="demandeAbsence.matriculeDemandeur"
                        label="Matricule"

onchange="dojo.event.topic.publish('updateInfosDemandeurTopic',
this.value);" />
        <s:div     theme="ajax"
                loadingText="Chargement en cours ..."
                href="%{urlInfosEmploye}"
                formId="form1"
                listenTopics="updateInfosDemandeurTopic"
                formFilter="filterInfosDemandeur" />
    </s:form>

The div listens a topic on which I publish when the onchange event is fired
for my text field.
It is bound to the form including the text field, the formFilter is used to
filter informations sent to the action (here the employee code), thanks to
the following JS function :

    <script type="text/javascript">
      function filterInfosDemandeur(field) {
        return field.name == "demandeAbsence.matriculeDemandeur";
      }
    </script>


My Struts action is configured as following :

    <package name="employes" extends="struts-default" namespace="/employes">
        <action name="getInfosEmploye" class="infosEmployeAction">
            <param name="aliases">#{'demandeAbsence.matriculeDemandeur' :
'matricule'}</param>
            <interceptor-ref name="alias" />
            <result name="success">/jsp/employes/infosEmploye.jsp</result>
        </action>
    </package>

The alias interceptor changes the name of parameter to what is expected by
the action.

And finally the infoEmploye.jsp page :

<!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.1 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>

<s:property value="employe.nom" />&nbsp;<s:property value="employe.prenom"
/>

The drawback of this solution is that you have to duplicate getInfosEmploye
action for each JSP page where you want to use it :(
Now it works, but if you have any suggestion to improve it, you're welcome.

And thanks a lot again to Musachy for his help ;)

Olivier

Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Olivier THIERRY <ol...@gmail.com>.
OK, I see. It's something like that ?

        <action name="getInfosEmploye" class="infosEmployeAction">
            <param name="aliases">#{'demandeAbsence.matriculeDemandeur' :
'matricule'}</param>
            <interceptor-ref name="alias" />
            <result name="success">/jsp/employes/infosEmploye.jsp</result>
        </action>

Does it mean I need to create a specific action for any form which will user
the getInfosEmploye action ?
In fact, it would be perfect if you could apply the alias interceptor in the
JSP page, but I'm not sure it could be possible :(

Olivier


2007/4/27, Musachy Barroso <mu...@gmail.com>:
>
> I think the "alias" interceptor would help in this case:
>
> http://struts.apache.org/2.x/docs/alias-interceptor.html
>
> musachy
>
> On 4/27/07, Olivier THIERRY <ol...@gmail.com> wrote:
> >
> > Thanks Musachy, your advices were very helpful.
> >
> > I succeeded in doing what I wanted, but there is still a detail that
> > upsets
> > me with your solution and I'm not totally happy with the solution.
> >
> > The drawback of the solution is that the the parameter I can get in my
> > action has the name of the text field in my JSP page (here "
> > demandeAbsence.matriculeDemandeur"). This reduces the possibility to
> reuse
> > this action in other forms, since the action expects the employee code
> to
> > be
> > sent in a "demandeAbsence.matriculeDemandeur" parameter. But the
> employee
> > code text field can have a different name in other forms ...
> >
> > I found a solution by implementing the ParameterAware interface in my
> > action, so I could get the first (and only) parameter. But of course it
> > won't work if I have more parameters expected.
> >
> > Do you know if there is a way to change the name of the parameters
> before
> > they are sent to the Struts servlet or to the action ?
> >
> > Thanks in advance
> >
> > Olivier
> >
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>

Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Musachy Barroso <mu...@gmail.com>.
I think the "alias" interceptor would help in this case:

http://struts.apache.org/2.x/docs/alias-interceptor.html

musachy

On 4/27/07, Olivier THIERRY <ol...@gmail.com> wrote:
>
> Thanks Musachy, your advices were very helpful.
>
> I succeeded in doing what I wanted, but there is still a detail that
> upsets
> me with your solution and I'm not totally happy with the solution.
>
> The drawback of the solution is that the the parameter I can get in my
> action has the name of the text field in my JSP page (here "
> demandeAbsence.matriculeDemandeur"). This reduces the possibility to reuse
> this action in other forms, since the action expects the employee code to
> be
> sent in a "demandeAbsence.matriculeDemandeur" parameter. But the employee
> code text field can have a different name in other forms ...
>
> I found a solution by implementing the ParameterAware interface in my
> action, so I could get the first (and only) parameter. But of course it
> won't work if I have more parameters expected.
>
> Do you know if there is a way to change the name of the parameters before
> they are sent to the Struts servlet or to the action ?
>
> Thanks in advance
>
> Olivier
>



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

Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Olivier THIERRY <ol...@gmail.com>.
Thanks Musachy, your advices were very helpful.

I succeeded in doing what I wanted, but there is still a detail that upsets
me with your solution and I'm not totally happy with the solution.

The drawback of the solution is that the the parameter I can get in my
action has the name of the text field in my JSP page (here "
demandeAbsence.matriculeDemandeur"). This reduces the possibility to reuse
this action in other forms, since the action expects the employee code to be
sent in a "demandeAbsence.matriculeDemandeur" parameter. But the employee
code text field can have a different name in other forms ...

I found a solution by implementing the ParameterAware interface in my
action, so I could get the first (and only) parameter. But of course it
won't work if I have more parameters expected.

Do you know if there is a way to change the name of the parameters before
they are sent to the Struts servlet or to the action ?

Thanks in advance

Olivier

How to disable a submit button with ajax

Posted by "King, Leon C" <le...@verizonbusiness.com>.
Hi all,

	I have a non-ajax button that I want to disable when my 'ajax'
autocompleter(s) change values.  (I DIDN'T go with the 'ajax' submit
button because it doesn't work with IE 6)   How would I do this?  Is
this even possible?   CODE SNIPPET below:



	
	<script type="text/javascript">
				  function fireevent()
			      {			
	
dojo.event.topic.publish("/countryChanged");		      		
			      }	

			      function fireservingareachanged()
			      {
	
dojo.event.topic.publish("/servingareaChanged");
			      }

			      
			      function firetrafficchanged()
			      {
	
dojo.event.topic.publish("/trafficChanged");
			      }
						      
			      function fireCarrierchanged()
			      {
	
dojo.event.topic.publish("/carrierChanged");
			      }
			      
			      function fireSwitchchanged()
			      {
	
dojo.event.topic.publish("/switchChanged");
			      }
			      
			      function firetrunkchanged()
			      {
	
dojo.event.topic.publish("/switchChanged");
			      }		
	</script>

     
	 <script type="text/javascript">
				dojo.require("dojo.widget.*");
				dojo.require("dojo.widget.ComboBox");	
	

				
				function init()
			      {
	
dojo.widget.byId("destinationCountry").dataProvider.searchLimit = 400;
	
dojo.widget.byId("servingArea").dataProvider.searchLimit = 400;

	
dojo.widget.byId("traffic").dataProvider.searchLimit = 400;
	
dojo.widget.byId("carrier").dataProvider.searchLimit = 400;
	
dojo.widget.byId("switch").dataProvider.searchLimit = 400;

	
dojo.widget.byId("trunk").dataProvider.searchLimit = 400;	
			        
	
dojo.event.connect(dojo.widget.byId("startDateId"), "onValueChanged" , 
	
"fireservingareachanged"); 
	
dojo.event.connect(dojo.widget.byId("endDateId"), "onValueChanged" , 
	
"fireservingareachanged"); 	
	
dojo.event.connect(dojo.widget.byId("servingArea"), "onValueChanged" , 
	
"fireservingareachanged");

	
dojo.event.connect(dojo.widget.byId("destinationCountry"),
"onValueChanged" , 
	
"fireevent"); 	
	
dojo.event.connect(dojo.widget.byId("traffic"), "onValueChanged" , 
	
"firetrafficchanged"); 					
	
dojo.event.connect(dojo.widget.byId("carrier"), "onValueChanged" , 
	
"fireCarrierchanged");

	
dojo.event.connect(dojo.widget.byId("switch"), "onValueChanged" , 
	
"fireSwitchchanged");

								
			      }
      		        	
			      dojo.addOnLoad(init);	

<script>


<s:url id="getTrunk" includeParams="all"
action="CityCountryLevelQueryAction" method="getTrunkForForm"/>

				<s:autocompleter href="%{getTrunk}" 
					id="trunk" 
					name="trunk"
		                   keyName="trunkKey"
autoComplete="false"
		                   theme="ajax" 
		                   label="Trunk"
		                   emptyOption="true"
  	                         formId="cityCountryLevelForm"
  	                         indicator="indicatortrunk"
listenTopics="/trafficChanged,/switchChanged,/carrierChanged,/countryCha
nged" 
		                                forceValidOption="true" 
		                                cssStyle="width:
250px"/>   
		                                <img id="indicatortrunk"
src="images/indicator.gif" alt="Loading..." style="display:none"/>  
								</td>

							 </tr>

				</table>
			</td>

		</tr>
	</table>

	<table>
		
		<tr>
				<td>
					&nbsp;
				</td>
		</tr>
		<tr>
		  <td colspan="4">
		   <img id="submitindicator" src="images/indicator.gif"
alt="Loading..." style="display:none"/>  
    	    <s:url id="submitquery" includeParams="all"  
    	    	action="CityCountryLevelQueryAction"
method="submitQueryResult"/>                            	 
		   
		    <s:submit type="button" id="query"
href="%{submitquery}"
				  label="submit"  targets="tableresults"

				  formId="cityCountryLevelForm"
				  indicator="submitindicator" />
				


Thanks,

Leon

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


Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Musachy Barroso <mu...@gmail.com>.
http://struts.apache.org/2.x/docs/ajax-tags.html

musachy

On 4/26/07, Martin Gainty <mg...@hotmail.com> wrote:
>
> is there a way to make sure all of these parameters as well as the step by
> step instructions are placed in the docs
> Thanks!
>
> Martin--
> 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: "Musachy Barroso" <mu...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Thursday, April 26, 2007 12:05 PM
> Subject: Re: How to fill a div from an Ajax call when a onchange event is
> fired ?
>
>
> > yes, all the values will be sent, but there is a "formFilter" attribute
> > where you can specify a function that will be called for each element,
> and
> > you just need to return true, for the ones that you want to be
> submitted.
> > The function has one parameter, which will be the element.
> >
> > musachy
> >
> > On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
> >>
> >> Thanks a lot, I can call my action now.
> >>
> >> One more question ...
> >> When I set the formId attribute for the div, does it mean that all
> values
> >> in
> >> the form will be sent to my action ?
> >> If it is the case, is there a way to send only the value of my
> textfield
> >> ?
> >>
> >> Olivier
> >>
> >> 2007/4/26, Musachy Barroso <mu...@gmail.com>:
> >> >
> >> > I think it will be easier (and work) like this:
> >> >
> >> > 1. set href in your div, pointing to your action
> >> > 2. set formId in your div pointing to the form that has the text
> field
> >> > 3. add listenTopic to your div
> >> > 4. publish the topic of 3. when the user types in the textbox
> >> >
> >> > musachy
> >> >
> >> > On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
> >> > >
> >> > > Hi,
> >> > >
> >> > > I used to use Struts 1.x and I just begin to use Struts 2.x
> >> > > I am very interested with the Ajax feature, but I can't make it
> work
> >> ...
> >> > >
> >> > > What I need to do looks very classical to me :
> >> > > - The user types an employee code in a text box
> >> > > - When the onchange event is fired, I call a Struts action with
> Ajax
> >> > > - This action retrieves the firstname and the name of the employee.
> I
> >> > want
> >> > > these informations to be displayed into a div.
> >> > >
> >> > > I found a similar example in the Struts documentation (bottom of
> this
> >> > page
> >> > > :
> >> > > http://struts.apache.org/2.0.6/docs/ajax-div-template.html ), but I
> >> > can't
> >> > > make it work ...
> >> > >
> >> > > When the onchange event is fired, I have the following Javascript
> >> error
> >> > :
> >> > >
> >> > > FATAL exception raised: TypeError: infosDemandeurDiv has no
> >> > > properties
> >> > >
> >> > > Could someone tell me what I did wrong, or if there is an easier
> >> method
> >> > to
> >> > > do what I want ?
> >> > >
> >> > > Here is the head section of my jsp :
> >> > >
> >> > > <head>
> >> > >     <title>Demande d'absence</title>
> >> > >     <s:head theme="ajax" debug="true" />
> >> > >     <script type="text/javascript">
> >> > >         function updateInfosDemandeur(matricule) {
> >> > >            var infosDemandeurDiv = window['infosDemandeur'];
> >> > >            infosDemandeurDiv.href =
> >> > > '/../employes/getInfosEmploye.action?matricule='
> >> > > + matricule;
> >> > >            infosDemandeurDiv.bind ();
> >> > >         }
> >> > >         dojo.event.topic.getTopic
> >> > > ("updateInfosDemandeurTopic").subscribe(null,
> >> > > "updateInfosDemandeur");
> >> > >     </script>
> >> > > </head>
> >> > >
> >> > > ... and an extract of the form section ...
> >> > >
> >> > >     <s:form action="submitCreerDemandeAbsence">
> >> > >         <s:textfield     name="demandeAbsence.matriculeDemandeur"
> >> > >                         label="Matricule"
> >> > >                         onchange="
> >> > > dojo.event.topic.publish('updateInfosDemandeurTopic',
> >> > > this.value);" />
> >> > >         <s:div id="infosDemandeur" theme="ajax"
> loadingText="Loading
> >> > > ..."></s:div>
> >> > >         <s:submit type="button" theme="ajax" />
> >> > >     </s:form>
> >> > >
> >> > > Thanks in advance
> >> > >
> >> > > Olivier
> >> > >
> >> >
> >> >
> >> >
> >> > --
> >> > "Hey you! Would you help me to carry the stone?" Pink Floyd
> >> >
> >>
> >
> >
> >
> > --
> > "Hey you! Would you help me to carry the stone?" Pink Floyd
> >
>
>
> ---------------------------------------------------------------------
> 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: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Martin Gainty <mg...@hotmail.com>.
is there a way to make sure all of these parameters as well as the step by 
step instructions are placed in the docs
Thanks!

Martin--
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: "Musachy Barroso" <mu...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Thursday, April 26, 2007 12:05 PM
Subject: Re: How to fill a div from an Ajax call when a onchange event is 
fired ?


> yes, all the values will be sent, but there is a "formFilter" attribute
> where you can specify a function that will be called for each element, and
> you just need to return true, for the ones that you want to be submitted.
> The function has one parameter, which will be the element.
>
> musachy
>
> On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
>>
>> Thanks a lot, I can call my action now.
>>
>> One more question ...
>> When I set the formId attribute for the div, does it mean that all values
>> in
>> the form will be sent to my action ?
>> If it is the case, is there a way to send only the value of my textfield 
>> ?
>>
>> Olivier
>>
>> 2007/4/26, Musachy Barroso <mu...@gmail.com>:
>> >
>> > I think it will be easier (and work) like this:
>> >
>> > 1. set href in your div, pointing to your action
>> > 2. set formId in your div pointing to the form that has the text field
>> > 3. add listenTopic to your div
>> > 4. publish the topic of 3. when the user types in the textbox
>> >
>> > musachy
>> >
>> > On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
>> > >
>> > > Hi,
>> > >
>> > > I used to use Struts 1.x and I just begin to use Struts 2.x
>> > > I am very interested with the Ajax feature, but I can't make it work
>> ...
>> > >
>> > > What I need to do looks very classical to me :
>> > > - The user types an employee code in a text box
>> > > - When the onchange event is fired, I call a Struts action with Ajax
>> > > - This action retrieves the firstname and the name of the employee. I
>> > want
>> > > these informations to be displayed into a div.
>> > >
>> > > I found a similar example in the Struts documentation (bottom of this
>> > page
>> > > :
>> > > http://struts.apache.org/2.0.6/docs/ajax-div-template.html ), but I
>> > can't
>> > > make it work ...
>> > >
>> > > When the onchange event is fired, I have the following Javascript
>> error
>> > :
>> > >
>> > > FATAL exception raised: TypeError: infosDemandeurDiv has no 
>> > > properties
>> > >
>> > > Could someone tell me what I did wrong, or if there is an easier
>> method
>> > to
>> > > do what I want ?
>> > >
>> > > Here is the head section of my jsp :
>> > >
>> > > <head>
>> > >     <title>Demande d'absence</title>
>> > >     <s:head theme="ajax" debug="true" />
>> > >     <script type="text/javascript">
>> > >         function updateInfosDemandeur(matricule) {
>> > >            var infosDemandeurDiv = window['infosDemandeur'];
>> > >            infosDemandeurDiv.href =
>> > > '/../employes/getInfosEmploye.action?matricule='
>> > > + matricule;
>> > >            infosDemandeurDiv.bind ();
>> > >         }
>> > >         dojo.event.topic.getTopic
>> > > ("updateInfosDemandeurTopic").subscribe(null,
>> > > "updateInfosDemandeur");
>> > >     </script>
>> > > </head>
>> > >
>> > > ... and an extract of the form section ...
>> > >
>> > >     <s:form action="submitCreerDemandeAbsence">
>> > >         <s:textfield     name="demandeAbsence.matriculeDemandeur"
>> > >                         label="Matricule"
>> > >                         onchange="
>> > > dojo.event.topic.publish('updateInfosDemandeurTopic',
>> > > this.value);" />
>> > >         <s:div id="infosDemandeur" theme="ajax" loadingText="Loading
>> > > ..."></s:div>
>> > >         <s:submit type="button" theme="ajax" />
>> > >     </s:form>
>> > >
>> > > Thanks in advance
>> > >
>> > > Olivier
>> > >
>> >
>> >
>> >
>> > --
>> > "Hey you! Would you help me to carry the stone?" Pink Floyd
>> >
>>
>
>
>
> -- 
> "Hey you! Would you help me to carry the stone?" Pink Floyd
> 


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


Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Musachy Barroso <mu...@gmail.com>.
yes, all the values will be sent, but there is a "formFilter" attribute
where you can specify a function that will be called for each element, and
you just need to return true, for the ones that you want to be submitted.
The function has one parameter, which will be the element.

musachy

On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
>
> Thanks a lot, I can call my action now.
>
> One more question ...
> When I set the formId attribute for the div, does it mean that all values
> in
> the form will be sent to my action ?
> If it is the case, is there a way to send only the value of my textfield ?
>
> Olivier
>
> 2007/4/26, Musachy Barroso <mu...@gmail.com>:
> >
> > I think it will be easier (and work) like this:
> >
> > 1. set href in your div, pointing to your action
> > 2. set formId in your div pointing to the form that has the text field
> > 3. add listenTopic to your div
> > 4. publish the topic of 3. when the user types in the textbox
> >
> > musachy
> >
> > On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > I used to use Struts 1.x and I just begin to use Struts 2.x
> > > I am very interested with the Ajax feature, but I can't make it work
> ...
> > >
> > > What I need to do looks very classical to me :
> > > - The user types an employee code in a text box
> > > - When the onchange event is fired, I call a Struts action with Ajax
> > > - This action retrieves the firstname and the name of the employee. I
> > want
> > > these informations to be displayed into a div.
> > >
> > > I found a similar example in the Struts documentation (bottom of this
> > page
> > > :
> > > http://struts.apache.org/2.0.6/docs/ajax-div-template.html ), but I
> > can't
> > > make it work ...
> > >
> > > When the onchange event is fired, I have the following Javascript
> error
> > :
> > >
> > > FATAL exception raised: TypeError: infosDemandeurDiv has no properties
> > >
> > > Could someone tell me what I did wrong, or if there is an easier
> method
> > to
> > > do what I want ?
> > >
> > > Here is the head section of my jsp :
> > >
> > > <head>
> > >     <title>Demande d'absence</title>
> > >     <s:head theme="ajax" debug="true" />
> > >     <script type="text/javascript">
> > >         function updateInfosDemandeur(matricule) {
> > >            var infosDemandeurDiv = window['infosDemandeur'];
> > >            infosDemandeurDiv.href =
> > > '/../employes/getInfosEmploye.action?matricule='
> > > + matricule;
> > >            infosDemandeurDiv.bind ();
> > >         }
> > >         dojo.event.topic.getTopic
> > > ("updateInfosDemandeurTopic").subscribe(null,
> > > "updateInfosDemandeur");
> > >     </script>
> > > </head>
> > >
> > > ... and an extract of the form section ...
> > >
> > >     <s:form action="submitCreerDemandeAbsence">
> > >         <s:textfield     name="demandeAbsence.matriculeDemandeur"
> > >                         label="Matricule"
> > >                         onchange="
> > > dojo.event.topic.publish('updateInfosDemandeurTopic',
> > > this.value);" />
> > >         <s:div id="infosDemandeur" theme="ajax" loadingText="Loading
> > > ..."></s:div>
> > >         <s:submit type="button" theme="ajax" />
> > >     </s:form>
> > >
> > > Thanks in advance
> > >
> > > Olivier
> > >
> >
> >
> >
> > --
> > "Hey you! Would you help me to carry the stone?" Pink Floyd
> >
>



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

Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Olivier THIERRY <ol...@gmail.com>.
Thanks a lot, I can call my action now.

One more question ...
When I set the formId attribute for the div, does it mean that all values in
the form will be sent to my action ?
If it is the case, is there a way to send only the value of my textfield ?

Olivier

2007/4/26, Musachy Barroso <mu...@gmail.com>:
>
> I think it will be easier (and work) like this:
>
> 1. set href in your div, pointing to your action
> 2. set formId in your div pointing to the form that has the text field
> 3. add listenTopic to your div
> 4. publish the topic of 3. when the user types in the textbox
>
> musachy
>
> On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
> >
> > Hi,
> >
> > I used to use Struts 1.x and I just begin to use Struts 2.x
> > I am very interested with the Ajax feature, but I can't make it work ...
> >
> > What I need to do looks very classical to me :
> > - The user types an employee code in a text box
> > - When the onchange event is fired, I call a Struts action with Ajax
> > - This action retrieves the firstname and the name of the employee. I
> want
> > these informations to be displayed into a div.
> >
> > I found a similar example in the Struts documentation (bottom of this
> page
> > :
> > http://struts.apache.org/2.0.6/docs/ajax-div-template.html ), but I
> can't
> > make it work ...
> >
> > When the onchange event is fired, I have the following Javascript error
> :
> >
> > FATAL exception raised: TypeError: infosDemandeurDiv has no properties
> >
> > Could someone tell me what I did wrong, or if there is an easier method
> to
> > do what I want ?
> >
> > Here is the head section of my jsp :
> >
> > <head>
> >     <title>Demande d'absence</title>
> >     <s:head theme="ajax" debug="true" />
> >     <script type="text/javascript">
> >         function updateInfosDemandeur(matricule) {
> >            var infosDemandeurDiv = window['infosDemandeur'];
> >            infosDemandeurDiv.href =
> > '/../employes/getInfosEmploye.action?matricule='
> > + matricule;
> >            infosDemandeurDiv.bind ();
> >         }
> >         dojo.event.topic.getTopic
> > ("updateInfosDemandeurTopic").subscribe(null,
> > "updateInfosDemandeur");
> >     </script>
> > </head>
> >
> > ... and an extract of the form section ...
> >
> >     <s:form action="submitCreerDemandeAbsence">
> >         <s:textfield     name="demandeAbsence.matriculeDemandeur"
> >                         label="Matricule"
> >                         onchange="
> > dojo.event.topic.publish('updateInfosDemandeurTopic',
> > this.value);" />
> >         <s:div id="infosDemandeur" theme="ajax" loadingText="Loading
> > ..."></s:div>
> >         <s:submit type="button" theme="ajax" />
> >     </s:form>
> >
> > Thanks in advance
> >
> > Olivier
> >
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>

Re: How to fill a div from an Ajax call when a onchange event is fired ?

Posted by Musachy Barroso <mu...@gmail.com>.
I think it will be easier (and work) like this:

1. set href in your div, pointing to your action
2. set formId in your div pointing to the form that has the text field
3. add listenTopic to your div
4. publish the topic of 3. when the user types in the textbox

musachy

On 4/26/07, Olivier THIERRY <ol...@gmail.com> wrote:
>
> Hi,
>
> I used to use Struts 1.x and I just begin to use Struts 2.x
> I am very interested with the Ajax feature, but I can't make it work ...
>
> What I need to do looks very classical to me :
> - The user types an employee code in a text box
> - When the onchange event is fired, I call a Struts action with Ajax
> - This action retrieves the firstname and the name of the employee. I want
> these informations to be displayed into a div.
>
> I found a similar example in the Struts documentation (bottom of this page
> :
> http://struts.apache.org/2.0.6/docs/ajax-div-template.html ), but I can't
> make it work ...
>
> When the onchange event is fired, I have the following Javascript error :
>
> FATAL exception raised: TypeError: infosDemandeurDiv has no properties
>
> Could someone tell me what I did wrong, or if there is an easier method to
> do what I want ?
>
> Here is the head section of my jsp :
>
> <head>
>     <title>Demande d'absence</title>
>     <s:head theme="ajax" debug="true" />
>     <script type="text/javascript">
>         function updateInfosDemandeur(matricule) {
>            var infosDemandeurDiv = window['infosDemandeur'];
>            infosDemandeurDiv.href =
> '/../employes/getInfosEmploye.action?matricule='
> + matricule;
>            infosDemandeurDiv.bind ();
>         }
>         dojo.event.topic.getTopic
> ("updateInfosDemandeurTopic").subscribe(null,
> "updateInfosDemandeur");
>     </script>
> </head>
>
> ... and an extract of the form section ...
>
>     <s:form action="submitCreerDemandeAbsence">
>         <s:textfield     name="demandeAbsence.matriculeDemandeur"
>                         label="Matricule"
>                         onchange="
> dojo.event.topic.publish('updateInfosDemandeurTopic',
> this.value);" />
>         <s:div id="infosDemandeur" theme="ajax" loadingText="Loading
> ..."></s:div>
>         <s:submit type="button" theme="ajax" />
>     </s:form>
>
> Thanks in advance
>
> Olivier
>



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