You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Griffith, Michael *" <Mi...@fda.hhs.gov> on 2008/01/31 23:16:44 UTC

Help with (1...N) Editing using Ajax?

Hello all, 

 

I am trying to understand how to present an interface where I allow a
user to edit a master/detail relationship using an Ajax technique. I am
quite new to Struts2, so please forgive the dalliance. 

 

I have a form that presents the user the ability to edit the master of
the master/detail, and below the form a list of each of the child
records.  Each child record presents an Ajax enabled link to trigger a
method on the struts action, where I pick out the child record from the
list and put it in the session...

 

The link looks like this:

 

            <s:iterator id="guide" value="guides">

                        <s:url id="editGuide" action="getGuide"
namespace="/datacall" > 

                                    <s:param name="gid"
value="#guide.id" /> 

                        </s:url> 

                        <s:a theme="ajax" href="%{editGuide}"
notifyTopics="updateResult"><s:property
value="#guide.shortDescription"/></s:a> <br/>

            </s:iterator>

 

The method is triggered in the action, and I set the child into my
request session... 

request.getSession().setAttribute("guide", g);

 

And I have a form that I'm trying to bind to the object in the session.
The form is actually hidden in a div/panel I'm using the YUI to present
the form to the user after the round trip to the server.  The form isn't
bound to the correct variable, because its set via a user interaction
after the entire page is presented to the user.

The form looks like this:

 

<s:form theme="ajax" action="updateGuide" method="post">

            <s:hidden name="#session['guide'].id" />

            <s:textfield key="guide.shortDescription"
name="#session['guide'].shortDescription" />

            <s:textarea key="guide.instructions"
name="#session['guide'].instructions" cols="25" rows="8"/>

</s:form>

 

In Struts 1 I would have gotten a terrible error saying that the bean
wasn't found. Now the error fails silently. How can I make the form
somehow bind to the object in the session after the user clicks the
link? 

 

Any help would be much appreciated.

 

MG

 


RE: Help with (1...N) Editing using Ajax?

Posted by "Griffith, Michael *" <Mi...@fda.hhs.gov>.
Laurie, 

Thanks for your reply. You have nailed the problem!

It seems like the 2nd solution is the more elegant one. Are there any
reference implementations or examples you could point me to that might
show me how to populate the form using JSON data?

MG

-----Original Message-----
From: news [mailto:news@ger.gmane.org] On Behalf Of Laurie Harper
Sent: Friday, February 01, 2008 10:45 AM
To: user@struts.apache.org
Subject: Re: Help with (1...N) Editing using Ajax?

The problem is that you're rendering the form before you've stored 
anything under #session['guide']. I assume when you say you want to 
'bind the form to the object' your Ajax request places in the session, 
you mean you want to populate the form fields with data from that
object?

That can't work automagically, since the form is just part of the page 
in the browser and  has no knowledge of what might be happening to the 
session over on the server.

There are a couple of approaches you can consider to get this working:

1) instead of rendering the form as part of the initial page load, 
render it as the result of the Ajax request that loads the data. On the 
client-side, take that response and render it directly.

2) return the data itself as the result of the Ajax request (in XML or 
JSON format probably). On the client-side, take that response and use it

to populate the form you already have.

The key is that the form will not get populated with data just because 
you made data available after the fact. You either must render the form 
after the data is available, or perform additional processing to 'push' 
the data into the form.

L.

