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());
}
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...
– Ricardo
Have you inspected the element? How is the select id?
– karanalpe
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.
– Ricardo
Do this... Test also put @form. To see if it updates.
– karanalpe
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– Ricardo
Try to tag process="@form" in p:ajax
– karanalpe
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??– Ricardo
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.
– Ricardo
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.
– Ricardo
Weird! which version you’re using?
– karanalpe
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
– Ricardo
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 todevicesName
. There’s the problem, the variabledevices
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
@Ricardo managed to find a solution?
– karanalpe
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.– Ricardo