Hi Dan.

Ok.  After rereading your post a few (like four or five) times, and reading 
John's response and your response to him, I _think_ that this is the crux of 
your problem:

>That's the heart of the matter. Using two different ActionBeans within the
>same page, one of which manipulates fields bound in the other.

and furthermore 

>> I am starting
>> to wonder if I'm just going about it the wrong way entirely due to a
>> misunderstanding of one of the concepts in use...

:)  Or at least, I think that you think that you have a problem because of a 
misunderstanding which means that you're thinking about it in the wrong way. 
 On the bright side, if I'm right, then you have a really easy solution.

The big thing is, I don't think that you should think of having ActionBeans 
actually interacting with one another in this case.  Rather, you should 
think of an ActionBean (or two ActionBeans) creating an HTML Form, then that 
Form being manipulated in the browser in various ways (user input, AJAX 
calls, JavaScript, etc.), and finally the Form being submitted back to a 
single ActionBean.  While the Form is in the browser, there isn't any 
ActionBean to be interacted with.

So, to use your original example:

> <s:form actionBeanClass="some.RandomAction">
>
> Field: <s:text name="someField"/>
>
> Another Field: <s:text name="anotherField"/>
>
> Browsable Field:
>     <s:hidden name="selectedValue"/>
>     Current Value: ${actionBean.selectedValue}
>     Browse for New Value:
>     <jsp:include page="valueSelector.jsp"/>
>
> </s:form>
>
> And here's the "component" jsp (valueSelector.jsp):
>
> <s:useActionBean beanclass="some.BrowserAction"/>
>
> <div id="valueBrowser">
>
> <div id="valueBrowserValues">
> <ul>
> <c:forEach items="${actionBean.values}" var="value">
>    <li><a href="#" onclick="select('${value}'">${value}</a></li>
> </c:forEach>
> </li>
> </div>
>
> <a href="#" onclick="next()">Next</a>
>
> </div>


....and changing this line

>     Current Value: ${actionBean.selectedValue}

to

>     Current Value: <span id="selectedValueDisplay"> 
${actionBean.selectedValue} </span>

all that you need to do is have your select(value) JavaScript read like

function select(value) {
  document.forms[0].selectedValue.value = value;
  document.getElementById('selectedValueDisplay').innerHTML=value;
}

(...blah blah crappy JavaScript blah use Prototype or jQuery blah...)

So what happens now is the following:

1)  someRandomAction populates the Form, including putting the current value 
in the selectedValue form element.
2)  some.BrowserAction populates the display of the Browser component.
3)  RandomAction and BrowserAction are complete and don't exist anymore; all 
state is held in the Form.
4)  User clicks on one of the elements in the Browser component.
5)  The select() JS function is run, which updates the hidden 
'selectedValue' field in the Form, as well as the display span.
6)  The user submits the Form.
7)  The RandomAction.selectedValue property is populated from the (updated) 
hidden selectedValue field.
8)  RandomAction does whatever it's supposed to do with the new value.

Does that make sense?

Now, the one other piece in there is that if you really want to make the 
component and JSP reusable, then you may not always been changing a field 
called 'selectedValue'.  For that, you should just be able to pass in the 
name/ID of the field to the JSP fragment and BrowserAction.  I'd just put it 
in as a regular request Attribute:

>     <s:hidden name="variableObject.selectedValue"/>
>     Current Value: ${actionBean.variableObject.selectedValue}
>     Browse for New Value:
      <c:set var="browserObjectName" value="variableObject.selectedValue" 
scope="request"/>
>     <jsp:include page="valueSelector.jsp"/>

and


> <s:useActionBean beanclass="some.BrowserAction"/>
>
> <div id="valueBrowser">
>
> <div id="valueBrowserValues">
> <ul>
> <c:forEach items="${actionBean.values}" var="value">
>    <li><a href="#" onclick="select('${browserObjectName}', 
'${value}'">${value}</a></li>
> </c:forEach>
> </li>
> </div>
>
> <a href="#" onclick="next('${browserObjectName}')">Next</a>
>
> </div>

