【问题标题】:Primefaces autocomplete menu opens in the wrong spotPrimefaces 自动完成菜单在错误的位置打开
【发布时间】:2014-03-07 07:57:09
【问题描述】:

我有一些详细信息的对话框。打开对话框时,信息显示为不可编辑的标签。用户可以打开可编辑网格按下按钮,将渲染参数更改为 panelGrid,noneditabile 设置为 flase,editabile 设置为 true。

在可编辑网格中,我有自动完成组件,该组件的菜单显示在错误的位置。自动完成菜单的左侧和顶部属性是相对于正文设置的,而不是相对于对话框设置的(例如对话框的左上角位于 0,0 上)。仅当我第一次打开对话框时才会发生这种情况,如果我关闭它并再次打开,则菜单会在文本框字段下方正确打开。

<p:dialog ... appendTo="@(body)">
  <h:form>  
    <p:outputPanel id="opX">
      <p:panelGrid rendered="#{x}" > 
        // non editabile content
      </p:panelGrid>

      <p:panelGrid rendered="#{!x}" >
        // editabile content
        ... 
        <p:autoComplete value="#{xBean.acValue}"  completeMethod="#{xBean.acMenu}" />              
        ...
      </p:panelGrid>
    </p:outputPanel>
    <p:commandButton action="#{x=!x;}" process="@this" update="opX" />
  </h:form>
</p:dialog>

知道为什么会这样吗? 此外,我在自动完成方面遇到了麻烦,它在之后呈现时(或在某些更改后更新)中有列。 我得到错误:

itemLabel="#{sifra.value}":在类型上找不到属性“值” java.lang.String

<p:autoComplete value="#{xBean.acValue}" completeMethod="#{xBean.acMenu}" var="sifra" itemValue="#{sifra.value}" itemLabel="#{sifra.value}" >
  <p:column><b>#{sifra.value}</b></p:column>
  <p:column>#{sifra.name}</p:column>
</p:autoComplete>

 public List<GeneralListDto> acMenu(String inputValue) {
   try {
     GeneralListDto x = calling sme web service;
     return x;
   } 
   catch(Exception e){
     ...
   }
  }

public class GeneralListDto {

public GeneralListDto(){

}

public GeneralListDto(String n, String v, String d){
    this.name = n;
    this.value = v;
    this.description = d;
}

private String value;
private String name;
private String description;

getter and setters
    ....

}

【问题讨论】:

    标签: primefaces menu autocomplete dialog position


    【解决方案1】:

    很遗憾,我无法重现您的问题,但这里有一些提示:

    • 尝试将表单放在对话框之外
         <h:form id="dialogForm">  
            <p:dialog widgetVar="dlgWV" appendToBody="true">
            </p:dialog>
         </h:form>
    
    • 尝试在打开对话框之前更新表单,这样可能会“重新计算位置”
        <p:commandButton update=":dialogForm" oncomplete="dlgWV.open()" />
    
    • 至于itemLabel="#{sifra.value}": Property 'value' not found on type java.lang.String。 您需要为sifra 对象实现转换器。

    • 有时如果您在自动完成建议面板中的结果过多,您可能会遇到视图问题,例如位置和一些不可见的项目,在这种情况下您有两种解决方案,CSS 或overrride the position of the panel


    CSS

       .ui-autocomplete-panel {
           max-width: 400px;
           z-index: 2012;
           overflow:auto;
           height: 200px;
        }
    

    JS

    PrimeFaces.widget.AutoComplete.prototype.alignPanel = function() {
        var fixedPosition = this.panel.css('position') == 'fixed',
        win = $(window),
        positionOffset = fixedPosition ? '-' + win.scrollLeft() + ' -' + win.scrollTop() : null,
        panelWidth = null;
    
        if(this.cfg.multiple) {
            panelWidth = this.multiItemContainer.innerWidth() - (this.input.position().left - this.multiItemContainer.position().left);
        }
        else {
            panelWidth = this.input.innerWidth();
        }
    
        this.panel.css({
                        left:'',
                        top:'',
                        width: panelWidth
                })
                .position({
                    my: 'left top'
                    ,at: 'left bottom'
                    ,of: this.input
                    ,collision: 'none',
                    offset : positionOffset
                });
    }
    

    希望这会有所帮助。

    【讨论】:

    • 感谢您的快速响应。表单和对话框顺序的变化似乎解决了自动完成菜单位置的问题(对话框现在在表单中)。
    • 关于自动完成的另一件事。我将尝试为自动完成实现转换器(当我研究它时),但自动完成可以很好地处理上面示例中的列,只要它没有使用其他一些控件进行更新。因此,如果它是在页面上加载的独立组件,它可以正常工作,但是如果我需要刷新列表依赖于其他一些组件或稍后使用 ajax 加载它,那么我会收到错误。
    • 在我看来,这是因为值被提交(同时被更新和处理)而没有转换对象,这就是为什么转换器的 getAsObject 在这里很重要..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 2014-03-31
    • 2018-08-05
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    相关资源
    最近更新 更多