如何使用CommandButton更新我的panelGrid?

时间:2013-09-14 16:02:59

标签: jsf jsf-2 primefaces

我尝试使用更新属性从我的PanelGrid更新我的CommandButton,但它不起作用:

<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”)时,我动态设置了commandButton(“submitDialog”)的actionListener。 正确调用该方法,但panelGrid(“myPanelgrid”)未更新。 当我重新加载页面时,所有组件都正确显示。但对我来说,“submitDialog”的更新属性已正确设置。

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

actionListener

此方法是我将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(“addMemo”)的方法 :

commandButton

我的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)); } (“getLastMemo”)调用我的方法createLastmemo。正确调用MethodExpression,但视图未更新。我在ViewScoped。

0 个答案:

没有答案