0

I have problem with setting default value of <p:selectOneRadio>. I've read some related topics, but I was not able to find an answer to my problem. There it is how it works now:

  1. I've set value in my backing bean (has session scope) after click on <p:commandButton>, using showLogEntryClassificationDlg().

    <p:commandButton value="#{text['button.add']}" id="treeAdd"    
        styleClass="btn btn-primary" icon="fa fa-plus"
        actionListener="#{eventLogDetails.showLogEntryClassificationDlg()}"
        update=":logEntryClassificationDialogForm"
        oncomplete="PF('dlgLogEntryClassification').show(); return false;" />
    

    java

    public void showLogEntryClassificationDlg(){
        mode = MODE.ADD;
        logEntryClassification = new LogEntryClassification();
        logEntryClassification.setLogEntryType(LogEntryType.LOG_ENTRY_CATEGORY);
        //some other code
    }
    
  2. Dialog is shown, but value in radio button is not selected. I've checked getter in backing bean and it returns correct value (but it is called few times). Radio button becomes selected when I cilck anywhere(!) on the dialog (no getter called though).

    (almost) full xhtml file:

    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:o="http://omnifaces.org/ui">
    
        <ui:composition template="/layouts/default.xhtml">
        <ui:define name="title">#{text['eventLogDetail.title']}</ui:define>
        <ui:param name="menu" value="EventLogMenu" />
    
        <ui:define name="body">
            <h:outputScript name="jsf.js" library="javax.faces" target="head" />
    
            <h:form id="eventLogDetailsForm">
    
                //some code
    
                <div class="row">
                    <div class="col-md-12">
                        <div class="portlet">
                            <h4 class="portlet-title">
                                <u><i class="fa fa-sitemap"> </i>
                                    #{text['eventLogDetail.heading.classification']}</u>
                            </h4>
                            <div class="portlet-body">
                                <div class="row dt-rt">
                                    <div class="col-sm-12">
                                        <p:panel id="treeButtonPanel" styleClass="no-style-panel">
                                            <div class="btn-group">
    
                                                <p:commandButton value="#{text['button.add']}" id="treeAdd"
                                                    styleClass="btn btn-primary" icon="fa fa-plus"
                                                    actionListener="#{eventLogDetails.showLogEntryClassificationDlg}"
                                                    update=":logEntryClassificationDialogForm, :logEntryClassificationDialogForm:logEntryTypeRadioPanel"
                                                    oncomplete="PF('dlgLogEntryClassification').show(); return false;" />
    
                                                //other commandButtons
    
                                            </div>
                                        </p:panel>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </h:form>
    
        <!-- dialogs -->
            <p:dialog
                header="#{text['logEntry.logEntryClassification.add.title']}"
                widgetVar="dlgLogEntryClassification" appendTo="@(body)" modal="true"
                dynamic="true" height="300" resizable="false"
                styleClass="custom-popup-xs" id="logEntryClassificationDialog">
    
                <h:form id="logEntryClassificationDialogForm">
                    <o:resourceInclude path="/common/messages.jsp" />
    
                    <div class="row">
                        <div class="col-sm-12 form-group">
                        <p:panel id="logEntryTypeRadioPanel" styleClass="no-style-panel">
                            <p:selectOneRadio id="logEntryTypeRadio"
                                value="#{eventLogDetails.logEntryClassification.logEntryType}"
                                converter="LogEntryTypeConverter">
                                <f:selectItem itemLabel="Kategoria zdarzeń"
                                    itemValue="LOG_ENTRY_CATEGORY" />
                                <f:selectItem itemLabel="Rodzaj zdarzenia"
                                    itemValue="LOG_ENTRY_TYPE" />
                            </p:selectOneRadio>
                            </p:panel>
                        </div>
                    </div>
    
                //some code
    
                </h:form>
            </p:dialog>
    
        </ui:define>
        </ui:composition>
    </html>
    

I've put <p:selectOneRadio> inside <p:panel> and tried to update :logEntryClassificationDialogForm:logEntryTypeRadioPanel, but result was the same.

EDIT: I've tested something and maybe this it is some kind of primefaces bug: it is not working only when I try to set that the first item is selected. The item is selected after I've added one more item at the beginning (shown below). Any thoughts?

<f:selectItem itemLabel="Rodzaj zdarzenia" itemValue="LOG_ENTRY_TYPE" />
<f:selectItem itemLabel="Kategoria zdarzeń" itemValue="LOG_ENTRY_CATEGORY" />
<f:selectItem itemLabel="Rodzaj zdarzenia" itemValue="LOG_ENTRY_TYPE" />

It works with <h:selectOneRadio>, but i need to use <f:selectOneRadio>

dodo
  • 31
  • 6

1 Answers1

0

It seems that it is primefaces bug. When <p:selectOneRadio> isn't first element on the form it works. But even when it is not first element when you focus on it (using tab key) it loses item selection. If you press tab once again selection is back. For now, before <p:selectOneRadio> I've added <p:focus for=someId> where someId is inputText (second element in <p:dialog>)

dodo
  • 31
  • 6