How to set selected value in html:options that isusing HasMap Long,String

So here is my problem
I have a HashMap<Long,String> where key is the country id and value is the country name. So I am displaying it in the jsp using the below code
<c-rt:set var="countriesMap" value="<%=countriesMap%>" target="java.util.HashMap<Long,String>"/>
<html:select size="1" property="countryId" >
<html:option value="" />
<html:options collection="countriesMap" property="key" labelProperty="value" />
</html:select>
And my Action form has the property countryId.
So it works fine , it displays all the countries and sets the country ID in the form's property that we set in the property attribute of <html:select>.The form's property is of type Long.
But suppose if some error occurs in the validate method for some other property then when the page renders back it does not set the selected country in the list box.
Can anyone please help me out of this.Thanks in advance.
Edited by: AmitDsm on May 9, 2008 8:01 AM

Hi,
I had the same issue. Altho I am using Spring, the solution is the same.
<select name="expMonth">
     <option value=""></option>
     <c:forEach items="${form.data.months}"
          var="month">
          <c:choose>
               <c:when test="${form.data.pDet.expDate_month eq month}">
                    <option selected="selected"><c:out value="${month}"/></option>
               </c:when>
               <c:otherwise>
                    <option><c:out value="${month}"/></option>
               </c:otherwise>
          </c:choose>
     </c:forEach>
</select>Disclaimer: Not sure if this is the correct way to do it, but it works for me
Edited by: Reegz on 2008/05/12 05:58

