Sal81
Sal81

Reputation: 101

Jsf ui:repeat - method that populates the value is accessed even when submiting different form

In my actual project I have noticed that the method that populates the ui:repeat tag, is being invoked when there is a post call, even though the ui:repeat is not part of the submitted form.

I have been trying to check againts the jsf documentation if that is the way it should work, with no success.

Is it supposed to work this way?

Thanks in advance.

Sample code:

When the button is clicked the method anotherBean.getCollection is being invoked:

<h:form id="firstForm">  
    <h:commandButton action="#{someBean.someAction}"/>   
</h:form>

<h:form id="secondForm">  
    <ui:repeat var="product" value="#{anotherBean.populatCollection}" >  
        <!-- CODE -->  
    </ui:repeat>  
</h:form>

Upvotes: 0

Views: 1081

Answers (2)

Sal81
Sal81

Reputation: 101

So, it looks like ui:repeat tag is invoking the methods assigned to its value argument when a post is done, no matter if the post is done from another form.

Thanks for the help.

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

In first place, a getter method shouldn't be populating the value at all. A getter method should, as its name says, just return the already-populated value.

You're not terribly clear on the concrete functional requirement, i.e. when exactly did you intend to populate the value, but one way would be moving the populating logic to the @PostConstruct of #{anotherBean}.

@ManagedBean
@ViewScoped
public class AnotherBean {

    private List<Something> getCollection; // Terrible variable name by the way.

    @PostConstruct
    public void init() {
        getCollection = populateItSomehow();
    }

    public List<Something> getGetCollection() {
        return getCollection; // See, just return the property, nothing more!
    }

}

See also:

Upvotes: 1

Related Questions