Griffith, Michael * wrote:
> In fact, looking at the page source, it appears the expression is
never
> cooked...
> 
> Here's the input from the rendered page:
> <input type="text" name="#session['guide'].shortDescription"
> value="#session['guide'].shortDescription"
> id="updateGuide_#session_'guide'__shortDescription"/>
> 
> -----Original Message-----
> From: Musachy Barroso [mailto:musachy@gmail.com] 
> Sent: Thursday, January 31, 2008 4:25 PM
> To: Struts Users Mailing List
> Subject: Re: Help with (1...N) Editing using Ajax?
> 
> so #session['guide'] is not returning anything?
> 
> musachy
> 
> On Jan 31, 2008 5:16 PM, Griffith, Michael *
> <Mi...@fda.hhs.gov> wrote:
>> Hello all,
>>
>>
>>
>> I am trying to understand how to present an interface where I allow a
>> user to edit a master/detail relationship using an Ajax technique. I
> am
>> quite new to Struts2, so please forgive the dalliance.
>>
>>
>>
>> I have a form that presents the user the ability to edit the master
of
>> the master/detail, and below the form a list of each of the child
>> records.  Each child record presents an Ajax enabled link to trigger
a
>> method on the struts action, where I pick out the child record from
> the
>> list and put it in the session...
>>
>>
>>
>> The link looks like this:
>>
>>
>>
>>             <s:iterator id="guide" value="guides">
>>
>>                         <s:url id="editGuide" action="getGuide"
>> namespace="/datacall" >
>>
>>                                     <s:param name="gid"
>> value="#guide.id" />
>>
>>                         </s:url>
>>
>>                         <s:a theme="ajax" href="%{editGuide}"
>> notifyTopics="updateResult"><s:property
>> value="#guide.shortDescription"/></s:a> <br/>
>>
>>             </s:iterator>
>>
>>
>>
>> The method is triggered in the action, and I set the child into my
>> request session...
>>
>> request.getSession().setAttribute("guide", g);
>>
>>
>>
>> And I have a form that I'm trying to bind to the object in the
> session.
>> The form is actually hidden in a div/panel I'm using the YUI to
> present
>> the form to the user after the round trip to the server.  The form
> isn't
>> bound to the correct variable, because its set via a user interaction
>> after the entire page is presented to the user.
>>
>> The form looks like this:
>>
>>
>>
>> <s:form theme="ajax" action="updateGuide" method="post">
>>
>>             <s:hidden name="#session['guide'].id" />
>>
>>             <s:textfield key="guide.shortDescription"
>> name="#session['guide'].shortDescription" />
>>
>>             <s:textarea key="guide.instructions"
>> name="#session['guide'].instructions" cols="25" rows="8"/>
>>
>> </s:form>
>>
>>
>>
>> In Struts 1 I would have gotten a terrible error saying that the bean
>> wasn't found. Now the error fails silently. How can I make the form
>> somehow bind to the object in the session after the user clicks the
>> link?
>>
>>
>>
>> Any help would be much appreciated.
>>
>>
>>
>> MG
>>
>>
>>
>>
> 
> 
> 


---------------------------------------------------------------------
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: Help with (1...N) Editing using Ajax?

Posted by Laurie Harper <la...@holoweb.net>.
The problem is that you're rendering the form before you've stored 
anything under #session['guide']. I assume when you say you want to 
'bind the form to the object' your Ajax request places in the session, 
you mean you want to populate the form fields with data from that object?

That can't work automagically, since the form is just part of the page 
in the browser and  has no knowledge of what might be happening to the 
session over on the server.

There are a couple of approaches you can consider to get this working:

1) instead of rendering the form as part of the initial page load, 
render it as the result of the Ajax request that loads the data. On the 
client-side, take that response and render it directly.

2) return the data itself as the result of the Ajax request (in XML or 
JSON format probably). On the client-side, take that response and use it 
to populate the form you already have.

The key is that the form will not get populated with data just because 
you made data available after the fact. You either must render the form 
after the data is available, or perform additional processing to 'push' 
the data into the form.

L.

Griffith, Michael * wrote:
> In fact, looking at the page source, it appears the expression is never
> cooked...
> 
> Here's the input from the rendered page:
> <input type="text" name="#session['guide'].shortDescription"
> value="#session['guide'].shortDescription"
> id="updateGuide_#session_'guide'__shortDescription"/>
> 
> -----Original Message-----
> From: Musachy Barroso [mailto:musachy@gmail.com] 
> Sent: Thursday, January 31, 2008 4:25 PM
> To: Struts Users Mailing List
> Subject: Re: Help with (1...N) Editing using Ajax?
> 
> so #session['guide'] is not returning anything?
> 
> musachy
> 
> On Jan 31, 2008 5:16 PM, Griffith, Michael *
> <Mi...@fda.hhs.gov> wrote:
>> Hello all,
>>
>>
>>
>> I am trying to understand how to present an interface where I allow a
>> user to edit a master/detail relationship using an Ajax technique. I
> am
>> quite new to Struts2, so please forgive the dalliance.
>>
>>
>>
>> I have a form that presents the user the ability to edit the master of
>> the master/detail, and below the form a list of each of the child
>> records.  Each child record presents an Ajax enabled link to trigger a
>> method on the struts action, where I pick out the child record from
> the
>> list and put it in the session...
>>
>>
>>
>> The link looks like this:
>>
>>
>>
>>             <s:iterator id="guide" value="guides">
>>
>>                         <s:url id="editGuide" action="getGuide"
>> namespace="/datacall" >
>>
>>                                     <s:param name="gid"
>> value="#guide.id" />
>>
>>                         </s:url>
>>
>>                         <s:a theme="ajax" href="%{editGuide}"
>> notifyTopics="updateResult"><s:property
>> value="#guide.shortDescription"/></s:a> <br/>
>>
>>             </s:iterator>
>>
>>
>>
>> The method is triggered in the action, and I set the child into my
>> request session...
>>
>> request.getSession().setAttribute("guide", g);
>>
>>
>>
>> And I have a form that I'm trying to bind to the object in the
> session.
>> The form is actually hidden in a div/panel I'm using the YUI to
> present
>> the form to the user after the round trip to the server.  The form
> isn't
>> bound to the correct variable, because its set via a user interaction
>> after the entire page is presented to the user.
>>
>> The form looks like this:
>>
>>
>>
>> <s:form theme="ajax" action="updateGuide" method="post">
>>
>>             <s:hidden name="#session['guide'].id" />
>>
>>             <s:textfield key="guide.shortDescription"
>> name="#session['guide'].shortDescription" />
>>
>>             <s:textarea key="guide.instructions"
>> name="#session['guide'].instructions" cols="25" rows="8"/>
>>
>> </s:form>
>>
>>
>>
>> In Struts 1 I would have gotten a terrible error saying that the bean
>> wasn't found. Now the error fails silently. How can I make the form
>> somehow bind to the object in the session after the user clicks the
>> link?
>>
>>
>>
>> Any help would be much appreciated.
>>
>>
>>
>> MG
>>
>>
>>
>>
> 
> 
> 


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


