You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Matthias Klein <ma...@cmklein.de> on 2006/05/22 17:11:57 UTC

[newbie] passing a parameter between two backing beans

Hi everyone

I have a small JSF application with two pages: menu.jsp and details.jsp

The menu.jsp contains something like this in a dataTable:

<h:form>
  <h:commandLink action="#{MenuBackingBean.userClick}" >
    <h:outputText value="#{menuTabItem.itemName}" />
    <f:param name="itemID" value="#{menuTabItem.itemID}" />
  </h:commandLink>
</h:form>

Depending on the itemID, the method userClick() returns "menu" or
"details" (if the return value is "menu", there is a sub-menu to be
displayed. if the return value is "display", there is no more sub-menu but
details of an actual item to be displayed) Those actions "menu" and
"details" are obviously associated with navigation rules of the
faces-config.

But here is my question:
If userClick() wants to return "details", I want it to pass the itemID to
the DetailsBackingBean first (before the statement return "details";)

How do I do that? The DetailsBackingBean is supposed to take this itemID
and look up the details data associated with this itemID before it
displays the details.jsp

How can that be done?
Is that even the right way to go?




Re: [newbie] passing a parameter between two backing beans

Posted by Matthias Klein <ma...@cmklein.de>.
Thanks. I read that Wiki article. And in fact, when I wrote my question, I
had the first approach implemented (the one with the FacesContext).
I put this long statement "FacesContext...get("id");" into the constructor
of my DetailsBackingBean - and was able to obtain the ID and perform the
lookup. The same would happen with approach 2 outlined in your wiki
article.

However, this works only once: whenever the DetailsBackingBean is
constructed. This scope of this bean is set to session because when i set
it to request, the button "back to the menu" doesn't work anymore (no idea
why). That button only calls a method in the DetailsBackingBean which
return the action "menu". Works if the scope is session, throws an
exception when scope is request.

I figured that the "session" scope would make sense because if I am not
mistaken that means that those classes are instantiated once for each user
session, right?

So either I debug my application so the scope can be set to "request" or I
need to implement the "details lookup query" in the MenuBackingBean which
then updates the attributes of the DetailsBackingBean. Are those really my
only options? Especially the latter one sounds "ugly".

Any idea?

thanks

Matt



Am Mo, 22.05.2006, 17:15, schrieb Matthias Wessendorf:
> Hi Matthias :-)
>
>
> You should read [1].
>
>
> I prefere the usage of updateActionListener
>
>
> -Matthias
>
>
> [1]
> http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters
>
>
> On 5/22/06, Matthias Klein <ma...@cmklein.de> wrote:
>
>> Hi everyone
>>
>>
>> I have a small JSF application with two pages: menu.jsp and details.jsp
>>
>>
>> The menu.jsp contains something like this in a dataTable:
>>
>>
>> <h:form>
>> <h:commandLink action="#{MenuBackingBean.userClick}" >
>> <h:outputText value="#{menuTabItem.itemName}" />
>> <f:param name="itemID" value="#{menuTabItem.itemID}" />
>> </h:commandLink>
>> </h:form>
>>
>>
>> Depending on the itemID, the method userClick() returns "menu" or
>> "details" (if the return value is "menu", there is a sub-menu to be
>> displayed. if the return value is "display", there is no more sub-menu
>> but details of an actual item to be displayed) Those actions "menu" and
>> "details" are obviously associated with navigation rules of the
>> faces-config.
>>
>> But here is my question:
>> If userClick() wants to return "details", I want it to pass the itemID
>> to the DetailsBackingBean first (before the statement return "details";)
>>
>>
>> How do I do that? The DetailsBackingBean is supposed to take this
>> itemID and look up the details data associated with this itemID before
>> it displays the details.jsp
>>
>> How can that be done?
>> Is that even the right way to go?
>>
>>
>>
>>
>>
>
>
> --
> Matthias Wessendorf
> Aechterhoek 18
> 48282 Emsdetten
> http://jroller.com/page/mwessendorf
> mwessendorf-at-gmail-dot-com
>



Re: [newbie] passing a parameter between two backing beans

Posted by Matthias Wessendorf <ma...@apache.org>.
Hi Matthias :-)

You should read [1].

I prefere the usage of updateActionListener

-Matthias

[1] http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters

On 5/22/06, Matthias Klein <ma...@cmklein.de> wrote:
> Hi everyone
>
> I have a small JSF application with two pages: menu.jsp and details.jsp
>
> The menu.jsp contains something like this in a dataTable:
>
> <h:form>
>   <h:commandLink action="#{MenuBackingBean.userClick}" >
>     <h:outputText value="#{menuTabItem.itemName}" />
>     <f:param name="itemID" value="#{menuTabItem.itemID}" />
>   </h:commandLink>
> </h:form>
>
> Depending on the itemID, the method userClick() returns "menu" or
> "details" (if the return value is "menu", there is a sub-menu to be
> displayed. if the return value is "display", there is no more sub-menu but
> details of an actual item to be displayed) Those actions "menu" and
> "details" are obviously associated with navigation rules of the
> faces-config.
>
> But here is my question:
> If userClick() wants to return "details", I want it to pass the itemID to
> the DetailsBackingBean first (before the statement return "details";)
>
> How do I do that? The DetailsBackingBean is supposed to take this itemID
> and look up the details data associated with this itemID before it
> displays the details.jsp
>
> How can that be done?
> Is that even the right way to go?
>
>
>
>


-- 
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
http://jroller.com/page/mwessendorf
mwessendorf-at-gmail-dot-com