JSF equivalent of HTML select Tag

Can any one please tell me how to achieve this in JSF.
<select>
  <option selected="selected" value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>I have tried this but its not working:
I want the "Volvo" option to be the default selected one.
<tr:selectOneChoice label="Car" required="true"
                          value="#{myBean.car}">
        <f:selectItem value="A" itemValue="A" itemLabel="Volvo"/>
        <f:selectItem value="B" itemValue="B" itemLabel="Saab"/>
        <f:selectItem value="C" itemValue="C" itemLabel="Mercedes"/>
        <f:selectItem value="D" itemValue="D" itemLabel="Audi"/>
  </tr:selectOneChoice>With the HTML code the VOLVO value comes as default selected, but with the JSF Code the default value is blank in the drop down. I want the first value to be selected in the drop down.
Some one please help.

You need to set the 'value' attribute of the selectOneChoice to the desired value as it is in f:selectItem's 'itemValue' attribute.
That said, the 'value' attribute of the f:selectItem should point to a javax.faces.model.SelectItem property, not a plain vanilla String. Also, you should either use that only, OR the itemValue and the itemLabel.

Similar Messages

  • Use of titleKey attribute in html:select tag

    Hi,
    There is one "titleKey" attribute to create mouse over pop-up texts taking key values from property files in case of i18n. It works for every struts specific tag like <html:text titleKey="help.rmc.name"/> or <html:checkbox titleKey="help.rmc.name"/> except for <html:select> tag which is used for creating combo box or list box. But this tag contains the titleKey attribute.
    Please give me some suggestions how to implement this mouse over pop-up texts in case of <html:select> tag

    Hi,
    There is one "titleKey" attribute to create mouse over pop-up texts taking key values from property files in case of i18n. It works for every struts specific tag like <html:text titleKey="help.rmc.name"/> or <html:checkbox titleKey="help.rmc.name"/> except for <html:select> tag which is used for creating combo box or list box. But this tag contains the titleKey attribute.
    Please give me some suggestions how to implement this mouse over pop-up texts in case of <html:select> tag

  • Html:select tag

    Hi all,
    In my jsp page i am using struts html:select tag,some contents are not fitting in the alloted size so i want to give horizontal scrolling for this select box,pls any body can tell me which property of select tag can be used,or any html tricks by which i can achive horizontal scrolling.examples will be help full.
    thanks,

    There aren't any tricks. This has nothing to do with Struts or JSP. It only has to to with HTML. The width is controlled by the size of the options or the size of the HTML area it has to display in. The latter if it's restricted otherwise by some table cell's width. I don't believe that I've ever seen a select box which has horizontol scrolling in any browser ever.

  • Html select tag issue.

    Hi All,
    I created a new project using EB3 to develop a photoshop extension. In that panel, I added the drop down box as follows,
    <body onLoad="onLoaded()">
         <select>
                <option value="">1</option>
                <option value="">2</option>
                <option value="">3</option>
                <option value="">4</option>
         </select>
    </body>
    I am seeing an issue, following are the steps to reproduce it,
    - Open the panel.
    - Click on the drop down. (Drop down opens)
    - Now loose the focus from the panel by clicking outside the panel.
    - Now click on the drop down. (Here comes the issue)
    Drop down doesn't open but it comes into the focus and when I clicked second time it will open.
    So every time when focus loosed the panel and I clicked on the drop down nothing happens on first time.
    And the strange thing is that I am seeing this issue on windows only.
    Anyone have any idea why it behave like this or is it a select tag bug in html panel?
    Thanks for any help..

    Yep, I second that. Combos take two clicks to be activated. Seems like yet another bug from a long, long list of issues with this CEP.

  • Using taglibs to generate html select tag

    Hello,
    I'm using taglibs to generate html select statements like this:
    <input:select ... options="<%= optionsMap %> </input:select>
    However I would like each option element to be assigned a
    "onclick" attribute. Is that possible?
    Thanks!

    >
    <input:select ... options="<%= optionsMap %> </input:select>
    Probably u meant ...
    <html:select ..>
    <html:option value="all">All</html:option>
    </html:select>
    You cannot add an onclick event on the "option" element. Its an incorrect tag.
    However you may add an onClick or rather onChange event of html:select
    Cheers
    -Rohit

  • How to make  struts html:select tag readOnly....!!!!

    Hi All,
    In my below code I want to make <html:select> as readonly like I did for <html:text>
    I don't want to make it disabled as it is graying out that field.
    My requirement is that it should be visible and also it shouldn't be editable.
    I am using Struts...!!!
    <html:text property="paramName" size="20" maxlength="50" readonly="true"/>                                
    <html:select property="paramTypeId" disabled="true"> // I dont want to use this--- disabled="true"
         <html:options collection="queryReturnType" property="value" labelProperty="label"/>
    </html:select>Thanks in advance....!!

    Can some one tell me in the below code
    *1. what is test="${controlEnabled}"....wha is this controlEnabled variable*
    *2. do I need to create an attribute for paramTypeId_Label in my form bean ??*
    I just wanna to make my <html:select> readonly..pls see my first post in this thread....!!
    <c:choose>
         <c:when test="${controlEnabled}">
           <html:select property="paramTypeId" >
                <html:options collection="queryReturnType" property="value" labelProperty="label"/>
           </html:select>
         </c:when>
         <c:otherwise
           <html:text property="paramTypeId_Label" value="${queryReturnType[paramTypeId].label}" readonly="true"/>
           <html:hidden property="paramTypeId"/>
         </c:otherwise>
    </c:choose>--Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • HTML select tag on irpt page - update database from options

    Hi all,
    I have an irpt page with two selects.  It is the traditional move stuff from one select to the other, then set the order of the options in the configured select.  (Admin page to specify an ordered list of items)
    After the user gets the list how they want it, I would like to send the options to an MII transaction (iCommand?) to update the database table that backs this admin data.
    I can do a comma delimited string to hold the select tag's option values, but would like to know if there is a more elegant way!
    Ideas?
    Thanks,
    --Amy Smith
    --Haworth

    It sounds elegant already - a pretty simple javascript loop to build your csv and Param.1 to your iCommand applet query should work like a charm.
    If you need to run it to a TRX, then the StringListToXML action makes turning your csv into linkable properties a simple effort.

  • On iOS7.0.3 html select tag with attribute 'multiple' crashes Safari

    Try loading an HTML page on Safari that has:
    <div>Multi-Select Picklist- tap on this to crash the iOS app
    <select id="12121" title="Available" multiple="multiple" size="3" style="width: 120px;">
    <optgroup label="Available">
    <option value="1">AAAAAA</option>
    <option value="2">BBBBBB</option>
    <option value="3">CCCCCC</option>
    <option value="4">DDDDDD</option>
    </optgroup>
    </select>
    </div>
    Safari will crash once you tap on the picklist. If I remove the attribute 'multiple' or if you have set it as multiple="multiple" it will work, but then it will offcourse not allow multiple selection. At least need to know a workaround.

    You might be better of asking this in the Developer forum. They might know more information about that, or at least in the Safari forum. I'll ask the moderators to move this for you.

  • Struts html:select tag

    Hi All,
    I am using struts. I want a dropdown single select menu option on my Jsp page.
    Basically, the options would be a dropdown either US or CA (meaning USA or CANADA). Html selectoptions is easy. How to do it in struts ?
    Once page is displayed, US will be selected by default. Then user may select either of the value from dropdown.
    Then, I have a state option dropdown, which should get populated, depending upon the first selection. Meaning, if user selects US in first dropdown, then all USA states show up in this second single select options.
    If user selects CA in first dropdown, then CANADA states show up in this second dropdown. I have the states list with me for both US and Canada.
    Can anyone send me a snippet of code for first dropdown. and then how in struts can I populate the second single select states dropdown (depending on whether user selected US or CA in first dropdown)
    Any help highly appreciated.
    thanks,
    pp

    Thanks Shanu.
    Nope. I am populating states in both cases in the ActionForm constructor. in other words, they are not coming from database. Folowing is short snippet how I am populating. So, I am able to display those states on the Jsp page dropdown.
    Onlything, i am stuck at is "that determination switch" as I quoted in previous post like
    If (US) then showUsStates else show CanadaStates on the Jsp thinggy ......... I am stuck here.
    And it has to happen on client side, cause if I sybmit the form, its gonna complain about other mandatory textfields like city , zip , phone NOT found as a result of Submit to ActionForm validation -- Even when user has yet to input rest of values and submit the entire form. Thats the reason why I say "On selection of country dropdown, population of appropriate states has to happen on client side"
    Any idea ?
      public CreateServiceRequestForm() {
             countrybean = new CountryBean[2];
             for (int i = 0; i < 2; i++) {
                 countrybean[i] = new CountryBean();
                 countrybean.setCountry(i);
    countrybean[0].setCountryName("US");
    countrybean[1].setCountryName("CA");
    statebean = new StateBean[54];
    for (int i = 0; i < 54; i++) {
    statebean[i] = new StateBean();
    statebean[i].setStateId(i);
    statebean[0].setName("AK");
    statebean[1].setName("AL");
    statebean[2].setName("AR");
    statebean[3].setName("AZ");
    statebean[4].setName("CA");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • XSL equivalent of  HTML br tag

    Hi,
    I am converting an html report in to xml and then this xml to PDF using Apache FOP. I have some data in my xml file which contains some text having BR tags in it. The data is displayed correctly in the browser when the content types are text/xml. However, when I convert this xml into PDF, the text having BR tags does not break into multiple lines.
    I have tried replacing BR with <xsl:text></xsl:text> but then I get error.
    Is there any alternative to get this working???
    Thnx.
    Sanjeev.

    In the XSL template for BR, what are you converting it to in the XML file?
    You need to convert the BR to whatever XML element is used to represent a sentence without an indent.
    The paragraphs in the XML instance should then contain this element as a child. For example,
    <paragraph>This is a sentence that is part of a paragraph converted from an HTML report that is using a BR element. We need to start a new line of text in the paragraph without an indent.How about right here:
    <newline/>
    I'm on a new line of text within the paragraph.
    </paragraph>
    Search the Apache FOP API to find out how to manipulate the format of the text.
    Edited by: GhostRadioTwo on Sep 25, 2007 12:39 PM

  • Default UIPicker in UIWebView for html select drop down- too large font.

    Hi everyone,
    The default picker that is used for selecting options from html select tag (drop down) in a UIWebView is cutting off our data.
    I could use labels if it were not in a web view, but can't work out how to adjust the picker used in web view.
    The only way I can think is the detect selection using js, overide the picker with a custom picker and then send selection back to page. Seems complicated so i'm trying to find out if there is an easier/better way?
    The data is quite long so I do need to reduce font size. As there are quite a lot of options the drop down much more suitable to radio buttons for instance.
    I have noted the quick connect framework but seems like an overkill and this is an app that is already live so I don't really want to add a new framework just for an update.
    Any advice?

    Hi K T thanks for your reply
    In the first example of real data that I have used, it is cut off in both orientations. Only one of the options by one character of so but this forces a '...' to be added in the middle and it to be cut off even more.
    Ideally I would like to bring the font size down and make it two lines.
    Cheers

  • Html:select border issue.

    Hi,
    I am trying to put a border on a dropdownlist. For the dropdown, I am using html:select tag. I tried giving the border using the style attribute in html:select.(<html:select style="border:1px solid red"). It does not seem to be working. Could someone help me out and guide me in the proper direction. Thanks.

    Are we talking java here? Or is this javascript? If javascript, you know that this is a java forum, and that the two languages are vastly different. If you're asking about java, then sorry, but I'm at a loss to help you as I've never heard of these before.

  • Problem in SELECT TAG using variables

    Hi all,
    I have a JSP page which updates the record for a user.Now there is a HTML select tag and when the user queries its data this SELECT tag will automaticaly select the user stored item in database automatically. It means the select tag will have a variable to select the options. Now how can i use variables in SELECT TAG. Please help needed.

    I'm not exactly sure what you are asking, but here goes.
    First, are you able to populate the select box with all the names... this is what it sounds like to me.
    Or are you not able to populate it nor select it.
    I use JSTL for all my jsps... so for me I would store a collection on the form and then iterate through it. (arrayList being my preference)
    look into using <c:forEach> or you could try <logic:iterate> which I've used before but it has been several years.
    here is an example block of code.
    Sorry this is going to be a bit convoluted because of what I'm doing with it..
    but I have an ArrayList that contains string arrays... position 0 being the value I want returned (like 1 through 10) and position 1 being the text representation..
    so it comes out like
    1 - Option 1
    2 - Option 2
    You will notice the if statement where I check to see if the localList[0] is equal to the view field. view would be your selected value.
    <SELECT name="view" size="7"
         multiple="multiple" class='OmniDlgLabel'>     
                   <c:if test="${sessionScope.PHI2Form.localList!=null}">
                        <c:forEach var="localList"
                             items="${sessionScope.PHI2Form.localList}" varStatus="status">
                             <OPTION value='<c:out value="${localList[0]}"/>'
                                       <c:if test="${sessionScope.PHI2Form.view==localList[0]}">SELECTED</c:if>>
                             <c:out value="${localList[0]}"/>-<c:out value="${localList[1]}" /></OPTION>
                        </c:forEach>
                   </c:if>          
    </SELECT></TD>There is an extra > that I cannot get rid of.. should be there after the
    <OPTION value='<c:out value="${localList[0]}"/>'

  • Html:select onchange

    Hi,
    In html:select tag, i'm using onchange function to submit the page. The problem here is, after selecting a value, if I immediately select another from the combo,it again submits but the page renders with blank page. is there is anyother way to solve this??
    thanks in advance.

    yeah, don't do that.
    You can force not doing that by doing this:
    ... onchange="theSubmitThing(); this.disabled = true;" ...

  • Preselect an option in html:select

    Hey,
    I am implementing struts in my application. How do i preselect an option in <html:select> tag
    here is what i am doing but the option does not get preselected.. the collection below returns A, B , C etc..
    <html:select property="accountClass" name="criteriaForm" value ="B" styleClass="selectBoxStyle">
    <logic:iterate id="myCollectionElement" collection="<%= Util.getAllClasses() %>">
    <html:option value ="<bean:write name="myCollectionElement" />">
    <bean:write name="myCollectionElement" /></html:option>
    </logic:iterate>     
    </html:select>
    everything seem to work fine except value "B" in the list box is not preselected.. how do i achieve this??
    Thanks
    KM

    Try using the <html:options> tag.
    <html:select property="accountClass" value="B">
        <html:options collection="<%= Util.getAllClasses() %>"
                      property="someValue"
                      labelProperty="someDescription" />
    </html:select>

Maybe you are looking for