Saturday, February 16, 2013

'Hello World!' Program for ADF

There will be an inputtext component, the user will click on Submit button, and then output will be displayed below the button.

A managed bean should be created for each of the inputtext and outputtext components so that we can access the value. This is the code created in the managed bean:

public class test {
    private RichInputText input;
    private RichOutputText output;

    public test() {
    }

    public String cb1_action() {
        // Add event code here...
        String test_input = (String)input.getValue();
        System.out.println("value: "+test_input);
        String value = "Hello " +test_input+ "!!";
        output.setValue(value);
        return null;
    }

    public void setInput(RichInputText input) {
        this.input = input;
    }

    public RichInputText getInput() {
        return input;
    }

    public void setOutput(RichOutputText output) {
        this.output = output;
    }

    public RichOutputText getOutput() {
        return output;
    }
}

Now imagine there was no Submit button, and you have to get the result as soon as you press TAB button after entering a string in the inputtext component. In this case, you have to write a method in valueChangeListener property.

    public void displayValue(ValueChangeEvent valueChangeEvent) {
        // Add event code here...
        String test_input = (String)valueChangeEvent.getNewValue();
        System.out.println("value: "+test_input);
        String value = "Hello " +test_input+ "!!";
        output.setValue(value);
    }
Please note that in this case, don't set any method in attributeChangeListener property. Also set the autoSubmit property of inputText component to be True, and the partialTriggers property of the outputtext component to be the inputText component.

Download the sample application from File Cabinet: HelloWorld.rar

No comments:

Post a Comment