0

I'm trying to have multiple elements update when a selectOneMenu's item has been selected.

Right now it works for a single element that needs updating, I did this by following this question's accepted answer, but since I'm working with id attributes, I can't re-use that.

After searching SO and various other sites (such as this search, and a search I did on Google named jsf ajax update outputtext, I can't post the link since I don't have 10 rep), I'm just kind of stuck.

How do I proceed?

The AJAX call is being made from here:

<h:form class="navbar-form"> 
    <h:selectOneMenu value="#{formHeader.selectedPersonId}" class="form-control">
        <f:selectItems value="#{persons.persons}" var="person" itemValue="#{person.id}" itemLabel="${person.fullName}"/>
        <f:ajax event="change"   listener="#{formHeader.impersonateListener}"  render=":selected-person" />        
    </h:selectOneMenu>
</h:form>     

Which successfully updates this part:

<!-- https://stackoverflow.com/questions/14790014/ajax-update-render-does-not-work-on-a-component-which-has-rendered-attribute -->
<h:panelGroup id="selected-person">
    <h:outputText>${auth.authPerson.fullName}</h:outputText>
</h:panelGroup>

But now also needs to update the <h:outputText> here:

<h:outputText value="#{auth.authPerson.fullName}"/>
<span>Working @</span>
<span>Doing bla ....</span>
<span>messages</span>

I'm quite new to JSF just as a heads up. I'm probably doing something trivially wrong or missing something very obvious.

Community
  • 1
  • 1
IWRichard
  • 241
  • 1
  • 2
  • 6

1 Answers1

1

You need to add an id to your outputText taq and then add this id to the render attribute of your f:ajax tag.

You can update multiple elements whose ids are space-separated inside the render attribute.

Apostolos
  • 10,033
  • 5
  • 24
  • 39