And then next() passes the browserObjectName to the BrowserActionForm in the 
AJAX request.  BrowserAction then calls 
getContext().getRequest().setAttribute("browserObjectName", 
getBrowserObjectName()) before rendering the page fragment, and finally 
select() uses the name passed in to know which form field and span to 
update.

Does that all make sense?  Does that help?  Or was I mistaken in what your 
actual problem was?

-allen






On Fri, Dec 18, 2009, 15:42, Dan Mace <[email protected]> wrote
>John,
>
>I typed all of that code in a GMail textbox, which doesn't make the best 
IDE
>in the world. :) It wasn't meant to be a working example.
>
>You?re saying these 2 lines need updated?
>>
>>
>>
>>     <s:hidden name="selectedValue"/>
>>     Current Value: ${actionBean.selectedValue}
>>
>>
>
>That's the heart of the matter. Using two different ActionBeans within the
>same page, one of which manipulates fields bound in the other. Here are 
some
>of of the old mailing list threads which gave me the inspiration for how to
>manage AJAX partial updates in Stripes in the first place. They all use 
some
>variation of this technique, the difference being none of them try to
>cross-bind from the fragment back to the containing page:
>
>"Help for truly reusable JSP tags in Stripes"
>http://old.nabble.com/Help-for-truly-reusable-JSP-tags-in-Stripes-ts2572096
1.html
>
>"Multiple Forms on one page"
>http://old.nabble.com/Multiple-forms-on-one-page-ts12840960.html#a12853522
>
>"Stripes tag library and AJAX"
>http://old.nabble.com/Stripes-tag-library-and-AJAX-ts6971477.html#a6971477
>
>There are several others which I don't see in my history at the moment.
>Mostly I searched for things like "fragment", "partial", "ajax", "reusable
>component", "useActionBean", "include", etc.
>
>On Fri, Dec 18, 2009 at 3:23 PM, Newman, John W 
<[email protected]
>> wrote:
>
>>  Could the missing ) be your problem
>>
>>
>>
>> <a href="#" onclick="select('${value}'">${value}</a>
>>
>>
>>
>> Also I?d recommend using href=?? onclick=?whatever(); return false;? .. I
>> can?t recall the reasons but we did switch from # to that.
>>
>>
>>
>> Other than that, I guess it?s Friday, but I?m having a hard time
>> understanding your problem.
>>
>>
>>
>> ?a requirement for my components to feed data back to the page which is
>> using them?
>>
>>
>>
>> You?re saying these 2 lines need updated?
>>
>>
>>
>>     <s:hidden name="selectedValue"/>
>>     Current Value: ${actionBean.selectedValue}
>>
>>
>>
>>
>>
>> function update()  {
>>
>>   new Ajax.Updater(?updateContainer?, <url>, <params w/ _eventName>);
>>
>> }
>>
>>
>>
>> <div id=?updateContainer?>
>>
>>      <jsp:include ?those2Lines.jsp?>
>>
>> </div>
>>
>>
>>
>> those2Lines.jsp:
>>
>>
>>
>> <stripes:form partial=true beanclass=${actionBean.currentBeanClass}>
>>
>>        <s:hidden name="selectedValue"/>
>>     Current Value: ${actionBean.selectedValue}
>>
>> </stripes:form>
>>
>>
>>
>> Again, I don?t fully grasp what you?re asking, so that may be nothing new
>> to you.
>>
>>
>>
>> *From:* Dan Mace [mailto:[email protected]]
>> *Sent:* Friday, December 18, 2009 2:55 PM
>> *To:* Stripes Mailing List
>> *Subject:* [Stripes-users] Reusable AJAX components using JSP fragments
>> and partial Stripes forms
>>
>>
>>
>> I've been reading through the mailing list archives and have done a ton 
of
>> experimentation, but still can't quite wrap my mind around the solution 
to
>> this. Here is a use case. I don't have any code here in front of me to
>> paste, so I'll do my best to describe it in prose. If I don't do a good
>> enough job, I'll see if I can dig up some example code when I get home
>> tonight...
>>
>> Scenario: Many forms within the application allow the user to select a
>> certain value from a pop-up hierarchical browser component, which, when
>> selected, needs to eventually get bound back into a property of the
>> ActionBean. The "partial" form gets data from a different ActionBean than
>> the thing which includes it. Here's the general setup for a simple form
>> which includes this component via a <jsp:include>. For the sake of
>> simplicity, I'm omitting tons of stuff like wrapping the component in a
>> popup, demonstrating the functionality of the hierarchy browser, etc:
>>
>> <s:form actionBeanClass="some.RandomAction">
>>
>> Field: <s:text name="someField"/>
>>
>> Another Field: <s:text name="anotherField"/>
>>
>> Browsable Field:
>>     <s:hidden name="selectedValue"/>
>>     Current Value: ${actionBean.selectedValue}
>>     Browse for New Value:
>>     <jsp:include page="valueSelector.jsp"/>
>>
>> </s:form>
>>
>> And here's the "component" jsp (valueSelector.jsp):
>>
>> <s:useActionBean beanclass="some.BrowserAction"/>
>>
>> <div id="valueBrowser">
>>
>> <div id="valueBrowserValues">
>> <ul>
>> <c:forEach items="${actionBean.values}" var="value">
>>    <li><a href="#" onclick="select('${value}'">${value}</a></li>
>> </c:forEach>
>> </li>
>> </div>
>>
>> <a href="#" onclick="next()">Next</a>
>>
>> </div>
>>
>> So, I hope I have demonstrated the basic ideas I'm interested with this:
>>
>> 1. When the initial page renders for RandomAction,
>>
>>   a. The "selectedValue" property is displayed, and bound via the
>> "selectedValue" hidden field.
>>
>>   b. The browser component is rendered, and gets its initial state from 
the
>> "values" property of a DIFFERENT ActionBean, "BrowserAction".
>>
>> 2. After initial page render,
>>
>>   a. The user clicks the "Next" link in the browser, which makes an AJAX
>> call to BrowserAction's "next" event, which fills the "values" property 
with
>> the next list of items, and replaces the contents of "valueBrowserValues"
>> with a freshly rendered view of "valueSelector.jsp" (the JS for this is 
not
>> displayed in the example). This works perfectly well.
>>
>>   b. The user clicks on a value, which fires the "select" JavaScript
>> function, which somehow needs to make its way back to the "selectedValue"
>> hidden field (and preferably to update the current display value, if it 
were
>> to be wrapped in a span or something. This is where my problems lie.
>>
>> I have no idea how to accomplish this without coupling the component to 
the
>> invoking page so that the "select" function can act upon its container's
>> elements.
>>
>> Another thought I had was to make the "component" encapsulate the actual
>> selected value control as well, so that the partial now looks like this:
>>
>> <s:useActionBean beanclass="some.BrowserAction"/>
>>
>> <div id="valueBrowser">
>>
>> <s:hidden name="selectedValue"/>
>>
>> <div id="valueBrowserValues">
>> <ul>
>> <c:forEach items="${actionBean.values}" var="value">
>>    <li><a href="#" onclick="select('${value}'">${value}</a></li>
>> </c:forEach>
>> </li>
>> </div>
>>
>> <a href="#" onclick="next()">Next</a>
>>
>> </div>
>>
>> In this case, the select() function would update the hidden field it
>> "knows" about... however, selectedValue needs to be bound to the 
CONTAINING
>> ActionBean, not the component's ActionBean.
>>
>> Is this making any sense? AJAX partials with Stripes have been working
>> great for me up until this point where it became a requirement for my
>> components to feed data back to the page which is using them. I am 
starting
>> to wonder if I'm just going about it the wrong way entirely due to a
>> misunderstanding of one of the concepts in use...
>>
>>
>>
>> 
----------------------------------------------------------------------------
--
>> This SF.Net email is sponsored by the Verizon Developer Community
>> Take advantage of Verizon's best-in-class app development support
>> A streamlined, 14 day to market process makes app distribution fast and
>> easy
>> Join now and get one step closer to millions of Verizon customers
>> http://p.sf.net/sfu/verizon-dev2dev
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>>
>


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to