views:

190

answers:

1

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

A: 

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

BalusC
actually I saw your other answer, but thought that maybe there is a way to make called only once.
Odelya
No problem, you're welcome.
BalusC