struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexandru <icid...@yahoo.com>
Subject Fw: RE: struts tags: How to use a list inside another list
Date Tue, 14 Jun 2011 13:16:36 GMT


--- 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