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") をクリックすると、("submitDialog") の actionListener を動的に設定しますcommandButton
。メソッドは適切に呼び出されますが、panelGrid
("myPanelgrid") は更新されません。ページをリロードすると、すべてのコンポーネントが正しく表示されます。しかし、私にとっては、「submitDialog」の更新属性が正しく設定されています。
panels
動的に追加する私のメソッドは、最初のpostConstruct
メソッドで呼び出され (コンポーネントは正しく表示されます)、2 つ目は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にいます。