How to add checkbox value to temporary storage and put it in obj session using Struts 2
Hear my flag:
<input type="checkbox" value="${subFill.fillingname}"
name="fillings"> ${subFill.fillingname}</input>
bean class:
public class AddCartBean {
public String fillings;
public String getFillings() {
return fillings;
}
public void setFillings(String fillings) {
this.fillings = fillings;
System.out.println("hiii"+fillings);
}
}
action class:
public class CartAction extends ActionSupport implements SessionAware,ModelDriven<AddCartBean>{
AddCartBean acb = new AddCartBean();
@Override
public void setSession(Map<String, Object> map) {
sessionObj=(SessionMap<String, Object>) map;
}
@Override
public AddCartBean getModel() {
return acb;
}
public String mycart(){
sessionObj.put("fillings",acb.getFillings());
System.out.println("fillings are....."+acb.getFillings());
return "success";
}
when i first check the box and click the submit button check the box the value is appropriate for my action i can save it in session and get it in my jsp but my question is when the second time i click another check the box and click the submit button at the time I first submit the checkbox value will disappear and the new checkbox value appears, how can I get the first value of the submit checkbox and the second value of the submit checkbox?
source to share
The s:checkbox
default value of the tag when it is sent is boolean true
. You can change this by specifying a fieldValue
tag attribute s:checkbox
.
See example fors:checkbox
:
In Struts 2, you can use a tag
<s:checkbox>
to create an HTML checkbox.fieldValue="true"
is the actual value that will be displayed using the checkbox.
<s:checkbox name="checkMe" fieldValue="true" label="Check Me for testing"/>
source to share