【问题标题】:Preset value of <p:selectOneRadio> inside <p:dialog><p:dialog> 内 <p:selectOneRadio> 的预设值
【发布时间】:2014-09-16 08:56:24
【问题描述】:

我在设置默认值&lt;p:selectOneRadio&gt; 时遇到问题。我已经阅读了一些相关主题,但我无法找到我的问题的答案。这就是它现在的工作方式:

  1. 在单击&lt;p:commandButton&gt; 后,我使用 showLogEntryClassificationDlg() 在我的支持 bean(具有会话范围)中设置了值。

    <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. 显示对话框,但未选择单选按钮中的值。我已经检查了支持 bean 中的 getter,它返回了正确的值(但它被调用了几次)。当我在对话框上的任何地方(!) cilck 时,单选按钮被选中(虽然没有调用 getter)。

    (几乎)完整的 xhtml 文件:

    <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>
    

我已将&lt;p:selectOneRadio&gt; 放入&lt;p:panel&gt; 并尝试更新:logEntryClassificationDialogForm:logEntryTypeRadioPanel,但结果相同。

编辑: 我已经测试了一些东西,也许这是某种 primefaces 错误: 仅当我尝试设置选择第一项时它才起作用。在我在开头添加了一个项目之后选择了该项目(如下所示)。有什么想法吗?

<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" />

它适用于&lt;h:selectOneRadio&gt;,但我需要使用&lt;f:selectOneRadio&gt;

【问题讨论】:

    标签: jsf primefaces dialog selectoneradio


    【解决方案1】:

    似乎是primefaces错误。当&lt;p:selectOneRadio&gt; 不是表单上的第一个元素时,它会起作用。但即使当你关注它时它不是第一个元素(使用 tab 键)它也会丢失项目选择。如果您再次按 Tab 键,则选择返回。现在,在&lt;p:selectOneRadio&gt; 之前,我添加了&lt;p:focus for=someId&gt;,其中someId 是inputText(&lt;p:dialog&gt; 中的第二个元素)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多