开发者

submitting form with p:commandButton jsf

I have a question regarding submitting form content with p:commandbutton that tends to work in the ajax way.

If I have a code like this:

<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>

When submitting the form with the command button, will the method getContructor from f:verbatim be called (I update different parts of the form)? How can I prevent it from being called?

I thought that submitting a form, only renders the content of the form / the content that was specified by update parameter..


It shouldn't harm. If you're doing expensive stuff in there, then you should move that to the constructor, @PostConstruct or action method of the bean in question, or introduce lazy loading or phase sniffing.

// 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;
}

See also

  • Why JSF calls getters multiple times?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