1

This is my Sample backing bean.

@ManagedBean
@SessionScoped
public class Sample {

    private String dateText;

    public Sample(){
        dateText = (new Date()).toString();
    }

    public String updateDate(){
        setDateText((new Date()).toString());
        return null;
   }

    public String getDateText() {
        return dateText;
    }

    public void setDateText(String dateText) {
       this.dateText = dateText;
   }

}

Scenario 01

<h:head></h:head>
<h:body>
    <h:form>
       <h:inputText id="txtFirst" value="#{sample.dateText}"/>
       <h:inputText id="txtSecond" value="#{sample.dateText}"/>
       <h:commandButton action="#{sample.updateDate}"/>
    </h:form>
</h:body>

Scenario 02

<h:head></h:head>
<h:body>
    <h:form>
       <h:inputText id="txtFirst" value="#{sample.dateText}"/>
       <p:inputText id="txtSecond" value="#{sample.dateText}"/>
       <h:commandButton action="#{sample.updateDate}"/>
    </h:form>
</h:body>

Scenario 03

<h:head></h:head>
<h:body>
    <h:form>
       <h:inputText id="txtFirst" value="#{sample.dateText}"/>
       <p:inputText id="txtSecond" value="#{sample.dateText}"/>
       <p:commandButton action="#{sample.updateDate}"/>
    </h:form>
</h:body>

Scenario 04

<h:head></h:head>
<h:body>
    <h:form>
       <h:inputText id="txtFirst" value="#{sample.dateText}"/>
       <p:inputText id="txtSecond" value="#{sample.dateText}"/>
       <p:commandButton action="#{sample.updateDate}" update="@form"/>
    </h:form>
</h:body>

When I click on the commandButton,

Scenario 01 : Works fine. I can see new date values from both inputText fields without manually refreshing the page.

Scenario 02 : It refreshes the page. Cannot see any ajax behavior. New values are there.

Scenario 03 : Nothing happens. No refreshes. No value changes. To see the values I have to refresh the page manually.

Scenario 04 : Works like Scenario 01

Please someone give me a little explanation about what is happening here with these components. I have used ICEfaces, but I haven't see anything like this.

Thank you!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sura2k
  • 7,365
  • 13
  • 61
  • 80

1 Answers1

1

IceFaces are able to determine which components should be refreshed when an ajax action is invoked. With standard JSF + Primefaces you don't get such an automation so you have to specify the executed and updated components yourself.

  • I'm ignoring scenarion 1 as the code you provided is the same as in scenario 2
  • Scenario 2 has no ajax at all, so the whole page get submitted
  • Scenario 3 uses default ajax behaviour of p:commandButton which onlt executes the action but does not render other components - thus you only see the changes after a refresh
  • Scenario 4 executes the action using ajax and rendres the entire form - so the changes are visible after the processing is finished

So the behaviour isn't actually "strange" :)

dratewka
  • 2,104
  • 14
  • 15
  • So you are saying that `` components do not work as `` or `` by default? – sura2k Jun 12 '13 at 12:52
  • 2
    No, he is saying that ICEfaces is unaskingly changing the default JSF behavior. It loads an additional JS file which silently turns every standard JSF command component into an ajax enabled component and defaults to `render="@form"`. PrimeFaces doesn't touch the standard JSF command components. See also http://www.icesoft.org/wiki/display/ICE/Disabling+Ajax – BalusC Jun 12 '13 at 12:59
  • You was been told that before, by the way: http://stackoverflow.com/questions/15131582/jsf-file-download-doesnt-work – BalusC Jun 12 '13 at 13:05
  • @BalusC: Yes of course and thank you. I was thinking about a standard, but various libraries use their own ways. I'm still learning JSF and much to be learnt. – sura2k Jun 12 '13 at 17:03