By Artem Moskalev


2013-02-09 16:14:32 8 Comments

I'm trying to ajax-update a conditionally rendered component.

<h:form>
    ...
    <h:commandButton value="Login" action="#{login.submit}">
        <f:ajax execute="@form" render=":text" />
    </h:commandButton>
</h:form>
<h:outputText id="text" value="You're logged in!" rendered="#{not empty user}" />

However, that does not work. I can assure that #{user} is actually available. How is this caused and how can I solve it?

1 comments

@BalusC 2013-02-09 20:04:26

It's not possible to re-render (update) a component by ajax if the component itself is not rendered in first place. The component must be always rendered before ajax can re-render it. Ajax is using JavaScript document.getElementById() to find the component which needs to be updated. But if JSF hasn't rendered the component in first place, then JavaScript can't find anything to update.

The solution is to simply reference a parent component which is always rendered.

<h:form>
    ...
    <h:commandButton ...>
        <f:ajax ... render=":text" />
    </h:commandButton>
</h:form>
<h:panelGroup id="text">
    <h:outputText ... rendered="#{not empty user}" />
</h:panelGroup>

See also:

@Artem Moskalev 2013-02-09 20:45:11

I have just tried it - but for no result

@perissf 2013-02-09 21:18:15

Shouldn't the bean be at least ViewScoped, or better SessionScoped?

@Artem Moskalev 2013-02-09 21:26:38

But the container does not print any Exception trace. Ususally when the id is not found - it prints that such an id was not found in the scope.

@BalusC 2013-02-09 21:29:07

Well, then the login is simply invalid :)

@Artem Moskalev 2013-02-09 21:30:03

That would be a perfect explanation :) But the persistence provider finds it - i checked the code)

@TREMOR 2017-07-24 13:33:46

Thanks. But in <f:ajax ... render=":text" /> the colon was troublesome for me. Just entering the id between the quotes worked <f:ajax ... render="abcd" />.

@BalusC 2017-07-24 13:51:51

@TREMOR: The colon is the correct solution for the code in its current form. You've apparently a different construct whereby everything is placed inside the same naming container component. Check last "See also" link for explanation how to determine the correct client ID.

@TREMOR 2017-07-25 04:57:56

@BalusC Thank you very much for pointing it out. Just read the the second link. Im new to this hence found it really helpful. In my case it was yes, within the same namingContainer, h:form.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Form submit in conditionally rendered component is not processed

2 Answered Questions

[SOLVED] conditionally rendered input component does not update value

1 Answered Questions

[SOLVED] Primefaces: conditionally rendered component doesn't get submitted

0 Answered Questions

Ajax Rendered Link Out Side form is not working

  • 2013-08-01 13:26:04
  • Jayaram
  • 145 View
  • 0 Score
  • 0 Answer
  • Tags:   jsf jsf-2

1 Answered Questions

[SOLVED] JSF component no longer rendered, but FacesMessage remains

  • 2013-04-08 17:13:43
  • nagohs
  • 201 View
  • 0 Score
  • 1 Answer
  • Tags:   jsf-2

1 Answered Questions

[SOLVED] JSF not firing bean setters when using f:ajax

  • 2012-11-28 11:19:29
  • Alan Smith
  • 2386 View
  • 0 Score
  • 1 Answer
  • Tags:   jsf-2

1 Answered Questions

[SOLVED] Changing the component type on an ajax update

1 Answered Questions

JSF2: why does empty test in rendered of panelGroup in composite prevent action from being called?

  • 2012-03-07 03:00:24
  • Webel IT Australia - upvoter
  • 4315 View
  • 0 Score
  • 1 Answer
  • Tags:   jsf jsf-2

1 Answered Questions

Sponsored Content