RE: Help with (1...N) Editing using Ajax?

Posted by "Griffith, Michael *" <Mi...@fda.hhs.gov>.
Nope, nothing. 

If I bind my form to #guide.<property> I find the first or last item in
the Collection that belongs to the parent when the list was iterated
over.

Maybe there is a better way to specify how to bind the property to the
struts control? Maybe something like: 
<s:hidden name="#guide[idx].id" />  

But how would I specify the item index in the collection?
Cheers!
MG

-----Original Message-----
From: Musachy Barroso [mailto:musachy@gmail.com] 
Sent: Thursday, January 31, 2008 4:25 PM
To: Struts Users Mailing List
Subject: Re: Help with (1...N) Editing using Ajax?

so #session['guide'] is not returning anything?

musachy

On Jan 31, 2008 5:16 PM, Griffith, Michael *
<Mi...@fda.hhs.gov> wrote:
> Hello all,
>
>
>
> I am trying to understand how to present an interface where I allow a
> user to edit a master/detail relationship using an Ajax technique. I
am
> quite new to Struts2, so please forgive the dalliance.
>
>
>
> I have a form that presents the user the ability to edit the master of
> the master/detail, and below the form a list of each of the child
> records.  Each child record presents an Ajax enabled link to trigger a
> method on the struts action, where I pick out the child record from
the
> list and put it in the session...
>
>
>
> The link looks like this:
>
>
>
>             <s:iterator id="guide" value="guides">
>
>                         <s:url id="editGuide" action="getGuide"
> namespace="/datacall" >
>
>                                     <s:param name="gid"
> value="#guide.id" />
>
>                         </s:url>
>
>                         <s:a theme="ajax" href="%{editGuide}"
> notifyTopics="updateResult"><s:property
> value="#guide.shortDescription"/></s:a> <br/>
>
>             </s:iterator>
>
>
>
> The method is triggered in the action, and I set the child into my
> request session...
>
> request.getSession().setAttribute("guide", g);
>
>
>
> And I have a form that I'm trying to bind to the object in the
session.
> The form is actually hidden in a div/panel I'm using the YUI to
present
> the form to the user after the round trip to the server.  The form
isn't
> bound to the correct variable, because its set via a user interaction
> after the entire page is presented to the user.
>
> The form looks like this:
>
>
>
> <s:form theme="ajax" action="updateGuide" method="post">
>
>             <s:hidden name="#session['guide'].id" />
>
>             <s:textfield key="guide.shortDescription"
> name="#session['guide'].shortDescription" />
>
>             <s:textarea key="guide.instructions"
> name="#session['guide'].instructions" cols="25" rows="8"/>
>
> </s:form>
>
>
>
> In Struts 1 I would have gotten a terrible error saying that the bean
> wasn't found. Now the error fails silently. How can I make the form
> somehow bind to the object in the session after the user clicks the
> link?
>
>
>
> Any help would be much appreciated.
>
>
>
> MG
>
>
>
>



-- 
"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




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


RE: Help with (1...N) Editing using Ajax?

Posted by "Griffith, Michael *" <Mi...@fda.hhs.gov>.
In fact, looking at the page source, it appears the expression is never
cooked...

Here's the input from the rendered page:
<input type="text" name="#session['guide'].shortDescription"
value="#session['guide'].shortDescription"
id="updateGuide_#session_'guide'__shortDescription"/>

-----Original Message-----
From: Musachy Barroso [mailto:musachy@gmail.com] 
Sent: Thursday, January 31, 2008 4:25 PM
To: Struts Users Mailing List
Subject: Re: Help with (1...N) Editing using Ajax?

