【发布时间】:2013-12-06 06:32:27
【问题描述】:
我在 backing bean 处创建了 jsf 表单。我已经创建了表单,它正在屏幕上成功显示值。当我单击 sumbit 按钮时,使用 ActionEvent 调用支持 bean 方法,但更新的输入值不会提交到后端。 Backign bean 实体对象值未更新。
有什么不对吗?非常感谢您的帮助,
兄弟。 斋月
HtmlForm form = new HtmlForm();
form.setId(appletWrapper.getName()+"_FORM");
PanelGrid panelGrid = (PanelGrid)createComponent(PanelGrid.COMPONENT_TYPE);
form.getChildren().add(panelGrid);
panelGrid.setColumns(4);
panelGrid.setId(appletWrapper.getName()+"_FORM_PANEL");
for (FieldWrapper fieldWrapper : appletWrapper.getFields()) {
panelGrid.getChildren().add(new UIFieldLabel(fieldWrapper).component(entities));
panelGrid.getChildren().add(newFieldComponent(fieldWrapper, entities));
}
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.setId(appletWrapper.getName()+"_PANEL_GROUP");
panelGrid.getFacets().put("footer", panelGroup);
CommandButton commandButton = new CommandButton();
panelGroup.getChildren().add(commandButton);
commandButton.setId(appletWrapper.getName()+"_UPDATE");
commandButton.setAjax(true);
commandButton.setValue("update");
commandButton.setProcess("@this");
commandButton.setType("submit");
MethodExpression updateEntityME = createMethodExpression("#{mainBean.entityUpdateListener}", null, new Class[] {ActionEvent.class });
commandButton.addActionListener(new MethodExpressionActionListener(updateEntityME));
return form;
已编辑:我给所有组件一个固定的 id。
我的一个组件是这样生成的;
InputText inputText = (InputText)createComponent(InputText.COMPONENT_TYPE);
inputText.setId(fieldAlphanumericWrapper.getName());
inputText.setValueExpression("value", createValueExpression("#{mainBean.selection."+fieldAlphanumericWrapper.getProperty()+"}", Object.class));
return inputText;
我的后台bean目标方法;
public void entityUpdateListener(ActionEvent actionEvent) {
TAccount tAccount = (TAccount)getSelection();
System.out.println("tAccount.gettWebsite():"+tAccount.gettWebsite());
}
主要问题实际上是;当我按下 commandButton 时 mainBean.setSelection 没有被调用,所以支持 bean 对象没有更新。我无法通过 actionEvent 实例获取更新的对象实例。
【问题讨论】:
-
给所有表单、输入和按钮一个固定的 ID,而不是让 JSF 自动生成它。
-
感谢 BalusC 的建议,我提供了固定的 ID,但情况仍然相同。
标签: jsf commandbutton commandlink