Skip to content
javahacks.dev
JavaServer Faces

JSF commandButton Not Working Fix for Silent Actions

Fix a JSF commandButton or commandLink that does nothing: check the form, validation messages, conversion errors, nested forms, rendered and immediate.

7 min read
Summarize in AI
Flat illustration of a browser page built from server-side components, with the OpenJDK, Thymeleaf and CSS logos.

You click Save. The page flashes, or does not even flash, and nothing changed: no navigation, no new value in the database, no message. There is no exception in the log either. A JSF h:commandButton or h:commandLink that does nothing is the classic silent failure, because the Faces lifecycle can drop a request at any of six phases without telling you, and the usual reason is that the action method was never called. This post lists the causes in the order they usually occur, with a way to confirm each and the fix. Examples use Jakarta Faces 4.1 on Mojarra with a CDI backing bean.

The reference case throughout is a page with one field and one button:

src/main/webapp/profile.xhtmlXML
<h:form>
    <h:messages globalOnly="false" />
    <h:inputText id="email" value="#{profileBean.email}" required="true" />
    <h:commandButton value="Save" action="#{profileBean.save}" />
</h:form>
src/main/java/dev/javahacks/web/ProfileBean.javajava
@Named
@ViewScoped
public class ProfileBean implements Serializable {

    private String email;

    public String save() {
        System.out.println("save called with " + email);
        return "done?faces-redirect=true";
    }

    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email; }
}

If save called with ... never prints, the action did not run. Start at the top.

1. The button is not inside a form

A command component submits the form that contains it. Outside a form there is nothing to submit, so the click does nothing at all, with no request in the browser's network tab. Check the rendered HTML: the button is an <input type="submit"> that should be a descendant of a <form> element.

XML
<!-- Wrong: no form around the button -->
<h:commandButton value="Save" action="#{profileBean.save}" />

<!-- Right -->
<h:form>
    <h:commandButton value="Save" action="#{profileBean.save}" />
</h:form>

The mirror problem is a nested form. HTML does not allow a <form> inside a <form>, and the browser drops the inner one, so the inner button submits the outer form, or nothing. This happens when a template and a page each declare their own h:form. Look for it in the page source:

XML
<h:form>                       <!-- from the template -->
    <ui:insert name="content">
        <h:form>               <!-- from the page: remove this one -->
            <h:commandButton value="Save" action="#{profileBean.save}" />
        </h:form>
    </ui:insert>
</h:form>

Keep one form per page region, and use prependId="false" or a name only when you need predictable ids.

2. A validation or conversion error stopped it

This is the most common cause by far. The lifecycle runs Apply Request Values, Process Validations, Update Model Values and only then Invoke Application. If any input fails conversion or validation in phase 3, Faces skips straight to Render Response and the action is never invoked. The message was queued, and if no h:messages or h:message is on the page, nobody sees it.

Add the messages component and click again:

XML
<h:messages showDetail="true" />
Text
Validation Error: Value is required.

Typical sources: required="true" on a field the user left empty, a converter that cannot parse a date or a number, a Bean Validation constraint on the model such as @Email or @Size, and a required field that is hidden by rendered="false" on the client side but still present on the server. Fix the data, or fix the rule. If the failing field is not relevant to this button, either set immediate="true" on the button (see section 4), or scope validation with an AJAX execute list that names only the fields it needs. The messages and converters machinery is covered in JSF validation, converters and messages.

A quick check without touching the page is to log the failures in a phase listener, or to run with jakarta.faces.PROJECT_STAGE=Development, which prints a Validation Error hint into the page automatically.

3. rendered or disabled changed on the postback

A command component is processed only if it is rendered and not disabled when the form comes back. Faces re-evaluates rendered during the postback in Apply Request Values, and if it now returns false, the button is skipped, as if it were not there.

XML
<h:commandButton value="Delete" action="#{orderBean.delete}"
                 rendered="#{orderBean.editable}" />

If editable depends on a request parameter or on a field that is only set later in the lifecycle, it is true when the page renders and false when the click arrives. Request-scoped beans make this worse: a new bean is created for the postback with default state.

Confirm it by temporarily making the condition constant:

