2
votes

I've got the following button:

<a4j:commandButton value="#{AppMessages['general.action.cancel']}"
            disabled="#{!entityBB.expandState.editable}"
            actionListener="#{entityBB.cancel}"
            render="initialServicePanel :messages" status="ajaxStatus"
            immediate="true" />

In my case the above button does everything I need (remove the inError state from an uiComponent to rerender it and reset (cancel) everything in the form to its previous state).

When I try to use it as this:

<h:commandButton value="#{AppMessages['general.action.cancel']}"
    disabled="#{!entityBB.expandState.editable}" immediate="true">
        <a4j:ajax execute="@this" render="initialServicePanel :messages"
        listener="#{entityBB.cancel}" status="ajaxStatus" />
</h:commandButton>

it isn't working (the value gets reset but the uiComponent (an inputText) stays red though in error). Why is this? I can't figure out the difference between the two of them since I thought an a4j:commandButton was just an h:commandButton with a4j:ajax in it behind the scenes.

EDIT: Now I've got another situation where the h:commandButton removes the value but keeps it in error (red border). And the a4j:commandButton removes it from in error (red border) but keeps the value.. It's the exact same input as above. I can't explain it.. Anyone?

2
Which JSF impl/version and which RichFaces version? - BalusC
@BalusC We are using JEE5 so JSF 1.2 and RichFaces 4.2.2.Final. - GregD
"JSF 1.2" is a spec version. I asked for impl and its version. E.g. "Mojarra 1.2_15" or "MyFaces 1.2.12". This information is visible in server log. By the way, how exactly did you manage to run RichFaces 4.x on JSF 1.2? That RichFaces version is designed for JSF 2.0. You'd better verify once more if you're really using JSF 1.2. - BalusC
Looked again and the pom said, as variable: <jsf.spec.version>3.9</jsf.spec.version>. The version for richfaces came up in my eclipse while hovering over the dependency. Also noticed the following: <additionalProjectFacets> <jst.web>3.0</jst.web> <jst.jsf>2.0</jst.jsf> </additionalProjectFacets> (I did not create the different poms. Sorry for the confusion..) - GregD
This is not helpful either. Ask the project owner/lead if you can't figure on your own by just looking at webapp startup log in server log. The last part is by the way coming from Eclipse specific settings file which basically says that project facets are set to Servlet 3.0 and JSF 2.0. But this is only a development time aid and doesn't say anything about the actually running JSF impl/version. - BalusC

2 Answers

3
votes

The execute of <a4j:commandButton> defaults to @form, but the one of <a4j:ajax> defaults to @this, which means that only the "current component" is being executed (thus, the button itself). This caused that UIInput#decode() of input components aren't being called during apply request values phase. It's exactly that method which resets the validity back to true.

To achieve exactly the same effect with <h:commandButton><a4j:ajax>, you need to explicitly set the execute attribute of <a4j:ajax> to @form as well.

<h:commandButton ... value="Cancel" immediate="true">
    <a4j:ajax execute="@form" ... />
</h:commandButton>

Update: to clear out the field, which was your initial problem and which actually wouldn't have worked on <a4j:commandButton> either (so the "does everything I need" part is wrong), head to this answer for a breakdown of the problem and both a JSF 2.x and JSF 1.x targeted solution: Input fields hold previous values only if validation failed.

0
votes

It is not the same code. The translation should be:

<h:commandButton value="#{AppMessages['general.action.cancel']}"
    disabled="#{!entityBB.expandState.editable}" immediate="true"
    actionListener="#{entityBB.cancel}" >
        <a4j:ajax render="initialServicePanel :messages"
        status="ajaxStatus" />
</h:commandButton>

Main differences:

  • Listener is in <h:commandButton>, not in <a4j:ajax>.
  • Removed execute="@this" which will change the data sent to the server.