You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Norm Deane <no...@vanderbilt.edu> on 2005/02/08 20:09:03 UTC
Submit Button Outside Form
Is it possible to create a form submit button (with htmlCommandLink or
whatever) outside the scope of the <h:form> that is submits. Sounds
crazy I know but consider this scenario...
We have a Tiles application. In this Tiles application there is a
"navigation" tile on the left and a "content" tile on the right. The
navigation tile has action links that are related to the current view in
the content tile. Sometimes an action link in the navigation tile will
submit a form that is defined in the content tile. In the current
Struts/Tiles/JSP implementation this easily achieved through some simple
JavaScript onclick stuff. How can this same approach be implemented in
JSF? I thought about just continuing down the JavaScript road but I
wasn't sure what pitfalls I might run into.
Thanks,
Norm Deane
http://jroller.com/page/deanen
Re: Submit Button Outside Form
Posted by Norm Deane <no...@vanderbilt.edu>.
I'm not completely sure I follow. Can you post some code snippets?
Norm
Heath Borders wrote:
>We had this problem also. The way we solved it was to have a few
>different options for form configuration.
>
>There is essentially 1 Tile for content in our pages that does an
>include on a JSP. The rest of the framework gets built from xml files
>so that developers don't have to deal with styling.
>
>Normally, a <h:form /> wraps all the Tiles, but occassionally, you
>need two forms inside your content JSP, so you can use a Tiles
>parameter to turn off the wrapping form.
>
>
>On Thu, 10 Feb 2005 08:37:17 -0500, Sean Schofield
><se...@gmail.com> wrote:
>
>
>>Hmmm. Well I better figure this out because the application I am
>>going to eventually be porting over an existing application to JSF
>>that will require this!
>>
>>How about this ...
>>
>>Make a command button on the main page but have it be hidden (with a
>>style I guess.) Give it a meaningful id and use the new forceId
>>attribute. Then have a button on your nav page that uses javascript
>>and getElementById to locate the button and "click" it.
>>
>>Another option might be to put the <h:form> tag in your top level
>>tiles layout page so both your nav page and your main page are part of
>>the same form.
>>
>>HTH,
>>
>>sean
>>
>>On Tue, 08 Feb 2005 13:09:03 -0600, Norm Deane
>><no...@vanderbilt.edu> wrote:
>>
>>
>>>Is it possible to create a form submit button (with htmlCommandLink or
>>>whatever) outside the scope of the <h:form> that is submits. Sounds
>>>crazy I know but consider this scenario...
>>>
>>>We have a Tiles application. In this Tiles application there is a
>>>"navigation" tile on the left and a "content" tile on the right. The
>>>navigation tile has action links that are related to the current view in
>>>the content tile. Sometimes an action link in the navigation tile will
>>>submit a form that is defined in the content tile. In the current
>>>Struts/Tiles/JSP implementation this easily achieved through some simple
>>>JavaScript onclick stuff. How can this same approach be implemented in
>>>JSF? I thought about just continuing down the JavaScript road but I
>>>wasn't sure what pitfalls I might run into.
>>>
>>>Thanks,
>>>
>>>Norm Deane
>>>http://jroller.com/page/deanen
>>>
>>>
>>>
>
>
>
>
Re: Submit Button Outside Form
Posted by Heath Borders <he...@gmail.com>.
We had this problem also. The way we solved it was to have a few
different options for form configuration.
There is essentially 1 Tile for content in our pages that does an
include on a JSP. The rest of the framework gets built from xml files
so that developers don't have to deal with styling.
Normally, a <h:form /> wraps all the Tiles, but occassionally, you
need two forms inside your content JSP, so you can use a Tiles
parameter to turn off the wrapping form.
On Thu, 10 Feb 2005 08:37:17 -0500, Sean Schofield
<se...@gmail.com> wrote:
> Hmmm. Well I better figure this out because the application I am
> going to eventually be porting over an existing application to JSF
> that will require this!
>
> How about this ...
>
> Make a command button on the main page but have it be hidden (with a
> style I guess.) Give it a meaningful id and use the new forceId
> attribute. Then have a button on your nav page that uses javascript
> and getElementById to locate the button and "click" it.
>
> Another option might be to put the <h:form> tag in your top level
> tiles layout page so both your nav page and your main page are part of
> the same form.
>
> HTH,
>
> sean
>
> On Tue, 08 Feb 2005 13:09:03 -0600, Norm Deane
> <no...@vanderbilt.edu> wrote:
> > Is it possible to create a form submit button (with htmlCommandLink or
> > whatever) outside the scope of the <h:form> that is submits. Sounds
> > crazy I know but consider this scenario...
> >
> > We have a Tiles application. In this Tiles application there is a
> > "navigation" tile on the left and a "content" tile on the right. The
> > navigation tile has action links that are related to the current view in
> > the content tile. Sometimes an action link in the navigation tile will
> > submit a form that is defined in the content tile. In the current
> > Struts/Tiles/JSP implementation this easily achieved through some simple
> > JavaScript onclick stuff. How can this same approach be implemented in
> > JSF? I thought about just continuing down the JavaScript road but I
> > wasn't sure what pitfalls I might run into.
> >
> > Thanks,
> >
> > Norm Deane
> > http://jroller.com/page/deanen
> >
>
--
-Heath Borders-Wing
hborders@mail.win.org
Re: Submit Button Outside Form
Posted by Sean Schofield <se...@gmail.com>.
Yes you have to use click(). You will probably want to use forceId on
your commandButtons so you don't have to try and guess what your id
will be every time you change up your tiles layout.
sean
On Tue, 15 Feb 2005 13:05:45 -0600, Norm Deane
<no...@vanderbilt.edu> wrote:
> Sean Schofield wrote:
>
> >Each button posts its id (and value) back when it is submitting. This
> >is how JSF knows which action listener to invoke. So just tell the
> >script to "click" the appropriate button.
> >
> >
> >
> Yes. That is what I'm doing but don't you have to use click() vs.
> submit()? That is what I'm doing.
>
> Norm
>
Re: Submit Button Outside Form
Posted by Norm Deane <no...@vanderbilt.edu>.
Sean Schofield wrote:
>Each button posts its id (and value) back when it is submitting. This
>is how JSF knows which action listener to invoke. So just tell the
>script to "click" the appropriate button.
>
>
>
Yes. That is what I'm doing but don't you have to use click() vs.
submit()? That is what I'm doing.
Norm
Re: Submit Button Outside Form
Posted by Sean Schofield <se...@gmail.com>.
Each button posts its id (and value) back when it is submitting. This
is how JSF knows which action listener to invoke. So just tell the
script to "click" the appropriate button.
sean
On Tue, 15 Feb 2005 12:44:46 -0600, Norm Deane
<no...@vanderbilt.edu> wrote:
> Sean Schofield wrote:
>
> >I took a look at what we are doing in our current application (no
> >Faces just yet) that uses Tiles and has the "nav" section you are
> >describing.
> >
> >Basically we know the id of the form that will ultimately end up in
> >the "main" section of our page so we use:
> >
> >document.forms.fooForm.submit();
> >
> >Why not just use this approach? I think you can add a style to your
> ><h:commandButton> so it would be hidden.
> >
> >
> >
> There are actually multiple buttons on this form that could trigger a
> submit. Each button is associated with a different actionListener
> method. How would it know which actionListener to fire if I just used
> "document.forms.fooForm.submit();" ?
>
> >sean
> >
> >
> >
>
> Norm
>
Re: Submit Button Outside Form
Posted by Norm Deane <no...@vanderbilt.edu>.
Sean Schofield wrote:
>I took a look at what we are doing in our current application (no
>Faces just yet) that uses Tiles and has the "nav" section you are
>describing.
>
>Basically we know the id of the form that will ultimately end up in
>the "main" section of our page so we use:
>
>document.forms.fooForm.submit();
>
>Why not just use this approach? I think you can add a style to your
><h:commandButton> so it would be hidden.
>
>
>
There are actually multiple buttons on this form that could trigger a
submit. Each button is associated with a different actionListener
method. How would it know which actionListener to fire if I just used
"document.forms.fooForm.submit();" ?
>sean
>
>
>
Norm
Re: Submit Button Outside Form
Posted by Sean Schofield <se...@gmail.com>.
I took a look at what we are doing in our current application (no
Faces just yet) that uses Tiles and has the "nav" section you are
describing.
Basically we know the id of the form that will ultimately end up in
the "main" section of our page so we use:
document.forms.fooForm.submit();
Why not just use this approach? I think you can add a style to your
<h:commandButton> so it would be hidden.
sean
On Tue, 15 Feb 2005 08:39:34 -0600, Norm Deane
<no...@vanderbilt.edu> wrote:
> The hidden command button/javascript click() solution is working for me.
> I'm not real crazy about it though. Seems like a hack. How about a JSF
> component that renders a submit button for a form defined elsewhere? I
> haven't dug very deep into the JSF internals yet but it seems like the
> component could navigate the component tree, find a form by id, and then
> render a submit button that uses JavaScript to submit the form. Would
> this work?
>
> Thanks,
>
> Norm Deane
> http://jroller.com/page/deanen
>
> Norm Deane wrote:
>
> > Sean Schofield wrote:
> >
> >> Hmmm. Well I better figure this out because the application I am
> >> going to eventually be porting over an existing application to JSF
> >> that will require this!
> >>
> >> How about this ...
> >>
> >> Make a command button on the main page but have it be hidden (with a
> >> style I guess.) Give it a meaningful id and use the new forceId
> >> attribute. Then have a button on your nav page that uses javascript
> >> and getElementById to locate the button and "click" it.
> >>
> >>
> >>
> >
> > I think I'll give this approach a shot and see how it works.
> >
> >> Another option might be to put the <h:form> tag in your top level
> >> tiles layout page so both your nav page and your main page are part of
> >> the same form.
> >>
> >> HTH,
> >>
> >> sean
> >>
> >>
> >>
> > I thought about this approach but it could get messy when you get into
> > multiple forms on a page.
> >
> > Norm
> >
>
>
Re: Submit Button Outside Form
Posted by Norm Deane <no...@vanderbilt.edu>.
The hidden command button/javascript click() solution is working for me.
I'm not real crazy about it though. Seems like a hack. How about a JSF
component that renders a submit button for a form defined elsewhere? I
haven't dug very deep into the JSF internals yet but it seems like the
component could navigate the component tree, find a form by id, and then
render a submit button that uses JavaScript to submit the form. Would
this work?
Thanks,
Norm Deane
http://jroller.com/page/deanen
Norm Deane wrote:
> Sean Schofield wrote:
>
>> Hmmm. Well I better figure this out because the application I am
>> going to eventually be porting over an existing application to JSF
>> that will require this!
>>
>> How about this ...
>>
>> Make a command button on the main page but have it be hidden (with a
>> style I guess.) Give it a meaningful id and use the new forceId
>> attribute. Then have a button on your nav page that uses javascript
>> and getElementById to locate the button and "click" it.
>>
>>
>>
>
> I think I'll give this approach a shot and see how it works.
>
>> Another option might be to put the <h:form> tag in your top level
>> tiles layout page so both your nav page and your main page are part of
>> the same form.
>>
>> HTH,
>>
>> sean
>>
>>
>>
> I thought about this approach but it could get messy when you get into
> multiple forms on a page.
>
> Norm
>
Re: Submit Button Outside Form
Posted by Norm Deane <no...@vanderbilt.edu>.
Sean Schofield wrote:
>Hmmm. Well I better figure this out because the application I am
>going to eventually be porting over an existing application to JSF
>that will require this!
>
>How about this ...
>
>Make a command button on the main page but have it be hidden (with a
>style I guess.) Give it a meaningful id and use the new forceId
>attribute. Then have a button on your nav page that uses javascript
>and getElementById to locate the button and "click" it.
>
>
>
I think I'll give this approach a shot and see how it works.
>Another option might be to put the <h:form> tag in your top level
>tiles layout page so both your nav page and your main page are part of
>the same form.
>
>HTH,
>
>sean
>
>
>
I thought about this approach but it could get messy when you get into
multiple forms on a page.
Norm
Re: Submit Button Outside Form
Posted by Sean Schofield <se...@gmail.com>.
Hmmm. Well I better figure this out because the application I am
going to eventually be porting over an existing application to JSF
that will require this!
How about this ...
Make a command button on the main page but have it be hidden (with a
style I guess.) Give it a meaningful id and use the new forceId
attribute. Then have a button on your nav page that uses javascript
and getElementById to locate the button and "click" it.
Another option might be to put the <h:form> tag in your top level
tiles layout page so both your nav page and your main page are part of
the same form.
HTH,
sean
On Tue, 08 Feb 2005 13:09:03 -0600, Norm Deane
<no...@vanderbilt.edu> wrote:
> Is it possible to create a form submit button (with htmlCommandLink or
> whatever) outside the scope of the <h:form> that is submits. Sounds
> crazy I know but consider this scenario...
>
> We have a Tiles application. In this Tiles application there is a
> "navigation" tile on the left and a "content" tile on the right. The
> navigation tile has action links that are related to the current view in
> the content tile. Sometimes an action link in the navigation tile will
> submit a form that is defined in the content tile. In the current
> Struts/Tiles/JSP implementation this easily achieved through some simple
> JavaScript onclick stuff. How can this same approach be implemented in
> JSF? I thought about just continuing down the JavaScript road but I
> wasn't sure what pitfalls I might run into.
>
> Thanks,
>
> Norm Deane
> http://jroller.com/page/deanen
>
Re: Submit Button Outside Form
Posted by Sean Schofield <se...@gmail.com>.
> I think using js with outputLink would be the best approach. Just
> remember that jsf can sometimes play with names and ids of the html
> elements (but I think the name of the form should be same as id of the
> h:form)
It will definitely be the same if you use forceId. If you are using
tiles (which require subviews) it will definitely not be the same as
the id of <h:form> That is one reason why I felt strongly that we
needed forceId.
> Michał Małecki
sean
Re: Submit Button Outside Form
Posted by Michał Małecki <Mi...@man.poznan.pl>.
I think using js with outputLink would be the best approach. Just
remember that jsf can sometimes play with names and ids of the html
elements (but I think the name of the form should be same as id of the
h:form)
Micha� Ma�ecki
> Is it possible to create a form submit button (with htmlCommandLink or
> whatever) outside the scope of the <h:form> that is submits. Sounds
> crazy I know but consider this scenario...
>
> We have a Tiles application. In this Tiles application there is a
> "navigation" tile on the left and a "content" tile on the right. The
> navigation tile has action links that are related to the current view in
> the content tile. Sometimes an action link in the navigation tile will
> submit a form that is defined in the content tile. In the current
> Struts/Tiles/JSP implementation this easily achieved through some simple
> JavaScript onclick stuff. How can this same approach be implemented in
> JSF? I thought about just continuing down the JavaScript road but I
> wasn't sure what pitfalls I might run into.
>
> Thanks,
>
> Norm Deane
> http://jroller.com/page/deanen
>
>