Results 1 to 4 of 4

Thread: Difference between action="" and action="?"

  1. #1
    Join Date
    Jul 2012

    Difference between action="" and action="?"

    Seems both of them don't create any query string when user submit. I don't know difference between "empty blank" and "question mark" property?

  2. #2
    Join Date
    Mar 2011
    The 'action' attribute of the <form> tag tells the browser what action to take when the user "submits" the form. It is the same as the 'href' attribute of the <a>nchor tag, and should contain the URL/URI of the resource (script or page) to be used to process the user's submission. If empty or missing, the default value is the current page - that is, the form is "submitted" to the page itself, which is reloaded. Your example where the 'action' attribute is set to "?" would mean the the form would be submitted to the current page with an empty (or invalid) query string.

    Keep in mind that the 'method' attribute of the <form> tag determines how the form data is transmitted to the URI pointed to by the 'action' attribute. It can be either 'GET' (the default) or 'POST'. If the form uses the 'GET" method, the form data is encoded into a query string which is appended to the URI from the 'action' attribute. Your example of the 'action' attribute being set to '?' would end up creating an invalid query string. Finally, if the form uses the 'POST' method, the form data is incorporated into the HTTP request sent to the URI pointed to by the 'action' attribute.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Sep 2012
    Very nice information about action="" and action="?". Thanks for sharing...

  4. #4
    Join Date
    Oct 2012
    Use actionListener if you want have a hook before the real business action get executed, e.g. to log it, and/or to set an additional property (by <f:setPropertyActionListener>), and/or to have access to the component which invoked the action (which is available by ActionEvent argument). The actionListener method is required to have the following signature:

    public void actionListener(ActionEvent event) {
    // ...
    Note that you can't pass additional arguments by EL 2.2.

    Use action if you want to execute a business action and if necessary handle navigation. The action method can return a String which will be used as navigation case outcome (the target view). The action method can be any valid MethodExpression, also the ones which uses EL 2.2 arguments, e.g:

    <h:commandLink value="submit" action="#{bean.edit(item)}" />

    public void edit(Item item) {
    // ...
    The actionListeners are always invoked before the action in the order they are been declared in the view. So, the following example

    <h:commandLink value="submit" actionListener="#{bean.listener1}" action="#{bean.submit}">
    <f:actionListener type="com.example.SomeActionListener" />
    <f:setPropertyActionListener target="#{bean.property}" value="some" />
    will invoke Bean#listener1(), SomeActionListener#processAction(), Bean#setProperty() and Bean#submit() in this order.

    Another subtle difference is that the actionListener swallows any exceptions and won't propagate it up (i.e. you won't see an error/exception page, JSF will log them however). This is done so because the business logic, exception handling and navigation handling job is up to the action method.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles