1

i've been dealing with this for a quite some time already. When i choose an item in selectOneMenu i want to update another selectOneMenu with specific values and it is not working.

xhtml:

<p:dialog id="noviTermin_dlg" header="Upisi podatke o terminu" widgetVar="termin_dlg" modal="true"
        height="250" width="500">
        <h:panelGroup id="noviTerminPanel">
            <p:panelGrid columns="2">
                <h:outputText value="Pacijent:" />
                <p:selectOneMenu id="pacijentiList" value="#{termini.selectedPacijent}" 
                    filter="true" filterMatchMode="contains">
                    <p:ajax listener="#{termini.writeSomething}"
                        update="bolestiList" />
                    <f:selectItem itemLabel="Odaberi pacijenta" itemValue="" noSelectionOption="true" />
                    <f:selectItems value="#{termini.pacijenti_list}" var="pacijent"
                        itemLabel="#{pacijent.pacijent_prezime} #{pacijent.pacijent_ime}"
                        itemValue="#{pacijent}" />
                </p:selectOneMenu>
                <h:outputText value="Bolest:" />
               <p:selectOneMenu id="bolestiList" value="#{termini.selectedBolest}"
                    filter="true" filterMatchMode="contains" disabled="#{empty selectedPacijent}">
                    <f:selectItem itemLabel="Odaberi bolest" itemValue="" noSelectionOption="true" />
                    <f:selectItems value="#{termini.bolesti_list}" var="bolest"
                        itemLabel="#{bolest.naziv_bolesti}"
                        itemValue="#{bolest}" />
                </p:selectOneMenu>
                <h:outputText value="Vrijeme pocetka:" />
                <pe:timePicker mode="popup" />
                <h:outputText value="Vrijeme kraja:" />
                <pe:timePicker mode="popup" />
                <f:facet name="footer">
                    <p:commandButton value="Spremi" icon="fa fa-save"
                        process="noviTerminPanel"
                        update="table_termini"
                        oncomplete="PF('termin_dlg').hide();"></p:commandButton>
                </f:facet>
            </p:panelGrid>
        </h:panelGroup>
    </p:dialog>

ManagedBean:

@ManagedBean(name="termini")
@ViewScoped
public class TerminiBean implements Serializable{

    private List<Pacijenti> pacijenti_list;
    private Pacijenti selectedPacijent;
    private List<PovijestBolesti> bolesti_list;
    private PovijestBolesti selectedBolest;
    //+get set

   public void writeSomething() {
    System.out.println("adasd");
}

Converter:

    @FacesConverter(forClass=Pacijenti.class)
public class PacijentiConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
        if(value != null && value.trim().length() > 0) {
            try {
                if (value == null || value.isEmpty()) {
                    return null;
                }

                try {
                    Pacijenti pac = new Pacijenti();
                    for(Pacijenti p : CommonServices.fetchPacijentiFromDB()) {
                        if(value == p.getPacijent_id()) {
                            pac = p;
                        }
                    }
                    return pac;
                } catch (Exception e) {
                    throw new ConverterException(new FacesMessage(value + " is not a valid Warehouse ID"), e);
                }
            } catch(NumberFormatException e) {
                throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
            }
        }
        else {
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {

        if (value == null) {
            return "";
        }

        if (value instanceof Pacijenti) {
            return String.valueOf(((Pacijenti) value).getPacijent_id());
        } else {
            throw new ConverterException(new FacesMessage(value + " is not a valid Warehouse"));
        }
    }
}

In this example i am just trying to write something in console when i click on item in selectOneMenu.

Note: I've only posted code that is relevant to this problem.

JuliusCezarus
  • 53
  • 1
  • 8

1 Answers1

1

After lots of problems with dialogs containing event handling or other overlay components in one single big main form i ended up with the following pattern: Separate forms for separate components. One form per dialog. Dialog embedded in form.

Your event notation looks ok and should IMHO work. In case the event works and the update doesn't: You could also try to update parents instead of input components (for example @form or @parent or noviTerminPanel.

Good Luck.

Gunnar
  • 383
  • 4
  • 18
  • 'God' forms are evil... https://stackoverflow.com/questions/7371903/how-to-use-hform-in-jsf-page-single-form-multiple-forms-nested-forms – Kukeltje May 31 '18 at 12:21
  • @Kukeltje - yes, that's why I've recommended to not use one. Also posting the whole form is the default (unless you're not working with process and/or partial processing), which is bad practice the bigger a JSF application gets. – Gunnar May 31 '18 at 12:52
  • ;-), I should have posted: 'God' forms are _**indeed**_ evil (I was agreeing with you) – Kukeltje May 31 '18 at 12:53
  • Still no success. I tried switching to simple text selectItem values and it works but that's not really what i need... – JuliusCezarus Jun 02 '18 at 09:30
  • Strange. Perhaps you want to test simpler selections to find the problem: Just a plain page with a plain selection, two fix entries, without and with dialog. Or just a javascript "console.log" for "oncomplete" in the p:ajax. Have you checked the javascript console for errors? Javascript may stop working in the page when an error occurs. – Gunnar Jun 04 '18 at 07:03