0

I have started learning JSF. I understand from oracle fourm like

when the command button has immediate attribute then all its actions, conversions and validations will happen in ApplyRequestPhase for the button.

When a input has immediate attribute then similarly conversion , validation and all things will be happen in ApplyRequest phase for that input.

But my question is like Both command button and an input text has immediate attribute then can i get the value of input text in the ApplyRequest phase when i click the button?

If it is no then why this behavior for inputs ? If it is yes then that is not working in my sample.

   <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    JSF Immediate Sample
</h:head>
<h:body>
    <h:form>
    <h:messages globalOnly="true" showDetail="true" showSummary="true"/>
        <h:panelGrid border="2" columns="2">
        <h:outputText value="Enter Data (Str - Boo)" />
        <h:inputText value="#{classicBean.propBoolean}" immediate="true"/>
        <h:outputText value="Enter Data" />
        <h:inputText value="#{classicBean.propString2}" />
        <h:outputText value="Enter Data (Immediate)" />
        <h:inputText value="#{classicBean.propString3}" immediate="true"/>


        <h:commandButton value="ImmediateButton" action="#{classicBean.testMethod}" immediate="true" />
        <h:commandButton value="CommandButton"  action="#{classicBean.testMethod}" />
        </h:panelGrid>
    </h:form>
</h:body>
</html>



public class ClassicManagedBean {

    private boolean propBoolean;
    private String propString;
    private String propString2;
    private String propString3;
    private String propString4;
    private Integer propInteger;


    public String testMethod() {
        System.out.println("Inside TestMetod......");
        System.out.println("Property Boolean :"+propBoolean);
        System.out.println("Property String2 :"+propString2);
        System.out.println("Property String3 :"+propString3);
        return null;
    }
}

Log

  • Coming to RESTORE_VIEW 1 beforePhase
  • Coming to RESTORE_VIEW 1 afterPhase
  • Coming to APPLY_REQUEST_VALUES 2 beforePhase
  • Inside TestMetod......
  • Property Boolean :false
  • Property String2 :null
  • Property String3 :null
  • Coming to APPLY_REQUEST_VALUES 2 afterPhase
  • Coming to RENDER_RESPONSE 6 beforePhase
  • Coming to RENDER_RESPONSE 6 afterPhase

Screenshot & input

Thanks Manivannan

Mani
  • 81
  • 10
  • If you want to retreive the value of the input fields, you have to submit them via ajax. You are not submitting your entire form when using immediate on your command button, you simply execute the button, without submitting any input. You are simply skipping validation. – kevcodez Nov 02 '15 at 09:38
  • Hi.. Thanks for your reply. But i dont understand why we need to submit them via ajax. Anyhow both input field and button has same immediate attribute. It is to perform all the processing in the ApplyRequest phase isn't it..? – Mani Nov 03 '15 at 07:08
  • http://stackoverflow.com/questions/12960718/trying-to-understand-immediate-true-skipping-validation-when-it-shouldnt – kevcodez Nov 03 '15 at 08:16

0 Answers0