users@glassfish.java.net

RE: text plus pitures

From: Martin Gainty <mgainty_at_hotmail.com>
Date: Sat, 12 Jun 2010 09:32:44 -0400

pictures are jpgs like any other file so all you need is a mechanism to store it and locate the resource filename

struts contains a UITagExample example which populates text (name) with the picture (pictureFileName) of a cartoon-character

    <bean type="org.apache.struts2.views.TagLibrary" name="sx" class="org.apache.struts2.dojo.views.DojoTagLibrary" />

 

xml configuration:
        <action name="exampleSubmit" class="org.apache.struts2.showcase.UITagExample" method="doSubmit">
         <result>exampleSubmited.jsp</result>
         <result name="input">example.jsp</result>
        </action>


exampleSubmited.jsp:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

 

<html>
    <sx:div id="images" label="images">

 

<body>
<h3>images</h3>
<pre>
<table>
    <s:label label="Name" name="name" />
    <s:label label="Birthday" name="birthday" />
    <tr>
        <td>
    <s:label label="Biography" name="bio" />
    <s:label label="Favourite Color" name="favouriteColor" />
    <s:label label="Friends" name="friends" />
    <s:label label="Legal Age" name="legalAge" />
    <s:label label="Region" name="region" />
    <s:label label="State" name="state" />
    <s:label label="Picture" name="picture" />
    <s:label label="Favourite Language" name="favouriteLanguage" />
    <s:label label="Favourite Vehical Type" name="favouriteVehicalType" />
    <s:label label="Favourite Vehical Specific" name="favouriteVehicalSpecific" />
    <tr>
        <td><label class="label">Favourite Cartoon Characters (Left):</label></td>
        <td>
            <s:iterator value="leftSideCartoonCharacters" status="stat">
                <s:property value="%{#stat.count}" />.<s:property value="top" />&nbsp;
            </s:iterator>
        </td>
    </tr>
    <tr>
        <td><label class="label">Favourite Cartoon Characters (Right):</label></td>
        <td>
            <s:iterator value="rightSideCartoonCharacters" status="stat">
                <s:property value="%{#stat.count}" />.<s:property value="top" />&nbsp;
            </s:iterator>
        </td>
    </tr>
    <s:label label="Thoughts" name="thoughts" />
</table>

    </sx:div>

 

</body>

</html>

 

the input example.jsp contains a file complontnet which will upload your image:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<html>
....

<body>

  <s:file
            tooltip="Upload Your Picture"
            label="Picture"
            name="picture" />

</body>

</html>

 

and of course an ActionClass that populates images and text for attributes

public class UITagExample extends ActionSupport implements Validateable {

    private static final long serialVersionUID = -94044809860988047L;


    String name;
    Date birthday;
    Date wakeup;
    String bio;
    String favouriteColor;
    List friends;
    boolean legalAge;
    String state;
    String region;
    File picture;
    String pictureContentType;
    String pictureFileName;
    String favouriteLanguage;
    String favouriteVehicalType = "MotorcycleKey";
    String favouriteVehicalSpecific = "YamahaKey";

    List leftSideCartoonCharacters;
    List rightSideCartoonCharacters;

    List favouriteLanguages = new ArrayList();
    List vehicalTypeList = new ArrayList();
    Map vehicalSpecificMap = new HashMap();

    String thoughts;

    public UITagExample() {
        favouriteLanguages.add(new Language("EnglishKey", "English Language"));
        favouriteLanguages.add(new Language("FrenchKey", "French Language"));
        favouriteLanguages.add(new Language("SpanishKey", "Spanish Language"));

        VehicalType car = new VehicalType("CarKey", "Car");
        VehicalType motorcycle = new VehicalType("MotorcycleKey", "Motorcycle");
        vehicalTypeList.add(car);
        vehicalTypeList.add(motorcycle);

        List cars = new ArrayList();
        cars.add(new VehicalSpecific("MercedesKey", "Mercedes"));
        cars.add(new VehicalSpecific("HondaKey", "Honda"));
        cars.add(new VehicalSpecific("FordKey", "Ford"));

        List motorcycles = new ArrayList();
        motorcycles.add(new VehicalSpecific("SuzukiKey", "Suzuki"));
        motorcycles.add(new VehicalSpecific("YamahaKey", "Yamaha"));

        vehicalSpecificMap.put(car, cars);
        vehicalSpecificMap.put(motorcycle, motorcycles);
    }

 

    public List getLeftSideCartoonCharacters() {
        return leftSideCartoonCharacters;
    }
    public void setLeftSideCartoonCharacters(List leftSideCartoonCharacters) {
        this.leftSideCartoonCharacters = leftSideCartoonCharacters;
    }


