Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label layout. Show all posts
Showing posts with label layout. Show all posts

Friday, 3 April 2015

Stretch ADF Faces Components to fit browser width (Show as row-column layout- inline block )

Recently i have seen a thread in OTN about layout of components (How to use components to show a particular layout)
ADF layout for showing email recipients

Requirement was simple, user want to show components up to maximum available width (browser window width) first and then move to next line and show other components
So i thought to document it here :)

Suppose i have to show 6 images on page (horizontally) , so for that i have used 6 group layout
one for each image and button



See xml source-

<af:panelGroupLayout id="pgl1" layout="horizontal">
                    <af:panelGroupLayout id="pgl2" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;">
                        <af:image source="#{resource['images:a_hobbit_house-wallpaper-1280x800.jpg']}"
                                  shortDesc="Hobbit House" id="i1" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b1"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl3" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;">
                        <af:image source="#{resource['images:beach_at_sunset_3-wallpaper-1440x900.jpg']}"
                                  shortDesc="Sunset at Beach" id="i2" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b2"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl4" layout="vertical" halign="center" inlineStyle="padding:2px;">
                        <af:image source="#{resource['images:icelands_ring_road-wide.jpg']}" shortDesc="Ring Road"
                                  id="i3" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b3"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl5" layout="vertical" halign="center" inlineStyle="padding:2px;">
                        <af:image source="#{resource['images:road_to_mount_cook-wallpaper-1280x800.jpg']}"
                                  shortDesc="Road To Mount Cook" id="i4" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b4"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl6" layout="vertical" halign="center" inlineStyle="padding:2px;">
                        <af:image source="#{resource['images:skyscrapers_reflections-wallpaper-1280x800.jpg']}"
                                  shortDesc="Skycrappers " id="i5" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b5"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl7" layout="vertical" halign="center" inlineStyle="padding:2px;">
                        <af:image source="#{resource['images:tufandisli_1387241118_57.jpg']}" shortDesc="Tufan"
                                  id="i6" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b6"/>
                    </af:panelGroupLayout>
                </af:panelGroupLayout>

 and how it looks on page-


You can see here last image is not appearing properly because total width of all images has crossed maximum available width of browser window
Now i want to show last image on next line
So to do this set parent panel group layout to default layout and set display:inline-block for all child panel group layout


<af:panelGroupLayout id="pgl1">
                    <af:panelGroupLayout id="pgl2" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;display:inline-block;">
                        <af:image source="#{resource['images:a_hobbit_house-wallpaper-1280x800.jpg']}"
                                  shortDesc="Hobbit House" id="i1" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b1"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl3" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;display:inline-block;">
                        <af:image source="#{resource['images:beach_at_sunset_3-wallpaper-1440x900.jpg']}"
                                  shortDesc="Sunset at Beach" id="i2" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b2"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl4" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;display:inline-block;">
                        <af:image source="#{resource['images:icelands_ring_road-wide.jpg']}" shortDesc="Ring Road"
                                  id="i3" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b3"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl5" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;display:inline-block;">
                        <af:image source="#{resource['images:road_to_mount_cook-wallpaper-1280x800.jpg']}"
                                  shortDesc="Road To Mount Cook" id="i4" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b4"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl6" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;display:inline-block;">
                        <af:image source="#{resource['images:skyscrapers_reflections-wallpaper-1280x800.jpg']}"
                                  shortDesc="Skycrappers " id="i5" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b5"/>
                    </af:panelGroupLayout>
                    <af:panelGroupLayout id="pgl7" layout="vertical" halign="center"
                                         inlineStyle="padding:2px;display:inline-block;">
                        <af:image source="#{resource['images:tufandisli_1387241118_57.jpg']}" shortDesc="Tufan"
                                  id="i6" inlineStyle="width:250px;height:200px; "/>
                        <af:button text="View" id="b6"/>
                    </af:panelGroupLayout>
                </af:panelGroupLayout>

Now it appears like this -

now again test it by increasing and decreasing browser window width , images and group layout are adjusted as per screen size automatically like a grid view (row and columns)

Thanks , Happy Learning :)
Sample ADF Application- Download

Monday, 5 August 2013

Creating dynamic layout (form and UI Component) using ADF Faces

hello all,
today i had a scenario to create UI Components at run time and i tried to do that on my ADF page.
searched lot in Google and finally all summary is in post.

