0

Hi I want to submit my form using struts2 hibernate 3 who contain nested iterator but I can't diference between all attribute name i m trying to use a global variable in my jsp lik that :

<% int i=0; %>
<form  name="evalform" action="saveOrUpdateSousEval"    method="post"  >    
<s:iterator value="CategListGrille"  status="catgStatus">
     <s:iterator value="type"   status="typeStatus">
             <s:iterator  value="item" status="itemstatus" >
                    <s:textfield value="66" name="%{'souseval[#i].SousEval_Note'}"  />
                    <% i++;  %>
             </s:iterator>
    </s:iterator>
</s:iterator> 
    <s:submit value="Evaluer"  cssClass="btnsubmit"   /> 
    </div>  
</form> 

in my class Action i have this :

private ArrayList<SousEvaluation> souseval= new ArrayList<SousEvaluation>(); 
public String saveOrUpdate(){   
        System.out.println("enter saveOrUpdateEvalNote ok");    
        sousevaldao.saveOrUpdateSousEvaluation(souseval);

        return SUCCESS;
    }

and in my class Dao i have :

@Override 
    public void saveOrUpdateSousEvaluationNote(ArrayList<SousEvaluation> sousevalnote) {
        try {
            for (Iterator<SousEvaluation> it = sousevalnote.iterator(); it.hasNext();) {
                                      session.saveOrUpdate(it.next());
                 }
        } catch (Exception e) {
            transaction.rollback();
            e.printStackTrace();
        }   

    }

my goal is to submit many obect at once using my form

I can submit many record at once when i only use one iterator like that : i make this exmape i's work fine

<form  action="saveOrUpdateSousEval"    method="post"     > 
<s:iterator  begin="1" end="2" status="status">
            <s:textfield     name="%{'souseval['+#status.index+'].SousEval_Note'}"   />
        <s:textfield name="%{'souseval['+#status.index+'].evalglb.Eval_ID'}"    />
        <s:textfield name="%{'souseval['+#status.index+'].sousEvalItem.SousItem_ID'}"  />

</s:iterator>
 <s:submit value="Evaluer"  cssClass="btnsubmit"   /> 
 </form>
4

1 回答 1

0

一种非常糟糕的编码风格,将 struts 标签与 scriplets 混合在一起。事实上从不使用小脚本。让视野干净。

我把这个问题读了两遍,你已经自己写了解决方案。有什么问题 ?

<s:iterator value="CategListGrille"  status="firstIter">
     <s:iterator value="type"   status="secondIter">

<s:textfield name="souseval[%{#firstIter.index}].sousEvalItem[%{#secondIter.index}].SousItem_ID'}"  />
<s:textfield name="souseval[%{#firstIter.index}].sousEvalItem[%{#secondIter.index}].SousItem_Name'}"  />
<s:textfield name="souseval[%{#firstIter.index}].sousEvalItem[%{#secondIter.index}].SousItem_Description'}"  />

动作可以有类似的东西:

private List<List<sousEvalItem>> lst;

如果您能更清楚地解释您的问题,我也许可以提供有针对性的解决方案。

于 2013-09-14T09:11:58.333 回答