我可以设置面板的位置然后对其进行更新,但是在获取其当前位置时遇到了麻烦。
例如:目前,我的面板位于 (50, 50)。
 <h:form id="testForm">
        <p:panel id="pane" style="position: absolute; left:50px; top:50px;">
            <p:panelGrid columns=4>
                <p:outputPanel id="ASlot3" styleClass="slot"/>  
                <p:outputPanel id="ASlot4" styleClass="slot"/>  
                <p:outputPanel id="ASlot5" styleClass="slot"/>  
                <p:outputPanel id="ASlot6" styleClass="slot"/>  
            </p:panelGrid>
        </p:panel>
        <p:draggable id="drg" for="pane"/>
        <p:commandButton id="press" action="#{sbean.press}"/>
    </h:form>
我通过拖动面板来更新它的位置。拖动它后,我按下一个按钮,按住此方法打印“样式”的内容。
    //press() method
    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    UIComponent component = viewRoot.findComponent("testForm").findComponent("pane");
    Panel p = (Panel) component;
    System.out.println(p.getAttributes().get("style"));
拖动面板并按下按钮后,“样式”不会更新。
那么如何在拖动后获取面板的当前位置?
编辑:顺便说一句,我使用的范围是@ViewScoped