You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Saldy Mathew <sm...@webifyservices.com> on 2004/03/03 13:04:50 UTC

Need some info on ListEdit

Hi,

I have a page which consists of 5 blocks(default) and each block represents a Bean.These blocks have a checkbox attached.There are two buttons "Add Line" which will add a block and a "Delete Selected" which will delete the selected blocks.

Can anyone guide me as to how this can be best achieved.I am looking at ListEdit component currently.Any pointers/pseudo -code as how to go about.

-Saldy

Re: Need some info on ListEdit

Posted by Jamie Orchard-Hays <ja...@dang.com>.
I recently did something like this. In my page, there is a form for entering
data, and if the user needs more than one reservation, they can add another
dynamically and fill it out. Any but the original can be deleted as well.
I've included the code below for you to look at. You'll notice I've just got
a HashMap of my slot because this has mock data--I don't have a backend to
connect to yet. Also, I didn't include the html, so if you want that, let me
know.

Jamie

public abstract class InterviewSchedule extends DardenPage implements
PageRenderListener{
    private static final Log LOG =
LogFactory.getLog(InterviewSchedule.class);
    //private Integer reservationCount = null;

    public abstract ListEditMap getReservations();
    public abstract void setReservations(ListEditMap reservations);

    //TODO convert to proper data type. This is for mockup only.
    public abstract HashMap getReservation();
    public abstract void setReservation(HashMap reservation);

    public abstract Integer getReservationCount();
    public abstract void setReservationCount(Integer count);

    protected static HashMap createReservationSlot(){
        HashMap slot = new HashMap(17);
        slot.put("title","");
        slot.put("jobType","");
        slot.put("interviewType","");
        slot.put("numOpenInterviews", null);
        slot.put("numClosedInterviews", null);
        slot.put("numSlots", null);
        slot.put("location", "");
        slot.put("comments", "");
        slot.put("date1", null);
        slot.put("date2", null);
        slot.put("date3", null);
        slot.put("workStatusRequirement", null);
        slot.put("interviewType", null);
        return slot;
    }

    public void pageBeginRender(PageEvent event) {
        if(event.getRequestCycle().isRewinding()){
            return;
        }
        if(getReservations() == null){
            setupReservations();
        }

    }

    public void synchronizeReservations(IRequestCycle cycle){
        ListEditMap map = getReservations();
        HashMap reservation = (HashMap) map.getValue();
        setReservation(reservation);
    }

    public void addSchedule(IRequestCycle cycle){
        //TODO process other schedules
        setReservationCount(new Integer(getReservationCount().intValue() +
1));
        getReservations().add(getReservationCount(),
createReservationSlot());
    }

    public void deleteSchedule(IRequestCycle cycle){
        //TODO process other schedules
        ListEditMap reservations = getReservations();
        List values = reservations.getValues();
        ListEditMap newReservations = new ListEditMap();
        Iterator it = values.iterator();
        int count = 0;
        while (it.hasNext()) {
            Object value = it.next();
            newReservations.add(new Integer(++count),value);
        }
        setReservations(newReservations);
        setReservationCount(new Integer(count));
    }

    public void commitSchedule(IRequestCycle cycle){
        //get ReservationForm page to get its form info
        IPage resForm = cycle.getPage("ReservationForm");
        //TODO: get info and commit
    }

    //create the first, empty reservation
    private void setupReservations() {
        HashMap slot = createReservationSlot();

        ListEditMap map = new ListEditMap();
        setReservationCount(new Integer(1));
        map.add(getReservationCount(), slot);
        setReservations(map);
    }
}
-------------------
in the .page file:
-------------------
     <bean name="delegate"
class="edu.darden.career.corporation.tapestry.CareerValidationDelegate"/>

    <bean name="requiredStringValidator"
class="org.apache.tapestry.valid.StringValidator">
        <set-property name="clientScriptingEnabled" expression="false"/>
        <set-property name="required" expression="true"/>
    </bean>

    <property-specification name="reservation" type="java.util.HashMap"
persistent="no"/>
    <property-specification name="reservations"
type="org.apache.tapestry.form.ListEditMap" persistent="yes"/>
    <property-specification name="reservationCount" type="java.lang.Integer"
persistent="yes"/>
    <property-specification name="index" type="int" persistent="no"/>

    <!-- temporary for mock up -->
    <property-specification name="jobTypeList"
type="org.apache.tapestry.form.IPropertySelectionModel" persistent="no"
        initial-value="new
org.apache.tapestry.form.StringPropertySelectionModel(new java.lang.String[]
{'full-time','summer'})" />
    <property-specification name="interviewLengthList"
type="org.apache.tapestry.form.IPropertySelectionModel" persistent="no"
        initial-value="new
org.apache.tapestry.form.StringPropertySelectionModel(new java.lang.String[]
{'30: 8 sessions','45: 6 sessions','60: 4 sessions'})" />
    <property-specification name="closedInterviewsList"
type="org.apache.tapestry.form.IPropertySelectionModel" persistent="no"
        initial-value="new
org.apache.tapestry.form.StringPropertySelectionModel(new java.lang.String[]
{'0','1','2','3','4','5','6','7'})" />
    <property-specification name="openInterviewsList"
