struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexandru <icid...@yahoo.com>
Subject RE: struts tags: How to use a list inside another list
Date Tue, 14 Jun 2011 15:02:45 GMT
Martin, it looks like you know what you are doing, but some thing leave me puzzled.
Firstly, your code did worked but i don't understand some areas in it....
<s:iterator value="contentList" status="contentListStatus">
  <s:iterator value="top" status="translationsStatus"> // What's TOP?
         <td><s:property value="id" /></td>
         <td><s:property value="expression" /></td>
         <td><s:property value="translation" /></td> //translation
is part of Content in a relationship of OneToMany (viewing from content's side). So in order
to get to translation, in java code, would require this: content.getTranslations().get(index).getTranslation().
So that line should go somewhere else, perhaps in an other iterator?
     </tr>
 </s:iterator>

Second, i hope you understood that i want to send a 2d list back to the servlet, so there
must be a <s:hidden name="c.id"> tag somewhere in those loops ,where c is a Content
object and id is it's corresponding DB id. 

PS: document_id is populated though a hidden field in jsp which is not shown in my code snippets.

And, yes, i mapped the action with the corresponding results. 


I have tried though to work my way out with your code, but i'm stuck at some lines...
        <s:iterator value="contentList" status="contentListStatus">
            <tr>
                <s:iterator value="top" status="translationsStatus">
                    <td><s:property value="id" /></td><s:hidden
name=""> // THIS LINE
                        <td>
                               <s:property value="expression"
/>
                               <textarea name="" > </textarea>
//AND THIS LINE
                        </td>
                        <td><s:iterator value="translations">
                                <p class="translation">
                                    <s:property value="translation"
/>
                                </p>
                            </s:iterator>
                        </td>
                </s:iterator>
            </tr>
        </s:iterator>
What should i insert there between the "" ? For the first line i need it to simulate this:
contentList.get(index).setId(<value>);
For the second line:
ContentList.get(index).getTranslations().get(<index2>).setTranslation(<value>);

Thanks in advance!
--- On Tue, 6/14/11, Martin Gainty <mgainty@hotmail.com> wrote:

From: Martin Gainty <mgainty@hotmail.com>
Subject: RE: struts tags: How to use a list inside another list
To: "Struts Users Mailing List" <user@struts.apache.org>
Date: Tuesday, June 14, 2011, 10:14 AM


Assume this architecture:
                 Action
                     |
                     v
               1...n Content
                     |
                     v
              1..n Translation

<s:iterator value="contentList" status="contentListStatus">
  <s:iterator value="top" status="translationsStatus">
         <td><s:property value="id" /></td>
         <td><s:property value="expression" /></td>
         <td><s:property value="translation" /></td>
     </tr>
 </s:iterator>

2)
         Session s = HibernateUtil.getSessionFactory().openSession();
