Passing parameters with h:commandButton — or the equivalent

前端 未结 1 1473
[愿得一人]
[愿得一人] 2021-01-07 07:28

I read on other threads that this does not work:


   &l         


        
相关标签:
1条回答
  • 2021-01-07 08:03

    This should work perfectly fine on JSF 2.x. Did you ever try it yourself? If it doesn't work, then you're either actually using JSF 1.x or you're sending a redirect after POST.

    The other threads which you're referring to were undoubtely talking about JSF 1.x, when the <f:param> was indeed not supported on <h:commandButton>. On JSF 1.x, you would have used <f:setPropertyActionListener> instead or some shot of CSS to style the <h:commandLink> to look like a button.

    E.g.

    <h:commandLink styleClass="button" ...>
    

    with

    a.button {
        display: inline-block;
        background: lightgray;
        border: 1px outset lightgray;
        outline: none;
        color: black;
        text-decoration: none;
        cursor: default;
    }
    a.button:active {
        border-style: inset;
    }
    

    Note that in JSF 2.x you've also the opportunity to use the new <h:button> which fires a GET request instead of a POST request. This is better if you don't need to execute any bean action (i.e. your current action is just returning a plain navigation case outcome) and want the request to be idempotent.

    <h:button value="Create New Account" outcome="create">
        <f:param name="acctName" value="#{acctBean.handle}" />
        <f:param name="acctNo" value="#{acctBean.id}" />
    </h:button>
    

    This will navigate to create.xhtml with the given parameters in request URL.

    0 讨论(0)
提交回复
热议问题