Problems using Selectonemenu primefaces

Asked

Viewed 366 times

2

I have a problem to update the data of a Selectonemenu in the primefaces, as suggested by the code below, I have a button that when clicked, brings data of a Webservice and stores in a variable of Devices in back-end and right after, play only their names to the list deviceNames, this is because I print the Size of the list with the names and is OK, it happens that nothing appears in my Selectonemenu. I’ve already made many changes but so far nothing. It seems to be pretty silly but I can’t find the problem.

Page XHTML

<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());
}

2 answers

0

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

That is. Possibly the compontante id panelAU is as: mainform.panelAU.

Change this piece of code:

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

To:

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

If it still doesn’t work. Inspect the generated html and put exactly the id that was generated.

  • Good afternoon, first thanks for the help. I made the change now but with this line changed I get the following error: Cannot find Component with Expression "mainform.panelAU" referenced from "mainform:button1". I made the change to: <p:ajax Listener="#{config.loadSbcDevices}" update="mainform:panelAU"/> Which is how the id of the div appears in html, the page runs but still not updating...

  • Have you inspected the element? How is the select id?

  • I took the html and the id is like 'mainform:Selectone' - this 'Selectone' is the id I just put in the component, and even putting update='mainform:Selectone' does not return anything. I’m doing some tests with only id, or with form id + component id.

  • Do this... Test also put @form. To see if it updates.

  • I put the @form and so far nothing. I also tried with 'mainform:selectOne_panel' because inside the div 'Selectone' there is another with the id 'selectOne_panel' which is created in html and is where the <option>. In this link below you have the generated HTML: http://dontpad.com/htmlstackquestion

  • Try to tag process="@form" in p:ajax

  • I tried with the @form and @parent also, but there were no changes either. I changed the structure and now I have Form, and just below the button and Selectone, no panel. There was no improvement, I’m still trying to check the html but apparently there’s nothing without ID... And it seems that the component undergoes the update but does not make a new get() in the variable, I noticed this using a p:commandRemote, and on his onsuccess I put an Alert. Might have something to do with the JSF or Netbeans version, etc??

  • I just tested tb with <f:ajax instead of <p:ajax to see if it wasn’t a primeface bug or something, I also used <h:selectOneMenu instead of <p:selectOneMenu. Even so the error persisted, seems to me logical error. Strange this are not working.

  • I recreated this page of the first showcase faces: https://www.primefaces.org/showcase/ui/ajax/dropdown.xhtml And the result was this: http://tinypic.com/r/htwoxe/9 - Weird no? I think it might be something on my first face.

  • Weird! which version you’re using?

  • I was in 5.0 and changed to 6.0, the one on the page was an XML error, I changed a parameter and it worked, funny that the showcase page works right here. Now I made a test, with a button I press everything of the webservice and I leave ready, in the other I play for variable of the screen, following the same pattern of the showcase. And the strange thing is that it brings 22 records but when it comes to putting these records in the variable that goes to the screen, it launches an NPE, as if something else zeroes this variable. Tomorrow put more, I’m in evidence week at the facul. But thanks for so far :D

  • I think I found the problem, I separated the method into two parts and two buttons, the first population the variable devices which is the object list, and on the other button, calls the method that brings the names of objects to devicesName. There’s the problem, the variable devices is null at the time of the second call. It seems that the page is as Request Scoped, but in vdd is as Viewscoped... I believe this is it, I just don’t know how to solve, rs.

  • @Ricardo managed to find a solution?

  • I tried several forms of Scopo however, the solution, even if momentary, was to use variaves static, even though it is not the best way. After completing much of the application I will return to this issue. But at the moment this is it, since I have not obtained any other information in documentation. Thank you.

Show 9 more comments

0


Fixed Problem!

After minor daily failed attempts, I noticed that the same code made by other developers did not present error, when searching for solutions in the Packages I was using discovered the error, the Imports of the SessionScoped and of Named (I use this instead of @ManagedBean(name = 'beanName'). Therefore, I solved by making the following changes:

Alias of the Bean:

@Named(value = "beanAgregadorDetalhe")

And the import thereof:

import javax.inject.Named;

Session Scope:

@SessionScoped

And the import thereof:

import javax.enterprise.context.SessionScoped;

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.