FAQ
Hello,



I've got a JSF application which uses the <f:param> tag embedded in a
<h:commandLink> tag in several places. Now I need to set a parameter in
a backing bean that is accessible to the JSP when the page is
re-rendered (the same page is reloaded after the actionlistener
executes, no navigation taking place).



How would I go about attaching a parameter so that it would be
accessible? Note that this type of code doesn't work:



Public void actionListener (ActionEvent evt)

{

UIParameter uip = new UIParameter();

Uip.setName("blah");

Uip.setValue("blah");

Uip.setParent(Evt.getComponent());

}



I am guessing this is because the component tree is re-created when the
response is rendered, and that therefore the parameter disappears when
my JSP tries to get to it.



Any ideas as to how this would be done? I'm pretty lost and would
appreciate your help.



-Saumil

Search Discussions

  • Emily Gu at Dec 28, 2005 at 5:33 am
    I know you can get it as following. I don't know whether you have another
    way to do it though.

    public void actionListener (ActionEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    param =
    (String)context.getExternalContext().getRequestParameterMap().get("bluh");
    System.out.println("param: " + param);
    setParam("bluh2");
    }

    You can have regular setter and getter for param in the backing bean.
    On 12/27/05, Saumil Mehta wrote:

    Hello,



    I've got a JSF application which uses the <f:param> tag embedded in a
    <h:commandLink> tag in several places. Now I need to set a parameter in a
    backing bean that is accessible to the JSP when the page is re-rendered (the
    same page is reloaded after the actionlistener executes, no navigation
    taking place).



    How would I go about attaching a parameter so that it would be accessible?
    Note that this type of code doesn't work:



    Public void actionListener (ActionEvent evt)

    {

    UIParameter uip = new UIParameter();

    Uip.setName("blah");

    Uip.setValue("blah");

    Uip.setParent(Evt.getComponent());

    }



    I am guessing this is because the component tree is re-created when the
    response is rendered, and that therefore the parameter disappears when my
    JSP tries to get to it.



    Any ideas as to how this would be done? I'm pretty lost and would
    appreciate your help.



    -Saumil
  • Saumil Mehta at Dec 28, 2005 at 5:43 am
    Hmm...quick questions:



    a) where is the setParam call from?

    b) Sorry if I didn't explain this right, but what I am looking to
    do is attach parameters in the backing bean that would be visible to the
    JSP code as follows

    a. <h:outputText value="#{param.blah}"/>, where blah was *created*
    and *set* on the server-side.



    Is this possible, or am I going down a crazy path?



    Thanks,

    -Saumil





    _____

    From: Emily Gu
    Sent: Tuesday, December 27, 2005 9:33 PM
    To: MyFaces Discussion
    Subject: Re: set UIParameter in backing bean



    I know you can get it as following. I don't know whether you have
    another way to do it though.



    public void actionListener (ActionEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    param =
    (String)context.getExternalContext().getRequestParameterMap().get("bluh"
    );
    System.out.println("param: " + param);
    setParam("bluh2");
    }



    You can have regular setter and getter for param in the backing bean.



    On 12/27/05, Saumil Mehta wrote:

    Hello,



    I've got a JSF application which uses the <f:param> tag embedded in a
    <h:commandLink> tag in several places. Now I need to set a parameter in
    a backing bean that is accessible to the JSP when the page is
    re-rendered (the same page is reloaded after the actionlistener
    executes, no navigation taking place).



    How would I go about attaching a parameter so that it would be
    accessible? Note that this type of code doesn't work:



    Public void actionListener (ActionEvent evt)

    {

    UIParameter uip = new UIParameter();

    Uip.setName("blah");

    Uip.setValue("blah");

    Uip.setParent(Evt.getComponent());

    }



    I am guessing this is because the component tree is re-created when the
    response is rendered, and that therefore the parameter disappears when
    my JSP tries to get to it.



    Any ideas as to how this would be done? I'm pretty lost and would
    appreciate your help.



    -Saumil
  • Emily Gu at Dec 28, 2005 at 6:09 am
    Yes, you can

    Suppose you have a sample.jsp page that has something like
    <h:commandLink action="#{yourBean.action}"
    actionListener="#{yourBean.actionListerner}">
    <h:outputText value="#{yourBean.param}"/>,
    </h:commandLink>

    You have a bean called YourBean. You can give a default value of param as
    "bluh" for example, then change its value in actionListerner.
    On 12/28/05, Saumil Mehta wrote:

    Hmm…quick questions:



    a) where is the setParam call from?

    b) Sorry if I didn't explain this right, but what I am looking to do
    is attach parameters in the backing bean that would be visible to the JSP
    code as follows

    a. <h:outputText value="#{param.blah}"/>, where blah was **created**
    and **set** on the server-side.



    Is this possible, or am I going down a crazy path?



    Thanks,

    -Saumil




    ------------------------------

    *From:* Emily Gu
    *Sent:* Tuesday, December 27, 2005 9:33 PM
    *To:* MyFaces Discussion
    *Subject:* Re: set UIParameter in backing bean



    I know you can get it as following. I don't know whether you have another
    way to do it though.



    public void actionListener (ActionEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    param =
    (String)context.getExternalContext().getRequestParameterMap().get("bluh");
    System.out.println("param: " + param);
    setParam("bluh2");
    }



    You can have regular setter and getter for param in the backing bean.



    On 12/27/05, *Saumil Mehta* wrote:

    Hello,



    I've got a JSF application which uses the <f:param> tag embedded in a
    <h:commandLink> tag in several places. Now I need to set a parameter in a
    backing bean that is accessible to the JSP when the page is re-rendered (the
    same page is reloaded after the actionlistener executes, no navigation
    taking place).



    How would I go about attaching a parameter so that it would be accessible?
    Note that this type of code doesn't work:



    Public void actionListener (ActionEvent evt)

    {

    UIParameter uip = new UIParameter();

    Uip.setName("blah");

    Uip.setValue("blah");

    Uip.setParent(Evt.getComponent());

    }



    I am guessing this is because the component tree is re-created when the
    response is rendered, and that therefore the parameter disappears when my
    JSP tries to get to it.



    Any ideas as to how this would be done? I'm pretty lost and would
    appreciate your help.



    -Saumil

  • Dennis Byrne at Dec 28, 2005 at 6:17 am
    Try getting away from request parameters altogether with something like t:updateActionListener . I promise you will be glad ;)

    <h:commandLink value="Select Customer X">
    <t:updateActionListener value="#{path.to.customer.id}"
    property="#{backingbean.customeridProperty}" />
    </h:commandLink>
    -----Original Message-----
    From: Emily Gu
    Sent: Wednesday, December 28, 2005 12:32 AM
    To: 'MyFaces Discussion'
    Subject: Re: set UIParameter in backing bean

    I know you can get it as following. I don't know whether you have another
    way to do it though.

    public void actionListener (ActionEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    param =
    (String)context.getExternalContext().getRequestParameterMap().get("bluh");
    System.out.println("param: " + param);
    setParam("bluh2");
    }

    You can have regular setter and getter for param in the backing bean.
    On 12/27/05, Saumil Mehta wrote:

    Hello,



    I've got a JSF application which uses the <f:param> tag embedded in a
    <h:commandLink> tag in several places. Now I need to set a parameter in a
    backing bean that is accessible to the JSP when the page is re-rendered (the
    same page is reloaded after the actionlistener executes, no navigation
    taking place).



    How would I go about attaching a parameter so that it would be accessible?
    Note that this type of code doesn't work:



    Public void actionListener (ActionEvent evt)

    {

    UIParameter uip = new UIParameter();

    Uip.setName("blah");

    Uip.setValue("blah");

    Uip.setParent(Evt.getComponent());

    }



    I am guessing this is because the component tree is re-created when the
    response is rendered, and that therefore the parameter disappears when my
    JSP tries to get to it.



    Any ideas as to how this would be done? I'm pretty lost and would
    appreciate your help.



    -Saumil
  • Mike Kienenberger at Dec 28, 2005 at 3:55 pm

    On 12/27/05, Saumil Mehta wrote:
    Uip.setParent(Evt.getComponent());
    This probably will not solve your problem, but you should *NEVER* call
    setParent.

    Use Evt.getComponent().getChildren().add(Uip) instead.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriesmyfaces
postedDec 28, '05 at 2:22a
activeDec 28, '05 at 3:55p
posts6
users4
websitemyfaces.apache.org

People

Translate

site design / logo © 2018 Grokbase