Hi All,
I've made some test and seems to work fine:
I post the example for the List Archive.
This is basically a 2 component interaction:
*Main.wo*: the page that is showed
*TestList.wo*: a subcomponet called in Main.wo
Basically the TestList.wo get datas from DB and show them in a table, with
WOCheckBoxes on every rows for multiple selection. Every table's row have
also a Link that allow choose a single row.
*Content:*
*Main.wo:*
*HTML*
<wo:ERXNonNullConditional condition="$selectedItems">
<h1>Selezione Multipla</h1>
<ul>
<wo:loop list = "$selectedItems" item="$item">
<li><wo:str value = "$item.name"></wo:str></li>
</wo:loop>
</ul>
</wo:ERXNonNullConditional>
<wo:ERXNonNullConditional condition="$selectedSingle">
<h1>Selezione Singola</h1>
<p>
<wo:str value = "$selectedSingle.name"></wo:str>
</p>
</wo:ERXNonNullConditional>
<wo:form multipleSubmit = "$true">
<p>
<wo:submit action = "$selectMultiple"></wo:submit>
</p>
<wo:TestList selectedItems = "$selectedItems" selectedSingle =
"$selectedSingle"></wo:TestList>
</wo:form>
The first two components simply show the result of the operation getting
datas from Subcomponents
*Java:*
Here I prepare the variables that I'll use to store datas from
subcomponent, and the Actions that are called after the Multiple selection
of the single selection.
public NSArray<Item> selectedItems;
public WOActionResults selectMultiple(){
selectedSingle = null;
return null;
}
public Item selectedSingle;
public WOActionResults clickChoosed(){
selectedItems = null;
return null;
}
The actions basically do nothing, but you can put logic in these methods.
*TestList.wo:*
*API bindings: *
*selectedItems*: Undefined - Required
*selectedSingle*: Undefined - Required
*HTML*
<table>
<thead>
<tr>
<th><input type = "checkbox" name = "all" value = "1"
onclick="changeAll(this.form);" /></th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<wo:loop item = "$item" list = "$items">
<tr>
<td>
<wo:checkBox value = "$true" selection
= "$selectedItem"></wo:checkBox>
</td>
<td>
<wo:str value = "$item.name"></wo:str>
</td>
<td>
<wo:link action =
"$clickChoosed">Choose</wo:link>
</td>
</tr>
</wo:loop>
</tbody></table>
*In Java:*
/** * Generate the List of Items from the DB and variables
for the Component */
private NSArray<Item> items;
private Item item;
/** * @return the items */
public NSArray<Item> items() {
if(items == null)
items = Item.fetchAllItems(ERXEC.newEditingContext());
return items;
}
/** * @param items the items to set */
public void setItems(NSArray<Item> items) {
this.items = items;
}
/** * @return the item */
public Item item() {
return item;
}
/** * @param item the item to set */
public void setItem(Item item) {
this.item = item;
}
/** * Handle the Multiple Checkbox Selection */
private NSMutableArray<Item> _selectedItems = null;
public Boolean selectedItem() {
if(_selectedItems == null)
_selectedItems = new NSMutableArray<Item>();
return _selectedItems.containsObject(item);
}
public void setSelectedItem(Boolean selected) {
if(item == null) return;
if(selected != null && selected.booleanValue())
{
if(!_selectedItems.containsObject(item))
_selectedItems.addObject(item);
}
else{
if(_selectedItems.containsObject(item))
_selectedItems.removeObject(item);
}
}
/** * Prepare the Getter/Setter for the bindings */
public NSMutableArray<Item> selectedItems(){
return _selectedItems;
}
public void setSelectedItems(NSMutableArray<Item> selected){
_selectedItems = selected;
}
private Item _selectedSingle;
public Item selectedSingle(){
return _selectedSingle;
}
public void setSelectedSingle(Item item){
_selectedSingle = item;
}
/** * This is the Action fired by links on the table's rows. Call
the Parent Action "clickChoosed" * @return {@link WOActionResults}
*/
public WOActionResults clickChoosed() {
_selectedSingle = item;
return performParentAction("clickChoosed");
}
Basically, when I push the submit button or click a link, automatically the
variables in the Main.wo are populated with the result. I can also change
the selections on the TestList.wo checkboxes by changing the content of the
selectedItems array in Main.wo Component.
Hope anyone can find this useful!
Thanks to everyone!
2015-01-28 18:10 GMT+01:00 Daniele Corti <[email protected]>:
> Hi Robet,
> that's what I want to do!
>
> Thank You!
>
> I was thinking too much about code, not remembering Bindings are the great
> function in WO.
>
>
> Thank you, again!
>
> --
> Daniele
>
>
> 2015-01-28 18:01 GMT+01:00 Robert B. Hanviriyapunt <
> [email protected]>:
>
>> Daniele,
>>
>> If your components auto synchronize (true, by default), then all you
>> would need to do is add a binding.
>>
>> MyList.api
>> - add mySelection binding (when bound, this will cause array to be pushed
>> down to the subcomponent as well as pushed up from the subcomponent at
>> various times in request-response cycle)
>>
>> if MyList does NOT auto synchronize, then you will need to at the least
>> code push up to parent to have the parent get the value, OR use a shortcut
>> (at least I know this shortcut is available in the WOD file):
>>
>> MyList.wod:
>>
>> Foo : MyList {
>> mySelection = ^mySelection;
>> }
>>
>> Then bind a var in the parent component to the subcomponent
>>
>> MyPage.wo
>> - add binding <wo:MyList mySelection=“$myPageMySelection”/>
>>
>> see:
>> http://en.wikibooks.org/wiki/WebObjects/Web_Applications/Development/WO_Component/Binding_Synchronization
>>
>> But in general, pages/components don’t have direct access to
>> subcomponents. They push/pull values via bindings or share objects whose
>> attributes can be seen by both component classes.
>>
>> --
>> *Robert B. Hanviriyapunt*
>> *Director of Product Development and Architecture*
>>
>>
>> / EDC Technology
>>
>>
>> Direct 312.246.5509
>> Fax 630.243.5799
>>
>> [email protected]
>> [email protected]
>> http://www.EDCTechnology.com
>>
>>
>>
>> On Jan 28, 2015, at 8:00 AM, [email protected]
>> wrote:
>>
>> Hi Amedeo,
>> thanks for the answer, but, sorry, I'm not sure to understand it.
>> AFAIK, WODynamicElement
>> is a simple HTML Element, not a component, so I cannot assign a .wo file
>> to
>> it (or am I wrong?).
>>
>> Anyway, I'm trying to change my example by moving the submit button on the
>> SubComponent and using context().page().takeValueForKey(Object value,
>> String key) in the SubComponent Action to set the value in the Parent
>> Component, last I call performParentAction(String action) to do the login
>> in the parent.
>>
>> Not sure if this is the best way, but seems to work.
>>
>> Thank you,
>> __
>> Daniele
>>
>>
>> 2015-01-28 14:02 GMT+01:00 Amedeo Mantica <[email protected]>:
>>
>> The only way is to use a WODynamicElement as subcomponent instead of a
>> WOComponent
>>
>> Sent from my iPhone
>>
>> On 28/gen/2015, at 12:46, Daniele Corti <[email protected]> wrote:
>>
>> Hi list,
>> I don't know if what I want to do is the best approach:
>>
>> I would like to create a Main Component Page that call a reusable
>>
>> SubComponent
>>
>>
>> Example:
>>
>> MyPage.wo:
>> <h1>My Page</h1>
>>
>> <wo:form multipleSubmit="$true">
>> <wo:submitButton action="$myAction">Do It!</wo:subimtButton>
>> <wo:MyList></wo:MyList>
>> </wo:form>
>>
>> in the Subcomponent there is a List of Checkbox
>>
>> MyList.wo:
>> <ul>
>> <wo:loop list="$myList" item="$myItem">
>> <li><wo:checkBox selection="$mySelection"
>>
>> value="$true"></wo:checkBox></li>
>>
>> </wo:loop>
>> </ul>
>>
>> I would like to obtain the checked objects of the subcomponent, but I
>>
>> don't know how can I get the subcomponent from the Parent MyPage.
>>
>>
>> I know I can put the button in the subcomponent and call
>>
>> performParentAction, but I would like to put all the logic inside the
>> MyPage component, and simply display values in the MyList component.
>>
>>
>> Is this possible (first of all)? And, if so, how can I reach
>>
>> subcomponents from parent?
>>
>>
>> Thank you in advance!
>>
>> --
>> Daniele Corti
>> --
>> I DON'T DoubleClick
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list ([email protected])
>> Help/Unsubscribe/Update your Subscription:
>>
>>
>> https://lists.apple.com/mailman/options/webobjects-dev/amedeomantica%40me.com
>>
>>
>> This email sent to [email protected]
>>
>>
>>
>
>
> --
> Daniele Corti
> --
> I DON'T DoubleClick
>
--
Daniele Corti
--
I DON'T DoubleClick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]