>         if(document_id == null){
>             documentList= (List<Document>)s.createQuery("from Document
d where d.project="+project_id).list();
>         }else{
>             documentList= (List<Document>)s.createQuery("from Document
d where d.project="+project_id).list();
>             contentList = (List<Content>)
>  s.createQuery("from Content c where c.document="+document_id).list();
>         }
//I must have  missed where is  document_id is populated before the handoff to hibernate?

3)struts-config.xml contains action declaration with result-type declarations for success
and or fail and or input results
i assume you have a success result-type declaration for or a default result-type?
        <action name="MyAction" class="packageName.MyAction">
            <result>success.jsp</result>
        </action>

?
Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni
et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.




> Date: Tue, 14 Jun 2011 06:16:36 -0700
> From: icidrop@yahoo.com
> Subject: Fw: RE: struts tags: How to use a list inside another list
> To: user@struts.apache.org
> 
> 
> 
> --- On Tue, 6/14/11, Alexandru <icidrop@yahoo.com> wrote:
> 
> From: Alexandru <icidrop@yahoo.com>
> Subject: RE: struts tags: How to use a list inside another list
> To: "Martin Gainty" <mgainty@hotmail.com>
> Date: Tuesday, June 14, 2011, 9:15 AM
> 
> So it is possible to send a list with another list ( 2d list) to a servlet? My sources
follows:
> 
>     <s:form action="do-translate-document" cssClass="formtable"
>         method="POST">
>         <s:iterator value="contentList">
>             <tr><td>
>             <p class="expression">
>                 <s:property value="expression" />
>             </p>
>             <s:hidden name="content.id"/>
>             <textarea
>  name="contentList.content.translations.translation"> </textarea>
>             <s:iterator value="translations">
>                 <p class="translation"><s:property value="translation"
/></p>
>             </s:iterator>
>             </td></tr>
>         </s:iterator>
>         <s:submit />
>     </s:form>
> 
> Content.java
> **********
> public class Content {
>     private Long id;
>     private String expression;
>     private List<Translation> translations;
>     
>     public void setExpression(String expression)
>  {
>         this.expression = expression;
>     }
> 
> 
>     public String getExpression() {
>         return expression;
>     }
>     
>     public void setTranslations(List<Translation> translation) {
>         this.translations = translation;
>     }
>     
>     public List<Translation> getTranslations() {
>         if(translations == null)
>             translations = new ArrayList<Translation>();
>         return this.translations;
>     }
>     
>     public void addTranslation(Translation translation){
>        
>  getTranslations().add(translation);
>     }
>     public void setId(Long id) {
>         this.id = id;
>     }
> 
>     public Long getId() {
>         return id;
>     }
> 
> }
> 
> 
> Translation.java
> ********
> public class Translation {
>     private Long id;
>     private Content expression;
>     private String translation;
>     
>     public Translation(){}
>     
>     public Translation(String s){
>         translation = s;
>     }
>     
>     public void setId(Long id) {
>         this.id = id;
>     }
> 
>     
>     public
>  Long getId() {
>         return id;
>     }
> 
>     public void setExpression(Content expression) {
>         this.expression = expression;
>     }
> 
>     public Content getExpression() {
>         return expression;
>     }
> 
>     public void setTranslation(String translation) {
>         this.translation = translation;
>     }
> 
>     public String getTranslation() {
>         return translation;
>     }
> }
> 
> 
> TranslateDocumentAction.java
> *******************
> public class TranslateDocumentAction extends ActionSupport {
> 
>     private static final long serialVersionUID = -1752813781713631809L;
>    
>  private List<Document> documentList;
>     private List<Content> contentList;
>     private String project_id; //Project's id
>     private String document_id;//Document's id
>  
>     
>     public String selectDocument(){
>         Session s = HibernateUtil.getSessionFactory().openSession();
>         if(document_id == null){
>             documentList= (List<Document>)s.createQuery("from Document
d where d.project="+project_id).list();
>         }else{
>             documentList= (List<Document>)s.createQuery("from Document
d where d.project="+project_id).list();
>             contentList = (List<Content>)
>  s.createQuery("from Content c where c.document="+document_id).list();
>         }
>         s.close();
>         return SUCCESS;
>     }
>     
>     public void validate(){}
>     
>     public void setDocumentList(List<Document> documentList) {
>         this.documentList = documentList;
>     }
> 
>     public List<Document> getDocumentList() {
>         if(documentList ==null)
>             documentList = new ArrayList<Document>();
>         return documentList;
>     }
> 
>     public void setProject_id(String project_id) {
>    
>      this.project_id = project_id;
>     }
> 
>     public String getProject_id() {
>         return project_id;
>     }
> 
>     public void setDocument_id(String document_id) {
>         this.document_id = document_id;
>     }
> 
>     public String getDocument_id() {
>         return document_id;
>     }
> 
>     public void setContentList(List<Content> contentList) {
>         this.contentList = contentList;
>     }
> 
>     public List<Content> getContentList() {
>         return contentList;
>     }
> }
> 
> 
> 
> --- On Tue, 6/14/11, Martin Gainty
>  <mgainty@hotmail.com> wrote:
> 
> From: Martin Gainty <mgainty@hotmail.com>
> Subject: RE: struts tags: How to use a list inside another list
> To: icidrop@yahoo.com
> Date: Tuesday, June 14, 2011, 8:52 AM
> 
> 
> 
> 
> 
>  
> without looking at the Action class and the struts-config.xml it is difficult to determine
the failure to submit problem ..i did notice
> 1)contentList.content.translations.translation whwre name is not camelcase but lowercase
and does not include package identitifer e.g.
> name="name"
> 2)you endtag textarea to exclude <s:iterator value="translations">..thus textarea
is one giant block of text without any relationship
> to any of the other declared properties
> 3)the declared iterator <s:iterator value="translations"> has no knowledge or association
with previous iterator <s:iterator value="translations"> and does not reflect the current
state of the iterator e.g.:
> <!-- this example pulls from collection leftSideCartoonCharacters and the property
will output the count (and the top property) -->
>             <s:iterator value="leftSideCartoonCharacters"
>  status="stat">
>                 <s:property value="%{#stat.count}" />.<s:property
value="top" />&nbsp;
>             </s:iterator>
> 
> ?
> difficult to say whats going on without seeing your action class and struts-config.xml
> Martin Gainty 
> ______________________________________________ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>  
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so
bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer
Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und
entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails
koennen wir keine Haftung fuer den Inhalt
>  uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.
> 
> 
> 
> 
> > Date: Tue, 14 Jun 2011 05:33:54 -0700
> > From: icidrop@yahoo.com
> > Subject: Re: struts tags: How to use a list inside another list
> > To: user@struts.apache.org
> > 
> > Is there a way to submit the contentList back to the server? in other words, can
i send a list from jsp to struts? I tried the following but it doesn't work:
> > 
> >     <s:form
>  action="do-translate-document" cssClass="formtable"
> >         method="POST">
> >         <s:iterator value="contentList">
> >             <tr><td>
> >             <p >
> >                 <s:property value="expression" />
> >             </p>
> >             <s:hidden name="id"/>
> >             <textarea name="contentList.content.translations.translation">
</textarea>
> >             <s:iterator value="translations">
> >        
>          <p class="translation"><s:property value="translation" /></p>
> >             </s:iterator>
> >             </td></tr>
> >         </s:iterator>
> >         <s:submit />
> >     </s:form>
> > 
> > 
>                            
                           
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message