Problems using SelectOneMenu primefaces

2

I have a problem updating the data of a SelectOneMenu in primefaces, as the code below suggests, I have a button that when clicked, brings data from a WebService and stores it in a Devices variable on the back end and shortly after , it only throws its names to the deviceNames list, this happens because the Size of the list with the names and OK, nothing happens in my SelectOneMenu. I have already made many changes but so far nothing. It seems to be pretty silly but I can not seem to find the problem.

XHTML Page

<h:body>
    <p:messages autoUpdate="true"/>
    <h:form id="mainform">
        <p:commandButton id="button1" 
                         value="Configuração">
            <p:ajax listener="#{config.carregaSbcDevices}" update="panelAU"/>
        </p:commandButton>
        <p:outputPanel autoUpdate="true" id="panelAU">
            <p:selectOneMenu value="#{config.configSCBEsc}">
                <f:selectItem itemLabel="Selecione..." itemValue="" />
                <f:selectItems value="#{config.devicesName}" />
            </p:selectOneMenu>
        </p:outputPanel>
    </h:form>
</h:body>

Bean config

public void carregaSbcDevices() {
    if(this.devices == null) this.devices = new ArrayList<>();
    this.devices.clear();

    if(this.devicesName == null) this.devicesName = new ArrayList<>();
    this.devicesName.clear();

    session.getDevices(this.devices);
    for(SBCDevices device : this.devices) {
        this.devicesName.add(device.getTargetName());
    }

    System.out.println("Numero: " + this.devicesName.size());
}
    
asked by anonymous 21.09.2017 / 15:48

2 answers

0

Fixed issue!

After small failures daily attempts, I noticed that the same codes made by other developers did not present an error, when searching for solutions in the packages I was using I discovered the error, the imports of SessionScoped and Named (I use this instead of @ManagedBean(name = 'beanName') . So I solved it by making the following changes:

Bean Alias:

@Named(value = "beanAgregadorDetalhe")

And its import:

import javax.inject.Named;

Scope of Session:

@SessionScoped

And its import:

import javax.enterprise.context.SessionScoped;

That way the scopes work perfectly now and the page normally talks to the bean without the need for static variables. Anyone with a problem of manipulated variables in a given scope, Beware of imports!

    
10.11.2017 / 18:49
0

Possibly your ajax update is not finding the panelAU component. This is because when performing the rendering on the screen the firstfaces add the name of the form next to the name that was defined.

That is. Possibly the id of the compiler panelAU is as: mainform.panelAU .

Change this code snippet:

<p:ajax listener="#{config.carregaSbcDevices}" update="panelAU"/>

To:

<p:ajax listener="#{config.carregaSbcDevices}" update="mainform.panelAU"/>

If it still does not work. Inspect the generated html and put exactly the id that was generated.

    
21.09.2017 / 17:01