so #session['guide'] is not returning anything?

musachy

On Jan 31, 2008 5:16 PM, Griffith, Michael *
<Mi...@fda.hhs.gov> wrote:
> Hello all,
>
>
>
> I am trying to understand how to present an interface where I allow a
> user to edit a master/detail relationship using an Ajax technique. I
am
> quite new to Struts2, so please forgive the dalliance.
>
>
>
> I have a form that presents the user the ability to edit the master of
> the master/detail, and below the form a list of each of the child
> records.  Each child record presents an Ajax enabled link to trigger a
> method on the struts action, where I pick out the child record from
the
> list and put it in the session...
>
>
>
> The link looks like this:
>
>
>
>             <s:iterator id="guide" value="guides">
>
>                         <s:url id="editGuide" action="getGuide"
> namespace="/datacall" >
>
>                                     <s:param name="gid"
> value="#guide.id" />
>
>                         </s:url>
>
>                         <s:a theme="ajax" href="%{editGuide}"
> notifyTopics="updateResult"><s:property
> value="#guide.shortDescription"/></s:a> <br/>
>
>             </s:iterator>
>
>
>
> The method is triggered in the action, and I set the child into my
> request session...
>
> request.getSession().setAttribute("guide", g);
>
>
>
> And I have a form that I'm trying to bind to the object in the
session.
> The form is actually hidden in a div/panel I'm using the YUI to
present
> the form to the user after the round trip to the server.  The form
isn't
> bound to the correct variable, because its set via a user interaction
> after the entire page is presented to the user.
>
> The form looks like this:
>
>
>
> <s:form theme="ajax" action="updateGuide" method="post">
>
>             <s:hidden name="#session['guide'].id" />
>
>             <s:textfield key="guide.shortDescription"
> name="#session['guide'].shortDescription" />
>
>             <s:textarea key="guide.instructions"
> name="#session['guide'].instructions" cols="25" rows="8"/>
>
> </s:form>
>
>
>
> In Struts 1 I would have gotten a terrible error saying that the bean
> wasn't found. Now the error fails silently. How can I make the form
> somehow bind to the object in the session after the user clicks the
> link?
>
>
>
> Any help would be much appreciated.
>
>
>
> MG
>
>
>
>



-- 
"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




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


Re: Help with (1...N) Editing using Ajax?

Posted by Musachy Barroso <mu...@gmail.com>.
so #session['guide'] is not returning anything?

musachy

On Jan 31, 2008 5:16 PM, Griffith, Michael *
<Mi...@fda.hhs.gov> wrote:
> Hello all,
>
>
>
> I am trying to understand how to present an interface where I allow a
> user to edit a master/detail relationship using an Ajax technique. I am
> quite new to Struts2, so please forgive the dalliance.
>
>
>
> I have a form that presents the user the ability to edit the master of
> the master/detail, and below the form a list of each of the child
> records.  Each child record presents an Ajax enabled link to trigger a
> method on the struts action, where I pick out the child record from the
> list and put it in the session...
>
>
>
> The link looks like this:
>
>
>
>             <s:iterator id="guide" value="guides">
>
>                         <s:url id="editGuide" action="getGuide"
> namespace="/datacall" >
>
>                                     <s:param name="gid"
> value="#guide.id" />
>
>                         </s:url>
>
>                         <s:a theme="ajax" href="%{editGuide}"
> notifyTopics="updateResult"><s:property
> value="#guide.shortDescription"/></s:a> <br/>
>
>             </s:iterator>
>
>
>
> The method is triggered in the action, and I set the child into my
> request session...
>
> request.getSession().setAttribute("guide", g);
>
>
>
> And I have a form that I'm trying to bind to the object in the session.
> The form is actually hidden in a div/panel I'm using the YUI to present
> the form to the user after the round trip to the server.  The form isn't
> bound to the correct variable, because its set via a user interaction
> after the entire page is presented to the user.
>
> The form looks like this:
>
>
>
> <s:form theme="ajax" action="updateGuide" method="post">
>
>             <s:hidden name="#session['guide'].id" />
>
>             <s:textfield key="guide.shortDescription"
> name="#session['guide'].shortDescription" />
>
>             <s:textarea key="guide.instructions"
> name="#session['guide'].instructions" cols="25" rows="8"/>
>
> </s:form>
>
>
>
> In Struts 1 I would have gotten a terrible error saying that the bean
> wasn't found. Now the error fails silently. How can I make the form
> somehow bind to the object in the session after the user clicks the
> link?
>
>
>
> Any help would be much appreciated.
>
>
>
> MG
>
>
>
>



-- 
"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