2

我有一个关于提交表单内容的问题,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参数指定的内容..

4

1 回答 1

0

它不应该伤害。如果你在那里做昂贵的东西,那么你应该把它移到有@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;
}

也可以看看

于 2010-08-09T12:09:14.493 回答