1

次のカスタム タグを作成しました。

<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 のメソッドを実行しません! なにが問題ですか?

ありがとう。

4

3 に答える 3

0

この回答は役に立ちます.. なぜコマンドボタンが呼び出されないのですか?

于 2012-07-11T05:09:27.687 に答える
0

ボタンはコードで機能しました:

   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" );
于 2012-07-12T00:50:59.617 に答える
0

不思議なことに、私は同じ問題を抱えていましたが、EL式を使用していました。タグ「type=button」を削除する問題を解決しました。ロジックはありませんが、タグを削除するだけです。

PS: プライムフェイス 3.4

于 2012-12-14T12:44:07.313 に答える