Search code examples
javascriptjspstruts-1

how to set struts <html:select> value in java class


I have ShowAction java class, on success of class JSP page will be shown, that jsp page contains

<bean:define id="stateTypes" name="sessionData" property="stateTypes"  />
<html:select property="issueStateCode" styleClass="smallDropInput" tabindex="5" styleId="myId">
    <html:options collection="stateTypes" property="value" labelProperty="label" />
</html:select>

In my ShowAction java class I am setting values for <html:select> (JSP) like this:

sessionData.setStateTypes(TypeHelper.getTypeList(TypeHelper.TYPE_JURISDICTION,
            sessionData.getCarrierId(), sessionData.getProductId()));

I want to set a particular value from list for <html:select> which gets selected or auto populated when JSP will be shown.


Solution

  • Got solution. sessionData.getSession().setAttribute("issueBranch","SetValue"); //to set value that you wants to set and retrive this value in JSP

    <% String issueBranch= request.getSession().getAttribute("issueBranch").toString(); %>
    
        <html:hidden styleId="myText" property="issueBranch" value='<%=issueBranch %>' /> 
    

    and set value in JS var val=document.getElementById('myText').value; document.getElementById('myId').value=val; // myId is styleId or id attribute for <html:select>