【问题标题】:CommandButton action doesn't work with custom tagCommandButton 操作不适用于自定义标签
【发布时间】:2012-07-10 15:10:20
【问题描述】:

我创建了以下自定义标签:

<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 的方法!怎么了?

谢谢。

【问题讨论】:

    标签: java jsf jakarta-ee primefaces custom-tags


    【解决方案1】:

    这个答案会对你有所帮助..why command button not getting invoked?

    【讨论】:

      【解决方案2】:

      按钮与代码一起使用:

         ExpressionFactory ef = context.getFacesContext().getCurrentInstance().getApplication().getExpressionFactory();
      MethodExpression me = ef.createMethodExpression(ec, "#{cli.insert}", null, new Class[]{ActionEvent.class});
      MethodExpressionActionListener meal = new MethodExpressionActionListener( me );
      command.addActionListener(meal);
      command.setType( "submit" );
      

      【讨论】:

        【解决方案3】:

        奇怪的是,我遇到了同样的问题,但我使用的是 EL 表达式。我解决了删除标签“type=button”的问题。我知道,没有逻辑,只有移除标签。

        PS:Primefaces 3.4

        【讨论】:

          猜你喜欢
          • 2013-04-15
          • 2012-06-03
          • 1970-01-01
          • 2014-07-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多