XML
<h:commandButton value="Delete" action="#{orderBean.delete}" rendered="true" />

If the button now works, the expression is unstable across requests. The remedy is to base it on state that survives, which means a view-scoped bean or a persisted value, not a request parameter. The relationship between scope and lost state is explained in JSF bean scopes, and the sibling symptom of values that never reach the model is in JSF value not updated. The same applies to disabled: an expression that is true on the postback blocks the click.

4. The immediate attribute

immediate="true" on a command component moves its processing to the Apply Request Values phase, before validation, and skips conversion and validation of the other fields. That is useful for a Cancel button. It is also the cause of two opposite surprises.

XML
<h:commandButton value="Save" action="#{profileBean.save}" immediate="true" />

With immediate="true" the action runs, but the model has not been updated, so save() sees the old value of email. That looks like "the data is lost". The reverse also happens: an immediate input with a failing validator ends the lifecycle early and the button, which is not immediate, never fires. Only use it on a button that does not need the form's data, and do not use it as a way to quiet validation messages.

5. Something else broke the submit

If the form is valid and rendered, look at what the browser and server say.

The action method signature. An action must be public, take no arguments and return String, void or an outcome object. If the expression cannot resolve, the page fails with the error described in Target Unreachable, identifier resolved to null, but in some containers that is logged at FINE only. Raise the level for jakarta.faces and retry.

An exception swallowed by AJAX. A button with <f:ajax> that fails on the server returns a partial-response error, and the page just stops updating. Open the network tab, find the POST, and read the XML body for <error>. The Faces JavaScript library logs it too when the project stage is Development.

A JavaScript error. A script error on the page, or a onclick handler that returns false, prevents the form from being submitted at all. The console shows it.

A view that expired. After a session timeout or a server restart, the posted view state no longer exists. The click reaches the server and is answered with an exception, or, if you set a custom handler that redirects silently, with a refresh of the same page. The cure and the settings are in fixing ViewExpiredException.

A navigation outcome that points nowhere. The action runs, and returns "done", and no rule or file matches, so Faces re-renders the same page. The rules for outcomes are in implicit navigation in JSF. Check the output log for your System.out line to tell this apart from a skipped action.

6. Find where the request ends

When the list above does not name the cause, follow the lifecycle. A phase listener logs each phase boundary and the messages queued by then:

src/main/java/dev/javahacks/web/TracePhases.javajava
package dev.javahacks.web;

import jakarta.faces.context.FacesContext;
import jakarta.faces.event.PhaseEvent;
import jakarta.faces.event.PhaseId;
import jakarta.faces.event.PhaseListener;

public class TracePhases implements PhaseListener {

    @Override
    public void afterPhase(PhaseEvent event) {
        FacesContext ctx = event.getFacesContext();
        System.out.println("after " + event.getPhaseId() + ", messages=" + ctx.getMessageList().size());
    }

    @Override
    public void beforePhase(PhaseEvent event) { }

    @Override
    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }
}

Register it in faces-config.xml under <lifecycle><phase-listener>. A healthy submit prints all six phases. A validation failure shows the pattern:

Text
after RESTORE_VIEW 1, messages=0
after APPLY_REQUEST_VALUES 2, messages=0
after PROCESS_VALIDATIONS 3, messages=1
after RENDER_RESPONSE 6, messages=1

Phases 4 and 5 are missing and a message appeared in phase 3, which names the cause without further guessing. If the log stops after APPLY_REQUEST_VALUES, look at immediate and rendered. If there is no line at all, the request never arrived, so go back to the form and the JavaScript console. The deeper background on how components, state and requests communicate is in BalusC's long-standing JSF communication article, and the lifecycle is specified in Jakarta Faces 4.0.

Where this does not apply

If the button works locally and fails only behind a proxy, suspect the proxy: a rewritten path that drops the jsessionid, or a cookie that is not sent back, makes every postback a new session and a lost view. If you use h:button or h:link, these are GET navigations and never run an action method, which is by design. And with PrimeFaces p:commandButton, an ajax="false" or process/update mismatch has the same symptoms, but the checks above still apply, since it builds on the same lifecycle.

Also inDebugging
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.