    public List getRightSideCartoonCharacters() {
        return rightSideCartoonCharacters;
    }
    public void setRightSideCartoonCharacters(List rightSideCartoonCharacters) {
        this.rightSideCartoonCharacters = rightSideCartoonCharacters;
    }


    public String getFavouriteVehicalType() {
        return favouriteVehicalType;
    }

    public void setFavouriteVehicalType(String favouriteVehicalType) {
        this.favouriteVehicalType = favouriteVehicalType;
    }

    public String getFavouriteVehicalSpecific() {
        return favouriteVehicalSpecific;
    }

    public void setFavouriteVehicalSpecific(String favouriteVehicalSpecific) {
        this.favouriteVehicalSpecific = favouriteVehicalSpecific;
    }

    public List getVehicalTypeList() {
        return vehicalTypeList;
    }

    public List getVehicalSpecificList() {
        ValueStack stack = ServletActionContext.getValueStack(ServletActionContext.getRequest());
        Object vehicalType = stack.findValue("top");
        if (vehicalType != null && vehicalType instanceof VehicalType) {
            List l = (List) vehicalSpecificMap.get(vehicalType);
            return l;
        }
        return Collections.EMPTY_LIST;
    }

    public List getFavouriteLanguages() {
        return favouriteLanguages;
    }

    public String execute() throws Exception {
        return SUCCESS;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getBio() {
        return bio;
    }

    public void setBio(String bio) {
        this.bio = bio;
    }

    public String getFavouriteColor() {
        return favouriteColor;
    }

    public void setFavouriteColor(String favoriteColor) {
        this.favouriteColor = favoriteColor;
    }

    public List getFriends() {
        return friends;
    }

    public void setFriends(List friends) {
        this.friends = friends;
    }

    public boolean isLegalAge() {
        return legalAge;
    }

    public void setLegalAge(boolean legalAge) {
        this.legalAge = legalAge;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public void setPicture(File picture) {
        this.picture = picture;
    }
    public File getPicture() {
        return this.picture;
    }

    public void setPictureContentType(String pictureContentType) {
        this.pictureContentType = pictureContentType;
    }

    public void setPictureFileName(String pictureFileName) {
        this.pictureFileName = pictureFileName;
    }

    public void setFavouriteLanguage(String favouriteLanguage) {
        this.favouriteLanguage = favouriteLanguage;
    }

    public String getFavouriteLanguage() {
        return favouriteLanguage;
    }


    public void setThoughts(String thoughts) {
        this.thoughts = thoughts;
    }

    public String getThoughts() {
        return this.thoughts;
    }

    public Date getWakeup() {
        return wakeup;
    }

    public void setWakeup(Date wakeup) {
        this.wakeup = wakeup;
    }

    public String doSubmit() {
        return SUCCESS;
    }

 

    // === inner class
    public static class Language {
        String description;
        String key;

        public Language(String key, String description) {
            this.key = key;
            this.description = description;
        }

        public String getKey() {
            return key;
        }
        public String getDescription() {
            return description;
        }

    }


    public static class VehicalType {
        String key;
        String description;
        public VehicalType(String key, String description) {
            this.key = key;
            this.description = description;
        }

        public String getKey() { return this.key; }
        public String getDescription() { return this.description; }

        public boolean equals(Object obj) {
            if (! (obj instanceof VehicalType)) {
                return false;
            }
            else {
                return key.equals(((VehicalType)obj).getKey());
            }
        }

        public int hashCode() {
            return key.hashCode();
        }
    }


    public static class VehicalSpecific {
        String key;
        String description;
        public VehicalSpecific(String key, String description) {
            this.key = key;
            this.description = description;
        }

        public String getKey() { return this.key; }
        public String getDescription() { return this.description; }

        public boolean equals(Object obj) {
            if (! (obj instanceof VehicalSpecific)) {
                return false;
            }
            else {
                return key.equals(((VehicalSpecific)obj).getKey());
            }
        }

        public int hashCode() {
            return key.hashCode();
        }
    }
}


if you need details on coding designing and or implementing a struts-webapp please contact user-subscribe_at_struts.apache.org

your best approach would be to take a course on how to implement struts-webapps and uploading and storing pictures would of course be covered


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: Fri, 11 Jun 2010 19:23:06 -0700
> From: glassfish_at_javadesktop.org
> To: users_at_glassfish.dev.java.net
> Subject: text plus pitures
>
> i like text plus pictures to Learn from .
> Could people put my style of learning as many reply here ?
> [Message sent by forum member 'lawrephord']
>
> http://forums.java.net/jive/thread.jspa?messageID=473984
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
                                               
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1