dimanche 4 décembre 2016

Getting Values from Struts Checkbox that is iterated

So i have this code: JSP (First thing where user gets shown values)

<s:iterator value="animes">
        <tr>
            <td><s:checkbox name="checked" value="false"  fieldValue="%{aniTitle}" 
                        theme="simple" id=""/></td>
            <td><s:property value="aniTitle"/></td>
            <td><s:property value="aniStudio"/></td>
            <td><s:property value="aniEpi"/></td>
        </tr>
        </s:iterator>  

then after clicking a button, you get redirected here via struts:

<action name="aniDelHits2" class="AniAction" method="executeDelHits2">
        <result name="success" >deletechecked.jsp</result>
        <result name="error" >error2.jsp</result>
    </action>

then Action:

public String executeDelHits2(){
    titles = dao.deleteChecked(checked);
    Iterator iterator = titles.iterator();   
        if(iterator.hasNext()){    
            return SUCCESS;    
        }else{
            return ERROR;
            }    
}

and then DAO:

public ArrayList<String> deleteChecked(String[] checked){
    //List<Anime> animes = new ArrayList<Anime>();
    ArrayList<String> anime2 = new ArrayList<String>();

    for(int i=0;i < checked.length;i++){
        anime2.add(checked[i]);
    }



    return anime2; 

}

Then the results if it says SUCCESS:

<s:iterator value="titles">
                <tr>
                    <td><s:property value="titles.checked"/></td>

                </tr>
            </s:iterator>

I dont know how to get the values from checkboxes that are checked(i named them checked) and their fieldValue is what i want to put in an array outputted to another.

Please help. Thanks.




Aucun commentaire:

Enregistrer un commentaire