1

let the following code fragment contains a link to items.xhtml that lists item names and enables the user to select an item in order to view its details:

<?xml ... ?>
<!DOCTYPE ... >
<html ... >
    <h:head>
        <title>Welcome</title>
    </h:head>
    <h:body>
        <h:outputLink value="#{facesContext.externalContext.requestContextPath}/faces/client/items.xhtml">Items</h:outputLink>   
    </h:body>
</html>

When the user clicks the link named Items, then the request line states that the resource being requested is /javaee7-training/faces/client/items.xhtml and the desired action that should be applied to it is GET. That is fine.

The following code shows a fragment of items.xml:

<?xml ... ?>
<!DOCTYPE ...>
<html ...>
    <h:head>
        <title>items</title>
    </h:head>
    <h:body>
        <h:form prependId="false">
            <h:selectOneRadio value="#{bean.itemId}"
                              layout="pageDirection">
                <c:forEach items="#{bean.items}" var="itm">
                    <f:selectItem itemValue="#{itm.itemno}" 
                                  itemLabel="#{itm.itemname}" />
                </c:forEach>
            </h:selectOneRadio>

            <h:commandButton value="Details" action="item" />
        </h:form>
    </h:body>
</html>

Now when the user clicks the button named Details, then the request line states that the resource being requested is /javaee7-training/faces/client/items.xhtml and the desired action that should be applied to it is POST. I don´t expected this result, because when the user clicks the button named Details, then the requested resource is /javaee7-training/faces/client/item.xhtml and the desired action is GET.

Could anyone explain me this result and why I am wrong?

Thank you in advance

Tiny
  • 27,221
  • 105
  • 339
  • 599
Ayoub Falah
  • 484
  • 3
  • 19

1 Answers1

1

<h:commandButton> Always fire a post request because it is supposed to inside the <h:form>. And forms are always submitted as POST request in JSF arena. If you need to fire GET request use <h:button> instead of <h:commandButton>.

Usage Example:

<h:button value="Click Me!!" outcome="item"> <!--viewId is item insted of items-->
 <f:param name="item1" value="itemVal1" />
 <f:param name="item2" value="itemVal2" />
</h:button>
AsSiDe
  • 1,826
  • 2
  • 15
  • 24