You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by CarmenG <ca...@synect.com> on 2009/11/26 23:12:07 UTC

T5: Submit Button in Custom Component, Form in Page

I have a page with a form, nested within the form is a custom component with
a select box and a submit button. When the submit button is clicked I want
to download either a PDF or Excel file based on the value of the select box.

I know the event for the submit button cannot return a value and I don't
know how the page's onSuccess event can notify the custom component to
download the file, or if it should be done another way. 

I'm new to Tapestry 5 but have used Tapestry 4 and previously 3 for many
years.

thanks,
Carmen
-- 
View this message in context: http://old.nabble.com/T5%3A-Submit-Button-in-Custom-Component%2C-Form-in-Page-tp26535560p26535560.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Submit Button in Custom Component, Form in Page

Posted by Ulrich Stärk <ul...@spielviel.de>.
Events are passed up the component hierarchy until handled, so just handle the selected event in 
your page class. Alternatively have your special component fire its own event (use 
ComponentResources for that) based on what button was clicked and handle that. That's probably the 
cleaner way to do it.

Uli

Am 26.11.2009 23:41 schrieb CarmenG:
> Sorry Uli that doesn't help me as the onSelected event cannot return a value,
> the download file in my case. Can you elobarate a bit more?
> 
> What I have read so far have only been examples of Forms and Submit
> components on the same page/component where you would have 
> 
> ....
> private String type;              // Value assigned to select component.
> private String selectedType;
> 
> public void onSelectedFromDownload() {
>     selectedType = type;
> }
> 
> public Object onSuccess() {
>     if (selectedType != null) {
>         return XYZ;                  // StreamResponse of file for selected
> type.
>     }
> }
> 
> In my case onSelectedFromDownload and onSuccess are in 2 different classes,
> how do I get onSuccess from the page class to notify the custom component to
> download the file? 
> 
> The quick and dirty hack that I used was to add selectedType as a parameter
> of the custom component so the value was available to the custom component
> and the page, but I really do not like this solution. The custom component
> should handle the downloading of the file, as it did in Tapestry 4.
> 
> Any other ideas on what I can do?
> 
> thanks,
> Carmen

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Submit Button in Custom Component, Form in Page

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 26 Nov 2009 20:41:59 -0200, CarmenG <ca...@synect.com> escreveu:

> Sorry Uli that doesn't help me as the onSelected event cannot return a  
> value, the download file in my case. Can you elobarate a bit more?

onSelect() cannot, but onSuccess() can return a StreamResponse containing  
your PDF file.

> In my case onSelectedFromDownload and onSuccess are in 2 different  
> classes, how do I get onSuccess from the page class to notify the custom  
> component to download the file?

They could be in the component class. I can't see why not.

I would have a hidden TextField that would have its value copied from your  
select tag using JavaScript. In this case, all you need is an onSuccess()  
method in your component that uses the value and then returns the  
StreamResponse.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Submit Button in Custom Component, Form in Page

Posted by CarmenG <ca...@synect.com>.
Sorry Uli that doesn't help me as the onSelected event cannot return a value,
the download file in my case. Can you elobarate a bit more?

What I have read so far have only been examples of Forms and Submit
components on the same page/component where you would have 

....
private String type;              // Value assigned to select component.
private String selectedType;

public void onSelectedFromDownload() {
    selectedType = type;
}

public Object onSuccess() {
    if (selectedType != null) {
        return XYZ;                  // StreamResponse of file for selected
type.
    }
}

In my case onSelectedFromDownload and onSuccess are in 2 different classes,
how do I get onSuccess from the page class to notify the custom component to
download the file? 

The quick and dirty hack that I used was to add selectedType as a parameter
of the custom component so the value was available to the custom component
and the page, but I really do not like this solution. The custom component
should handle the downloading of the file, as it did in Tapestry 4.

Any other ideas on what I can do?

thanks,
Carmen
-- 
View this message in context: http://old.nabble.com/T5%3A-Submit-Button-in-Custom-Component%2C-Form-in-Page-tp26535560p26535821.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Submit Button in Custom Component, Form in Page

Posted by Ulrich Stärk <ul...@spielviel.de>.
If you use the submit component, it will fire a selected event. By handling that, you can detect 
which button was clicked and act accordingly.

HTH,

Uli

Am 26.11.2009 23:12 schrieb CarmenG:
> I have a page with a form, nested within the form is a custom component with
> a select box and a submit button. When the submit button is clicked I want
> to download either a PDF or Excel file based on the value of the select box.
> 
> I know the event for the submit button cannot return a value and I don't
> know how the page's onSuccess event can notify the custom component to
> download the file, or if it should be done another way. 
> 
> I'm new to Tapestry 5 but have used Tapestry 4 and previously 3 for many
> years.
> 
> thanks,
> Carmen

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org