type="org.apache.tapestry.form.IPropertySelectionModel" persistent="no"
        initial-value="new
org.apache.tapestry.form.StringPropertySelectionModel(new java.lang.String[]
{'0','1','2','3','4','5','6','7'})" />
    <property-specification name="workStatusList"
type="org.apache.tapestry.form.IPropertySelectionModel" persistent="no"
        initial-value="new
org.apache.tapestry.form.StringPropertySelectionModel(new java.lang.String[]
{'No Restrictions','US Citizen/Permanent Resident','EU Citizen','3Native of
Country'})" />
    <property-specification name="interviewTypeList"
type="org.apache.tapestry.form.IPropertySelectionModel" persistent="no"
        initial-value="new
org.apache.tapestry.form.StringPropertySelectionModel(new java.lang.String[]
{'Behavioral','Case','Combination'})" />

    <component id="form" type="Form">
        <binding name="delegate" expression="beans.delegate"/>
    </component>
    <component id="reservationList" type="ListEdit">
        <binding name="source" expression="reservations.keys"/>
        <binding name="value" expression="reservations.key"/>
        <binding name="listener"
expression="listeners.synchronizeReservations"/>
        <binding name="index" expression="index" />
    </component>

    <component id="jobTitle" type="ValidField">
        <binding name="value" expression="reservation.title" />
        <binding name="validator"
expression="beans.requiredStringValidator"/>
        <message-binding name="displayName" key="jobTitleLabel"/>
    </component>
    <component id="jobTitleField" type="common:Label">
        <binding name="field" expression="components.jobTitle" />
        <message-binding name="displayName" key="jobTitleLabel"/>
    </component>

    <component id="jobLocation" type="ValidField">
        <binding name="value" expression="reservation.location" />
        <binding name="validator"
expression="beans.requiredStringValidator"/>
        <message-binding name="displayName" key="jobLocationLabel"/>
    </component>
    <component id="jobLocationField" type="common:Label">
        <binding name="field" expression="components.jobLocation" />
        <message-binding name="displayName" key="jobLocationLabel"/>
    </component>

    <component id="jobTypeSelect" type="PropertySelection">
        <binding name="model" expression="jobTypeList" />
        <binding name="value" expression="reservation.jobType"/>
    </component>

    <component id="interviewLengthSelect" type="PropertySelection">
        <binding name="model" expression="interviewLengthList" />
        <binding name="value" expression="reservation.interviewType"/>
    </component>

    <component id="closedInterviewsSelect" type="PropertySelection">
        <binding name="model" expression="closedInterviewsList" />
        <binding name="value" expression="reservation.numClosedIntervies"/>
    </component>
    <component id="openInterviewsSelect" type="PropertySelection">
        <binding name="model" expression="openInterviewsList" />
        <binding name="value" expression="reservation.numOpenInterviews"/>
    </component>

    <component id="workStatusSelect" type="PropertySelection">
        <binding name="model" expression="workStatusList" />
        <binding name="value"
expression="reservation.workStatusRequirement"/>
    </component>

    <component id="interviewTypeSelect" type="PropertySelection">
        <binding name="model" expression="interviewTypeList" />
        <binding name="value" expression="reservation.interviewType"/>
    </component>

    <component id="comments" type="TextArea">
        <binding name="value" expression="reservation.comments" />
    </component>

    <component id="date1" type="DatePicker">
        <binding name="value" expression="reservation.date1" />
    </component>

    <component id="date2" type="DatePicker">
        <binding name="value" expression="reservation.date2" />
    </component>

    <component id="date3" type="DatePicker">
        <binding name="value" expression="reservation.date3" />
    </component>

    <component id="showDeleteBox" type="Conditional">
        <binding name="condition" expression="index gt 0"/>
    </component>
    <component id="showDeleteSubmit" type="Conditional">
        <binding name="condition" expression="index gt 0"/>
    </component>
    <component id="deleteSchedule" type="Checkbox">
        <binding name="selected" expression="reservations.deleted"/>
    </component>
    <component id="continue" type="Submit">
        <binding name="listener" expression="listeners.commitSchedule"/>
        <message-binding name="label" key="continueLabel"/>
    </component>

    <component id="addSchedule" type="Submit">
        <binding name="listener" expression="listeners.addSchedule"/>
        <message-binding name="label" key="addScheduleLabel"/>
    </component>

    <component id="deleteSelected" type="Submit">
        <binding name="listener" expression="listeners.deleteSchedule"/>
        <message-binding name="label" key="deleteScheduleLabel"/>
    </component>

    <component id="editCorporateInfo" type="Submit">
        <binding name="listener" expression="listeners.editCorporateInfo"/>
        <message-binding name="label" key="editCorporateInfoLabel"/>
    </component>


----- Original Message ----- 
From: "Saldy Mathew" <sm...@webifyservices.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Wednesday, March 03, 2004 7:04 AM
Subject: Need some info on ListEdit


Hi,

I have a page which consists of 5 blocks(default) and each block represents
a Bean.These blocks have a checkbox attached.There are two buttons "Add
Line" which will add a block and a "Delete Selected" which will delete the
selected blocks.

Can anyone guide me as to how this can be best achieved.I am looking at
ListEdit component currently.Any pointers/pseudo -code as how to go about.

-Saldy


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org