Radio button selection is not being saved on the front end in Struts2 upgrade to Struts 6.3.0.2

40 Views Asked by At

I have some radio button where I can select one radio button at a time and safe it. It is being saved in the database but on the frontend it is not being saved. There are no error. It is able to gather from the database when I checked on the console but it is not displaying on the frontend. There is no error on the console and neither is there any error on the developer tools on MS Edge Please assist.

public class getDotsCarRentalAction extends GenericMappingDispatchAction{

    public String saveCr(){
        HttpSession session = request.getSession();
        String result = null;
        DotsCarRentalForm frm = null;
        DotsCarRental dotsCarRental = new DotsCarRental();
        dotsCarRental = (DotsCarRental) session.getAttribute(DBConstants.sessionCarId);
        frm = (DotsCarRentalForm) form;
        dotsCarRental = frm.getFormData(dotsCarRental);
        result = frm.getFctSelected().trim();

        if(result == null || result.length() < 1) result = "CARRENTAL";
        ActionErrors errors = frm.validate(getTextProvider(),request);
        if(errors != null){
            saveErrors(errors);
            return "CARRENTAL";
        }
        session.setAttribute(DBConstants.sessionCarId,dotsCarRental);
        return result;
    }

    

    public String getCr(){
        HttpSession session = request.getSession();
        DotsCarRental dotsCarRental = new DotsCarRental;
        dotsCarRental = (DotsCarRental) session.getAttribute(DBConstants.sessionCarId);
        DotsCarRentalForm frm = new DotsCarRentalForm();
        if(dotsCarRental !=null){
            frm.setFormData(dotsCarRental);
        }
        frm.setFctSelected(null);
        frm.setValSelected(null);
        

    request.setAttribute("dotsCarRentalForm",frm);


        return "success";

    }


}
<div class="form-group" style="width:100%; clear: both;">
    <div>Staff</div><br />
    <s:iterator var="srr" value="#rr">
    <span>
    <s:radio name="rentalReason" style="font-weight: normal; padding: 2px; word-wrap: break-word;"      value="#frm.rentalReason" list="#srr" listKey="lookupTitle" listValue="lookupTitle" /><br/>
    </span>
    </s:iterator>
    </div>

    <div>
    <a class="btn btn-outline-primary"   href="javascript:document.forms[0].fctSelected.value='SAVEEOTAF';document.forms[0].submit();">SAVE AS   DRAFT</a>
    
    </div>

    <!--struts-dots.xml-->
    <action name="SaveDotsCarRental" class="com.dots.action.getDotsCarRentalAction" method="saveCr">

    <!--struts-generated.xml-->
    <action name="SaveDotsCarRental" class="com.dots.action.getDotsCarRentalAction" method="saveCr">

    <!--viewDotsCarRental.jsp-->
    <form name="form" method="post" action="SaveDotsCarRental.do" onsubmit="return false">

1

There are 1 best solutions below

0
Roman C On

Some attributes of the Struts tags require to forse OGNL to evaluate a value. Especially the <s:radio> tag when # is referenced. According to the doc none of the attributes are evaluated. So if you want to use OGNL expression in the tag attribute you have to forse OGNL.

How to preset the value of the <s:radio> tag

<s:radio name="rentalReason" style="font-weight: normal; padding: 2px; word-wrap: break-word;"      value="%{#frm.rentalReason}" list="%{#srr}" listKey="lookupTitle" listValue="lookupTitle" /><br/>
    

You can read more about How to assign value of <s:radio> to another variable using <s:set> in struts2.