Similar Messages

  • How to set defalut values for html:radio

    Hi all,
    can you please tell me how to set defalut values for radio buttons (html:radio) in struts?

    You may have more luck if you ask this Struts specific question in a forum devoted to Struts at their own homepage over there at apache.org. It may also help a lot to read its documentation and tutorials. I would really be surprised if they didn't even document such a trivial thing.

  • Plsss help me: how to set default values in html:file and html:radio

    Hai,
    To set default value to text box i use the following code. It works well.
    <html:text property="modifyserverdesc" value="<%= serverDesc%>" styleClass="text" size="38"/>But for file i use the code
    <html:file styleClass="file" property="modifyserverimgfile" value="<%= serverImage%>" size="40"/>It doesn't display value. What is problem here?
    how to set default selection in <html:radio>.

    No it won't help.
    You can't set a value into an <input type="file"> control at all. The user has to put values in themselves.
    The reason behind this is security. If the programmer could put any value they liked in there, you could upload any file at all from a users computer without their intervention. eg C:\windows\system32\passwords.txt
    Bottom line: you can't put a default value into the input type="file" control.
    And a good thing too ;-)

  • How to set default value for html:file in struts

    hi
                   i am working on an application using struts situation is i am using the
    <html:file property="" /> to allow the user to upload file. but i need that a default file should be set so that even if the user donot click browse ie                the user wish to upload that default file the default file get uploaded on page submition.     Is it possible to set any default value for html:file ...if yes plz provide any suggestion or links how to achieve this.     thanks in advance

    www.google.com?q=STRUTS+DOCUMENTATION

  • How to set Selected Value in InputSelect

    Hi,
    I have implemented InputSelect component from the BC4J, and the items(attributes) are retrieved and updated to the table correctly. However,there's an additional item, "None" appeared in the menu-list. I didn't insert any item of the value of "None". I referred back the sample of InputSelect in the Edit Record sample code, the list of items inside the menu are all from the table and there wasn't any item named "None". So, can anyone please tell me where did this "None" come from?
    Secondly, i would like to know how to make an item selected in a menu, so that it would be my initial value for the particular column?
    T.I.A,
    Sin Leng

    The 'none' option is automatically added when the database column accepts NULL as a value.

  • How to set default values in initialization event for select option

    Abapers,
    I have 3 GL account like 0024831231,0024831238,0024831245.
    Please help me how to set default values in select-options ( s_hkont ) in INTIALIZATION event
    Thanks

    Select option is table <Structure> with fields, low, high, sign & option
    you need to append the value into the select option, with appropriate value in low or
    example:
    S_HKONT-low  = <value>
    S_HKONT-SIGN = 'I'
    S_hkont-OPTION = 'EQ'
    append s_hkont.
    Default value for select-option also can be added directly in select-option statement.
    Regards,
    Mahesh

  • How to get the values from html:select? tag..?

    i tried with this, but its not working...
    <html:select styleClass="text" name="querydefs" property="shortcut"
                 onchange="retrieveOptions()" styleId="firstBox" indexed="true">
    <html:options collection="advanced.choices" property="shortcut" labelProperty="label" />
    </html:select>
                        <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>

    <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>This java script is not working at all..its not printing anything in document.write();
    This is code..
    <td class="rowcolor1" width="20%">
    <html:select styleClass="text" name="querydefs" property="shortcut"
                             onchange="retrieveSecondOptions()" styleId="firstBox"
                             indexed="true">
                             <html:options collection="advanced.choices" property="shortcut"
                                  labelProperty="label"  />
                        </html:select>i tried with this also. but no use..i'm not the getting the seleced option...
    function retrieveOptions(){
    firstBox = document.getElementById('firstBox');
                             if(firstBox.selectedIndex==0){
          return;
        selectedOption = firstBox.options[firstBox.selectedIndex].value;
    }actually , how to get the values from <html:select> ...?
    my idea is to know which value is selected from the combo box(<html:select> ) if that value is equal some string i have enable a hyperlink to open a popup window

  • How to set Selected Ship-To in BasketUI?

    Hi Experts,
    Can you please help me how (in java code) to "set" the selected ship-to in BasketUI?
    In the code below, at the option, I just need to display the selected="selected" option.
    The output:
    <option  value="1">OPTION_A</option>
    <option  selected="selected" value="2">OPTION_B</option>
    ============================================
    BasketUI ui = new BasketUI(pageContext);
    <select class="select-xlarge" name="headerShipTo" id="headerShipTo" <% if (ui.isAccessible) { %> title="<isa:translate key="b2b.acc.shipto.title"/>" <% } %> >
           <isa:iterate id="shipTo" name="<%= MaintainBasketBaseAction.SC_SHIPTOS %>"    type="com.sap.isa.businessobject.ShipTo">
                       <option <%= ui.getShipToSelected(shipTo) %> value="<%= shipTo.getTechKey() %>">
                                  <%= JspUtil.encodeHtml(shipTo.getShortAddress()) %>
                       </option>
           </isa:iterate>
    </select>
    Thank you very much,
    jemaru

    The method ui.getShipToSelected(Shipto shipto) method checks if the input shipto is the selected Header Shipto
    and returns a string value selected="selected' , and blank string is the current selected shipto is not what is passed to this method.
    Since the BasketUI is, as the name says an UI class, there are no "setters". The UI class actually derives the values from the active basket / order / item objects. So, if you want to set the selected value, you must set this to the actual business object - the order
    Here is what one will do in an Action class to set item ship-to. Use the code below only as an example. You can reuse some of the code in the JSP also.
    //Say, this is what you have from your JSP
    //ship-to selected index
    RequestParser.Parameter shipToCustomer =  requestParser.getParameter("customer[]");
    // Somewhere in the item loop. You are setting the item shipto..
    // Assumed that order object is already available to you..
    ShipTo selectedShipTo = order.getShipTo(new TechKey(shipToCustomer));
    order.getItem(techKey).setShipTo((selectedShipTo == null) ?
                             ShipTo.SHIPTO_INITIAL : selectedShipTo);
    Is this what you are looking for?

  • How to get selected value from selectOneRadio ???

    Hi...i want to how to get selected value from selectOneRadio and use it in another page and in backing bean.
    Note i have about 10 selectOneRadio group in one page i want to know value of each one of them.
    Plzzzzzzzz i need help

    You have a datatable in which each row is a question, correct?
    Also in each row you have 5 possible answers that are in a radio, correct?
    So,
    You need to put in your datatable model, a question, and a list of answers (5 in yor case) and the selected one.
    So you will have a get to the question, an SelectItem[] list to populate the radios and another get/set to the selected question.
    ex:
    <h:selectOneRadio value="#{notas.selectedString}" id="rb">
    <f:selectItem itemValue="#{notas.valuesList}"/>
    </h:selectOneRadio>
    Search the web for examples like yours.

  • How to set variable value in an XML array

    Hi,
    Please let me know how to set the value for a xml array element using assign activity inside a for-each block in BPEL 11g
    I tried to set the variable value for result element using the below condition but i encountered selection failure message
    $outputVariable.payload/ns1:Student['i']/ns1:result or
    $outputVariable.payload/ns1:Student[$i]/ns1:result
    And the xsd used is as below
    <xsd:complexType name="StudentCollection">
    <xsd:sequence>
    <xsd:element name="Student" type="Student" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Student">
    <xsd:sequence>
    <xsd:element name="Name" type="xsd:string"/>
    <xsd:element name="location" type="xsd:string"/>
    <xsd:element name="mark" type="xsd:string"/>
    <xsd:element name="result" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    Thanks,
    Dhana

    Hi,
    At the back of button specify the following parameter:-
    CMD    1        Execute_planning_function
    Planning_function_name  1   xyz
    Var_name     1    variable_name
    var_value      1    blank
    Can also refer to link below:-
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0a89464-f697-2910-2ba6-9877e3088954?quicklink=index&overridelayout=true(can refer to page 20)
    http://www.sdn.sap.com/ddc5564a-337d-4cf9-a34e-2dab64df09be/finaldownload/downloadid-a61a6724ba8e7b7fbd9c5df9590ab50d/ddc5564a-337d-4cf9-a34e-2dab64df09be/irj/scn/go/portal/prtroot/docs/library/uuid/f0881371-78a1-2910-f0b8-af3e184929be?quicklink=index&overridelayout=true
    Hope it may help

  • In flex, How to set a value to one parameter, the parameter defined in a cffunction in a cfc file

    In flex, How to set a value to one parameter, the parameter
    defined in a cffunction in a cfc file, In the cffunction there are
    much cfargument, I want set a value to one of them, such as the
    cfc:
    <cffunction access="remote" name="myShow" output="false"
    returntype="struct">
    <cfargument name="ID" type="numeric" default=0>
    <cfargument name="GoodsID" type="string" default="">
    <cfargument name="DestTime" type="string" default="">
    <cfargument name="DestCount" type="numeric" default=1>
    How I set a value to only parameter one of them , such as set
    GoodsID when use mx:remoteObject.
    Thanks for your help

    Got maybe a solution for you, I have just tested it.
    So, the idea is to use intermediate variables. Imagine Var1 and Var2 variables that you refresh with your more or less complicated queries. Then what you can do is to refresh your final variable Var3 with a query using your intermediate variables. Here is an example for Oracle:
    select #Var1+#Var2 from dual
    This way you can make a chain of dependent variables: Var3 is using Var2 and Var2 is using Var1.
    Hope it helps.
    Shamil

  • How to set the value of process variables/payload using a managed bean?

    Hello,
    Someone can give me an example about how to set the values of a process payload in a managed bean?
    thank you!

    Try this:
    jsf page:
    <af:selectOneChoice label="Select Suburb"
    requiredMessageDetail="Select a suburb"
    valueChangeListener="#{selectOneChoiceBean.onValueChanged}"
    validator="#{selectOneChoiceBean.validate}"
    unselectedLabel="None" autoSubmit="true"
    binding="#{selectOneChoiceBean.selectOneChoice}"
    value="#{selectOneChoiceBean.value}">
    <f:selectItems value="#{selectOneChoiceBean.selectionList}"/>
    </af:selectOneChoice>
    backing bean:
    public class SelectChoiceBean {
    private List<SelectItem> selectionList;
    private String value = "B";
    private RichSelectOneChoice selectOneChoice;
    public SelectChoiceBean() {
    initSelectionList();
    public void setSelectionList(List<SelectItem> selectionList) {
    this.selectionList = selectionList;
    public List<SelectItem> getSelectionList() {
    return selectionList;
    public void onValueChanged(ValueChangeEvent valueChangeEvent) {
    System.out.println(valueChangeEvent.getNewValue());
    // Add event code here...
    public void validate(FacesContext facesContext, UIComponent uIComponent,
    Object object) {
    // Add event code here...
    private void initSelectionList() {
    selectionList = new ArrayList<SelectItem>();
    selectionList.add(new SelectItem("A", "A label"));
    selectionList.add(new SelectItem("B", "B label"));
    selectionList.add(new SelectItem("C", "C label"));
    public void setValue(String value) {
    this.value = value;
    public String getValue() {
    return value;
    public void setSelectOneChoice(RichSelectOneChoice selectOneChoice) {
    this.selectOneChoice = selectOneChoice;
    public RichSelectOneChoice getSelectOneChoice() {
    return selectOneChoice;
    }

  • How to set a value to a disabled field in an B1 screen ?

    Hi,
    Can anyone tell me how to set a value to a disabled field in an existing screen.
    For example , I want to set a value to the Paid/Credited field in the Sales - A/R Invoice screen, which is a disabled field.
    I tried setting the field as enabled but it throws an error.
    Thanks in advance
    Mina

    It depends on the business process required for generating the invoice.  (What is this process just now?)
    I can think on quite a few ideas, but can't be sure if any of them will match your specific requirements.  I'll list a few here and see if any of them might work, or at least generate some new ideas for you. (Unfortunately you can't change an existing payment object to add an invoice to it at a later date, nor is the reconciliation process exposed through the SDK.  This limits your options a bit.)
    1) Is there a need for a separate delivery and invoice?  Would skipping the delivery process and using the standard Invoice + Payment screen work for you?  Stock would be issued, invoice created and payment matched directly to invoice without any work.
    2) This might apply if the invoice is simply a one for one match with the delivery.  Rather than just generate a payment in the delivery screen, generate the invoice and a payment at the same time.  The standard invoice screen will then show it as paid.  You can control the dates on the invoice raised through DI code.
    3) Where do you write the Paid Amount to?  How is it not available in the invoice screen?  Put it somewhere accessible and write it to the user field.
    John.

  • How to set a value when right click on af:commandlink ?

    Hi All,
    JDev Ver : 11.1.1.4.0
    How to set a value to property listener on right click of a commandLink ?
    I am having values that are hyper linked using af:commandlink, when i right click on hyperlink, that value i need to get in the managed bean ?
    (While right click i am populating on menu item)
    how to get the value ?
    Give some solutions ?
    thanks
    Gopinath

    Hi,
    Try this code:
    <af:clientListener method="rightClick"
    type="contextMenu"/>
    <af:serverListener type="setValue"
    method="#{beanName.setValueMethodName}"/>
    <trh:script xmlns:trh="http://myfaces.apache.org/trinidad/html"
    id="s13">rightClick = function(event) {
    var source = event.getSource();
    AdfCustomEvent.queue( source, "setValue"
    , {}, false); }
    </trh:script>

  • How to set default value to date type attribute.

    Hi,
    How to set default value to date type attribute.
    E.g I want to set u201C01/01/1999u201D to date attributes.
    First i want to set value and then i want to fetch the same & want to check equals.
    please suggest solution.
    Regards,
    Smita

    Hi,
    In wdinit() method u can set the date
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    Date today = Calendar.getInstance().getTime();
    String reportDate = df.format(today);
    wdContext.currentContextElement().setFromDate(reportDate);
    Another way you have set the this formate like that
    1. Create a Simple type under "Dictionaries->SimpleType" called DateFormat
    2. Select the type as "date"
    3. Go to the "Representation" tab and set the format as "dd/MM/yyyy" (or whatever u want, but month should be MM)
    4.Bind the context attribute to the type created now.
    Hope this helps u.
    Best Regards
    Vijay K

Maybe you are looking for

  • How can i connect my macbook air to a HD TV ?

    I want to connect my mac to my TV but there's no cable to connect from a thunderbolt port to a HDMI.    please help

  • Flash hot showing ion IE6

    Flash animations do not show up on IE6 web pages when I'm logged into Win XP on a non-admin account. I just get the red x placeholder. When I log in as admin, everything works fine. Any tips?

  • Opening a frame inside IE applet (window)

    I have an applet whih creates an instance of a frame .. the frame opens up in a separate IE window .. is there a way for the frame to overlay the applet window or is the nature of the frame always going to force a new window to open .. thanks to all

  • Best Upgrade to Improve Performance?

    I'm looking for the most economical way to boost Aperture's performance. The specs on my equipment are as follows: Dual 2.0 ghz G5 Tower (first generation) 160 gb internal HD (where my current projects and masters are stored) 320 gb external Lacie HD

  • Annoying iFolder Server Problems

    Hello, I am using the open source edition of iFolder Server 3.8 on Ubuntu 10.04 for 2 weeks now and have already encountered several issues. Most of them are not that problematic, but one thing does really bother me: - User 1 (using opera) uses the w