1

我尝试使用 update 属性更新我PanelGridCommandButton,但它不起作用:

<h:body>
    <p:dialog id="dialog" header="Add Memo" widgetVar="dialogMemo" resizable="false" >
        <h:form id="formDialog">
            <h:panelGrid columns="2" cellpadding="5">  
                <h:outputLabel for="commentInput" value="Comment:" />  
                <p:inputTextarea id="commentInput" value="#{dashboardBean.currentComment}" rows="6" cols="25" label="commentInput" required="true"/>
                <p:watermark for="commentInput" value="Enter your memo..."/>  
                <h:outputLabel for="selectShare" value="Share Memo: " />  
                <p:selectBooleanCheckbox id="selectShare" /> 

                <h:outputLabel for="choosePriority" value="Priority:" />  
                <p:selectOneMenu id="choosePriority" value="#{dashboardBean.currentPriority}" label="choosePriority">  
                    <f:selectItem itemLabel="Low Priority" itemValue="1" />  
                    <f:selectItem itemLabel="Medium Priority" itemValue="2" />  
                    <f:selectItem itemLabel="High Priority" itemValue="3" />  
                </p:selectOneMenu>

                <p:commandButton id="submitDialog" icon="ui-icon-check" value="Confirm" update=":formPanel:myPanelGrid" oncomplete="dialogMemo.hide();"  type="submit">

                </p:commandButton>
                <p:commandButton icon="ui-icon-close" onclick="dialogMemo.hide();" value="Cancel"/>
            </h:panelGrid>
        </h:form>
    </p:dialog>
    <p:layout fullPage="true">
        <p:layoutUnit id="leftPanel" position="west" size="250" header="My Memos" resizable="false" closable="false" collapsible="false">
            <h:form id="formPanel">
                <p:commandButton id="addMemo" icon="ui-icon-plus" onclick="dialogMemo.show();"  type="submit" actionListener="#{dashboardBean.getEditControl}"/>  
                <h:panelGrid id="myPanelGrid" columns="1" width="100%" >

                </h:panelGrid>
            </h:form>
        </p:layoutUnit>          
</h:body>

commandButton当我点击(“addMemo”)时,我动态设置了我的(“submitDialog”)的commandButtonactionListener。该方法已正确调用,但panelGrid("myPanelgrid") 未更新。当我重新加载页面时,所有组件都会正确显示。但对我来说,“submitDialog”的更新属性设置正确。

panels动态添加的方法,第一个在postConstruct方法中调用(组件显示正确),第二个在commandButton(“SubmitDialog”)中调用actionListener(Panelgrid 未更新):

public void createMemoList()
{
    if (panelGridUI != null && _countMemos > 0)
    {
        for (int i = 0; _countMemos > i; i++)
        {
            int u = _memosId.get(i);

            Panel panel = (Panel)_application.createComponent(FacesContext.getCurrentInstance(), "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
            MethodExpression editExpression = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleEdit}", Void.class, new Class[]{ActionEvent.class});
            MethodExpression me = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleClose}", null, new Class[]{AjaxBehaviorEvent.class});
            AjaxBehavior ajaxBehavior = new AjaxBehavior();   
            Draggable draggable = new Draggable();

            panel.setId("mymemo_" + String.valueOf(u));
            panel.setHeader(_userNames.get(i));
            panel.setClosable(true);
            panel.setToggleable(true);

            HtmlOutputText memo = new HtmlOutputText();
            memo.setValue(_userMemos.get(i));
            memo.setId("text_" + String.valueOf(u));
            panel.getChildren().add(memo);

            HtmlPanelGroup panelGroup = new HtmlPanelGroup();
            panelGroup.setId("group_" + u);

            CommandButton button = new CommandButton();
            button.setIcon("ui-icon-pencil");
            button.addActionListener(new MethodExpressionActionListener(editExpression));
            button.setOnclick("dialogMemo.show()");
            button.setStyle("width:20px;height:20px;margin-right:5px;");

            HtmlOutputText header = new HtmlOutputText();
            header.setValue(_userNames.get(i));
            header.setStyle("font-size:15px;");

            panelGroup.getChildren().add(button);
            panelGroup.getChildren().add(header);

            panel.getFacets().put("header", panelGroup);
            ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));       
            panel.addClientBehavior("close", ajaxBehavior);

            draggable.setFor("mymemo_" + String.valueOf(u));
            draggable.setRevert(true);
            draggable.setHandle(".ui-panel-titlebar");
            draggable.setStack(".ui-panel");

            getPanelGrid().getChildren().add(panel);
            getPanelGrid().getChildren().add(draggable);
        }
    }
}

public void createLastMemo()
{
    if (panelGridUI != null && _countMemos > 0)
    {
        int u = _memosId.get(_countMemos - 1);

        Panel panel = (Panel)_application.createComponent(FacesContext.getCurrentInstance(), "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
        MethodExpression editExpression = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleEdit}", Void.class, new Class[]{ActionEvent.class});
        MethodExpression me = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleClose}", null, new Class[]{AjaxBehaviorEvent.class});
        AjaxBehavior ajaxBehavior = new AjaxBehavior();
        Draggable draggable = new Draggable();

        panel.setId("mymemo_" + String.valueOf(u));
        panel.setHeader(_userNames.get(_countMemos - 1));
        panel.setClosable(true);
        panel.setToggleable(true);

        HtmlOutputText memo = new HtmlOutputText();
        memo.setValue(_userMemos.get(_countMemos - 1));
        memo.setId("text_" + String.valueOf(u));
        panel.getChildren().add(memo);

        HtmlPanelGroup panelGroup = new HtmlPanelGroup();
        panelGroup.setId("group_" + String.valueOf(u));

        CommandButton button = new CommandButton();
        button.setIcon("ui-icon-pencil");
        button.addActionListener(new MethodExpressionActionListener(editExpression));
        button.setOnclick("dialogMemo.show()");
        button.setStyle("width:20px;height:20px;margin-right:5px;");

        HtmlOutputText header = new HtmlOutputText();
        header.setValue(_userNames.get(_countMemos - 1));
        header.setStyle("font-size:15px;");

        panelGroup.getChildren().add(button);
        panelGroup.getChildren().add(header);

        panel.getFacets().put("header", panelGroup);

        ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));       
        panel.addClientBehavior("close", ajaxBehavior);

        draggable.setFor("mymemo_" + String.valueOf(u));
        draggable.setRevert(true);
        draggable.setHandle(".ui-panel-titlebar");
        draggable.setStack(".ui-panel");

        getPanelGrid().getChildren().add(panel);
        getPanelGrid().getChildren().add(draggable);
    }
}

这个方法是我设置actionListener为 my commandButton("addMemo") 的地方:

public void getEditControl()
{
    System.out.println("I am in getEditContol!!!");
    UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
    CommandButton button = (CommandButton) view.findComponent("formDialog:submitDialog");

    for(ActionListener act : button.getActionListeners()) {
        button.removeActionListener(act);
    }

    MethodExpression getLastmemo = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{dashboardBean.getLastMemo}", Void.class, new Class[]{ActionEvent.class});
    button.addActionListener(new MethodExpressionActionListener(getLastmemo));
}

我的MethodExpression(“getLastMemo”)调用我的方法 createLastmemo。ActionListener被正确调用,但视图没有更新。我在 ViewScoped 中。

4

0 回答 0