SelectManyChoice with Typing Capability in InputText Field in ADF.
Hi All,
Today I am going to show how you can create a component like SelectmanyChoice with capability of typing the text field.
As you might be knowing if we use default SelectManyChoice component from ADF Faces Component Palette then it will behave like the dropdown and when you will select the checkbox then it will show the selected value in text separated by semicolon. But in this case you cannot type the text.
Scenario: Some days ago I got the requirement that the user should be able to type the value as well as select also from dropdown list in SelectManyChoice component.
The default SelectManyChoice will look like this.
So what I did is I have kept one InputText and SelectManyChoice component side by side and made the content width of SelectManyChoice as 0px.
But here one problem arises like there was some space coming in between of the input text and SelectManyChoice component as shown like below. So it was not looking good at all like default SelectManyChoice.
Upto this point my jspx code was like this:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:panelGroupLayout id="pgl4" layout="vertical">
<af:panelGroupLayout id="pgl1" layout="horizontal">
<af:inputText id="it1" label="Label 1"/>
<af:selectManyChoice label="Label 2" id="smc3" simple="true"
contentStyle="width:0px;">
<af:selectItem label="India" value="IN" id="si5"/>
<af:selectItem label="America" value="US" id="si6"/>
<af:selectItem label="China" value="CH" id="si1"/>
<af:selectItem label="Australia" value="AUS" id="si2"/>
</af:selectManyChoice>
</af:panelGroupLayout>
<af:spacer width="10" height="20" id="s1"/>
<af:selectManyChoice label="Label 2" id="smc4">
<af:selectItem label="India" value="IN" id="si3"/>
<af:selectItem label="America" value="US" id="si4"/>
<af:selectItem label="China" value="CH" id="si8"/>
<af:selectItem label="Australia" value="AUS" id="si7"/>
</af:selectManyChoice>
</af:panelGroupLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
So I have applied some CSS property to make it look like SelectManyChoice component. Please pardon me if you find any mistake in the CSS because I am not a CSS expert.
So after applying CSS in my code in jspx page I am able to make it look like default SelectManyChoice with input capability.
So now my code is changed like this:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:panelGroupLayout id="pgl4" layout="vertical">
<af:panelGroupLayout id="pgl1" layout="horizontal">
<af:inputText id="it1" label="Label 1"
inlineStyle="position:relative; z-index:2;"/>
<af:selectManyChoice label="Label 2" id="smc3" simple="true"
contentStyle="width:0px;"
inlineStyle="position:relative; z-index:1; margin-left:-10px;">
<af:selectItem label="India" value="IN" id="si5"/>
<af:selectItem label="America" value="US" id="si6"/>
<af:selectItem label="China" value="CH" id="si1"/>
<af:selectItem label="Australia" value="AUS" id="si2"/>
</af:selectManyChoice>
</af:panelGroupLayout>
<af:spacer width="10" height="20" id="s1"/>
<af:selectManyChoice label="Label 2" id="smc4">
<af:selectItem label="India" value="IN" id="si3"/>
<af:selectItem label="America" value="US" id="si4"/>
<af:selectItem label="China" value="CH" id="si8"/>
<af:selectItem label="Australia" value="AUS" id="si7"/>
</af:selectManyChoice>
</af:panelGroupLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
After running the page I can see that both the component are looking alike as shown below.
Happy Coding :)
Today I am going to show how you can create a component like SelectmanyChoice with capability of typing the text field.
As you might be knowing if we use default SelectManyChoice component from ADF Faces Component Palette then it will behave like the dropdown and when you will select the checkbox then it will show the selected value in text separated by semicolon. But in this case you cannot type the text.
Scenario: Some days ago I got the requirement that the user should be able to type the value as well as select also from dropdown list in SelectManyChoice component.
The default SelectManyChoice will look like this.
So what I did is I have kept one InputText and SelectManyChoice component side by side and made the content width of SelectManyChoice as 0px.
But here one problem arises like there was some space coming in between of the input text and SelectManyChoice component as shown like below. So it was not looking good at all like default SelectManyChoice.
Upto this point my jspx code was like this:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:panelGroupLayout id="pgl4" layout="vertical">
<af:panelGroupLayout id="pgl1" layout="horizontal">
<af:inputText id="it1" label="Label 1"/>
<af:selectManyChoice label="Label 2" id="smc3" simple="true"
contentStyle="width:0px;">
<af:selectItem label="India" value="IN" id="si5"/>
<af:selectItem label="America" value="US" id="si6"/>
<af:selectItem label="China" value="CH" id="si1"/>
<af:selectItem label="Australia" value="AUS" id="si2"/>
</af:selectManyChoice>
</af:panelGroupLayout>
<af:spacer width="10" height="20" id="s1"/>
<af:selectManyChoice label="Label 2" id="smc4">
<af:selectItem label="India" value="IN" id="si3"/>
<af:selectItem label="America" value="US" id="si4"/>
<af:selectItem label="China" value="CH" id="si8"/>
<af:selectItem label="Australia" value="AUS" id="si7"/>
</af:selectManyChoice>
</af:panelGroupLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
So I have applied some CSS property to make it look like SelectManyChoice component. Please pardon me if you find any mistake in the CSS because I am not a CSS expert.
So after applying CSS in my code in jspx page I am able to make it look like default SelectManyChoice with input capability.
So now my code is changed like this:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:panelGroupLayout id="pgl4" layout="vertical">
<af:panelGroupLayout id="pgl1" layout="horizontal">
<af:inputText id="it1" label="Label 1"
inlineStyle="position:relative; z-index:2;"/>
<af:selectManyChoice label="Label 2" id="smc3" simple="true"
contentStyle="width:0px;"
inlineStyle="position:relative; z-index:1; margin-left:-10px;">
<af:selectItem label="India" value="IN" id="si5"/>
<af:selectItem label="America" value="US" id="si6"/>
<af:selectItem label="China" value="CH" id="si1"/>
<af:selectItem label="Australia" value="AUS" id="si2"/>
</af:selectManyChoice>
</af:panelGroupLayout>
<af:spacer width="10" height="20" id="s1"/>
<af:selectManyChoice label="Label 2" id="smc4">
<af:selectItem label="India" value="IN" id="si3"/>
<af:selectItem label="America" value="US" id="si4"/>
<af:selectItem label="China" value="CH" id="si8"/>
<af:selectItem label="Australia" value="AUS" id="si7"/>
</af:selectManyChoice>
</af:panelGroupLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
After running the page I can see that both the component are looking alike as shown below.
Happy Coding :)
Comments
Post a Comment