我创建了以下自定义标签:
<h:form>
<d:formBuilder/>
</h:form>
标签呈现没有这样的问题:
标记代码:
public class FormBuilder extends TagHandler {
public FormBuilder(TagConfig config) {
super(config);
}
public void apply(FaceletContext context, UIComponent parent) throws IOException {
CommandButton command = (CommandButton) context.getFacesContext().getCurrentInstance().getApplication().createComponent( CommandButton.COMPONENT_TYPE);
command.setValue("Click");
command.setAjax(false);
MethodExpression me = context.getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{cli.insert}", null, new Class<?>[0]);
command.setActionExpression(me);
InputText it = (InputText) context.getFacesContext().getCurrentInstance().getApplication().createComponent(InputText.COMPONENT_TYPE);
ValueExpression ve1 = context.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{cli.name}", String.class);
it.setValueExpression("value", ve1);
parent.getChildren().clear();
parent.getChildren().add(it);
parent.getChildren().add(command);
}
}
托管bean:
@SessionScoped
@ManagedBean(name = "cli")
public class ClienteController {
private String name = "aa";
public String insert() {
name = "test";
return "clientes";
}
}
inputText 工作正常,但 commandButton 没有执行 managedBean 的方法!怎么了?
谢谢。