Suppose you have to create UI Components (input text, buttons, check-boxes etc ) or form (set of multiple UI Components) at runtime - follow these steps

  • Find a parent component to create child under it as any layout (panel form, panel group, af:form etc)
  • Suppose you have a page with a panel form layout, now you have to create child components in this form layout at runtime
  • Bind this form layout to managed bean

  • <af:panelFormLayout id="pfl1" rows="2" binding="#{DynamicCompBean.panelFormLay}"/>
    

  • Now thanks to Mahmoud A. Elsayed for this method, that adds child component to parent component

  •     public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent) {
            parentUIComponent.getChildren().add(childUIComponent);
            AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
        }
    

  • you can call this method , wherever you want to create UI Component and add it to page .



  • Now i have created a button on page and a radio box to select which component should be created
  • Now on button click , i have generated components conditionally based on selection
  • To generate any component - see managed bean code to create input text

  •             RichInputText ui = new RichInputText();
                ui.setId("rit1");
                ui.setLabel("Input text");
                ui.setValue("Hello ADF");
                ui.setContentStyle("font-weight:bold;color:red");
    

  • same as this ,for other component i have written code and set their properties in managed bean
  • look at managed bean code-

  • package dynamic.view.bean;
    
    import java.io.Serializable;
    
    import javax.faces.component.UIComponent;
    import javax.faces.event.ActionEvent;
    
    import oracle.adf.view.rich.component.rich.RichForm;
    import oracle.adf.view.rich.component.rich.input.RichInputText;
    import oracle.adf.view.rich.component.rich.input.RichSelectBooleanCheckbox;
    import oracle.adf.view.rich.component.rich.input.RichSelectOneRadio;
    import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
    import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
    import oracle.adf.view.rich.component.rich.output.RichOutputText;
    import oracle.adf.view.rich.context.AdfFacesContext;
    
    public class DynamicCompBean implements Serializable {
    
        /**Parent component to add childs in it*/
        private RichPanelFormLayout panelFormLay;
    
        /**Binding to select which component should be created*/
        private RichSelectOneRadio compTypeBind;
    
        public DynamicCompBean() {
        }
    
        /**Method to add child to parent component*/
        public void addComponent(UIComponent parentUIComponent, UIComponent childUIComponent) {
            parentUIComponent.getChildren().add(childUIComponent);
            AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
        }
    
        /**Button code to generate and add components conditionally*/
        public void createComptext(ActionEvent actionEvent) {
    
            if (compTypeBind.getValue().toString().equalsIgnoreCase("I")) {
                RichInputText ui = new RichInputText();
                ui.setId("rit1");
                ui.setLabel("Input text");
                ui.setValue("Hello ADF");
                ui.setContentStyle("font-weight:bold;color:red");
                addComponent(getPanelFormLay(), ui);
            } else if (compTypeBind.getValue().toString().equalsIgnoreCase("O")) {
                RichOutputText ui = new RichOutputText();
                ui.setId("rot1");
                ui.setValue("I am output text");
                ui.setInlineStyle("font-weight:bold;color:green");
                addComponent(getPanelFormLay(), ui);
            } else if (compTypeBind.getValue().toString().equalsIgnoreCase("C")) {
                RichSelectBooleanCheckbox ui = new RichSelectBooleanCheckbox();
                ui.setId("ch1");
                ui.setValue(true);
                ui.setLabel("CheckBox");
                addComponent(getPanelFormLay(), ui);
            } else if (compTypeBind.getValue().toString().equalsIgnoreCase("B")) {
                RichCommandButton ui = new RichCommandButton();
                ui.setId("ch1");
                ui.setText("Button");
                ui.setInlineStyle("font-weight:bold;");
                addComponent(getPanelFormLay(), ui);
            }
    
        }
    
    
        public void setPanelFormLay(RichPanelFormLayout panelFormLay) {
            this.panelFormLay = panelFormLay;
        }
    
        public RichPanelFormLayout getPanelFormLay() {
            return panelFormLay;
        }
    
        public void setCompTypeBind(RichSelectOneRadio compTypeBind) {
            this.compTypeBind = compTypeBind;
        }
    
        public RichSelectOneRadio getCompTypeBind() {
            return compTypeBind;
        }
    }
    

  • Now run this application and select input text to create-

  • Select others also and create a form

  • You can create complex forms using this

         Download Sample workspace-Download Sample