使用p:commandButton jsf提交表单

使用p:commandButton jsf提交表单,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我有一个关于使用p:commandbutton提交表单内容的问题,该按钮倾向于以ajax方式工作 如果我有这样的代码: <f:verbatim rendered="#{myBean.constructor}"></f:verbatim > <h:form prependId="false"> .... ..... <p:commandButton value="#{msg.Add

我有一个关于使用
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中的getconstructor方法(我会更新表单的不同部分)?我如何防止它被调用


我认为提交表单时,只会呈现表单的内容/由
update
参数指定的内容。

它不应该有害。如果你在那里做昂贵的事情,那么你应该把它移动到构造函数,
@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;
}
另见

    • 它不应该有害。如果你在那里做昂贵的事情,那么你应该把它移动到构造函数,
      @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;
      }
      
      另见

      事实上,我看到了你的另一个答案,但我认为也许有一种方法可以只打一次电话。事实上,我看到了你的另一个答案,但我认为可能有一种方法可以只打一次电话。