【问题标题】:submitting form with p:commandButton jsf使用 p:commandButton jsf 提交表单
【发布时间】:2010-08-09 10:01:17
【问题描述】:

我有一个关于使用p:commandbutton 提交表单内容的问题,这往往以 ajax 方式工作。

如果我有这样的代码:

<f:verbatim  rendered="#{myBean.constructor}"></f:verbatim >
 <h:form prependId="false">
          ....            
            .....
<p:commandButton   value="#{msg.Add_Parameter_Set}" update="addParameterSetPnl,msgs"  action="#{myBean.initNewParametersSet}"/>
  </h:form>

使用命令按钮提交表单时,是否会调用 f:verbatim 中的 getContructor 方法(我更新了表单的不同部分)?如何防止它被调用?

我以为提交表单,只会渲染表单的内容/update参数指定的内容..

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    它不应该伤害。如果你在那里做一些昂贵的事情,那么你应该把它移到构造函数,@PostConstruct 或相关 bean 的操作方法,或者引入延迟加载或阶段嗅探。

    // In Constructor..
    public Bean() {
        constructed = getItSomehow();
    }
    
    // ..or @PostConstruct..
    @PostConstruct
    public void init() {
        constructed = getItSomehow();
    }
    
    // ..or action method..
    public String submit() {
        constructed = getItSomehow();
        return "outcome";
    }
    
    // ..or lazy loading..
    public boolean getConstructed() {
        if (constructed == null) constructed = getItSomehow();
        return constructed;
    }
    
    // ..or phase sniffing (this one updates during render response only).
    public boolean getConstructed() {
        if (FacesContext.getCurrentInstance().getRenderResponse()) constructed = getItSomehow();
        return constructed;
    }
    

    另见

    【讨论】:

    • 其实我看到了你的另一个答案,但认为也许有一种方法可以只调用一次。
    猜你喜欢
    • 2012-04-02
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 2018-02-01
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多