myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ignicolist <ignicol...@gmail.com>
Subject Re: Remove Entry from schedule Tomahawk
Date Sat, 18 Aug 2007 00:59:03 GMT

Hi again, Tks for your great example, i do every thing, and i found a
problem, in the function remove:

 protected boolean removeEntry(String id)
        {
        	 
                ScheduleEntry entry = null;
                String currentId = null;
               
                System.out.println("++++++++++++++++"+entries.size());//*1
                
                for(ScheduleEntry se : (TreeSet<ScheduleEntry>)entries)
                {
                	
                        if((currentId = se.getId()) != null &&
currentId.equals(id))
                        {
                        	
                                entry = se;
                                break;
                        }
                }
               
                if(entry != null)
                {
                	
                        entries.remove(entry);
                        entry = null;
                       
                        return true;
                }
               
                return false;
        }

the id that i select its correct in the funcion, the problem is the entries
dont have values! i println the entries.size() and its 0. 


i add the entries like that:

 
private ScheduleModel model;

entry.setId(cod_cal);
	        entry.setStartTime(startTime);
	        entry.setEndTime(endTime);
	        entry.setTitle(title);
	        entry.setDescription(description);
	        
	   model.addEntry(entry);     
	     model.refresh();

i try delete like that:

ExtendedScheduleModel foo = new ExtendedScheduleModel();
 DefaultScheduleEntry entry = new DefaultScheduleEntry();
entry.setId("10");
		
foo.removeEntry(entry);

if i add the entries like that:


 private  ExtendedScheduleModel sss ;

               entry.setId(cod_cal);
	        entry.setStartTime(startTime);
	        entry.setEndTime(endTime);
	        entry.setTitle(title);
	        entry.setDescription(description);
	        
	     sss.addEntry(entry);
	     sss.refresh();

blank page...


Any sujection? Tks for all you are doing! 






Michał 'Gandalf' Stawicki wrote:
> 
> Right, it was fubar'ed, SimpleScheduleModel wasn't meant for extending
> :) This works - you use like you tried at the beginning - create
> entry, set id and you can remove it. BTW: I think your bean should be
> session, not request, unless you intended so.
> 
> /*
>  * Licensed to the Apache Software Foundation (ASF) under one
>  * or more contributor license agreements.  See the NOTICE file
>  * distributed with this work for additional information
>  * regarding copyright ownership.  The ASF licenses this file
>  * to you under the Apache License, Version 2.0 (the
>  * "License"); you may not use this file except in compliance
>  * with the License.  You may obtain a copy of the License at
>  *
>  *   http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing,
>  * software distributed under the License is distributed on an
>  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>  * KIND, either express or implied.  See the License for the
>  * specific language governing permissions and limitations
>  * under the License.
>  */
> 
> package ###########
> 
> import java.io.Serializable;
> 
> import java.text.DateFormat;
> import java.text.SimpleDateFormat;
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Date;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.TreeSet;
> import org.apache.myfaces.custom.schedule.model.AbstractScheduleModel;
> import org.apache.myfaces.custom.schedule.model.Day;
> import org.apache.myfaces.custom.schedule.model.DefaultScheduleEntry;
> import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
> 
> import org.apache.myfaces.custom.schedule.util.ScheduleEntryComparator;
> 
> /**
>  * <p>
>  * A simple implementation of the ScheduleModel, not backed by any kind of
>  * datasource: entries have to be added manually.
>  * </p>
>  *
>  * @author Jurgen Lust (latest modification by $Author: werpu $)
>  * @version $Revision: 371736 $
>  */
> public class ExtendedScheduleModel extends AbstractScheduleModel
> implements Serializable
> {
> 	
> 	
> // TEST
> //	public static void main(String [] args)
> //	{
> //		ExtendedScheduleModel foo = new ExtendedScheduleModel();
> //		DefaultScheduleEntry bar = new DefaultScheduleEntry();
> //		bar.setId("1");
> //		foo.addEntry(bar);
> //		DefaultScheduleEntry bar2 = new DefaultScheduleEntry();
> //		bar2.setId("1");
> //
> //		foo.removeEntry(bar2);
> //	}
> 	
> 	
> 	private static final long serialVersionUID = 1L;
> 	protected final TreeSet entries;
> 	protected final HashMap holidays;
> 	protected final DateFormat holidayFormat = new
> SimpleDateFormat("yyyyMMdd");
> 	
> 	public ExtendedScheduleModel()
> 	{
> 		this.entries = new TreeSet(new ScheduleEntryComparator());
> 		this.holidays = new HashMap();
> 	}
> 	
> 	/**
> 	 * Set the name of a holiday.
> 	 *
> 	 * @param date
> 	 *            the date
> 	 * @param holidayName
> 	 *            the name of the holiday
> 	 */
> 	public void setHoliday(Date date, String holidayName)
> 	{
> 		if (date == null)
> 		{
> 			return;
> 		}
> 		
> 		String key = holidayFormat.format(date);
> 		holidays.put(key, holidayName);
> 	}
> 	
> 	/**
> 	 * Add an entry to the model.
> 	 *
> 	 * @param entry
> 	 *            the entry to add
> 	 */
> 	public void addEntry(ScheduleEntry entry)
> 	{
> 		entries.add(entry);
> 	}
> 	
> 	/**
> 	 * Remove an entry from the model.
> 	 *
> 	 * @param entry
> 	 *            the entry to remove
> 	 */
> 	public void removeEntry(ScheduleEntry entry)
> 	{
> 		if(entries.remove(entry))
> 			return;
> 		
> 		if(entry != null && entry.getId() != null)
> 			removeEntry(entry.getId());
> 	}
> 	
> 	/**
> 	 * @see
> org.apache.myfaces.custom.schedule.model.ScheduleModel#removeSelectedEntry()
> 	 */
> 	public void removeSelectedEntry()
> 	{
> 		if (!isEntrySelected())
> 			return;
> 		removeEntry(getSelectedEntry());
> 		setSelectedEntry(null);
> 		refresh();
> 	}
> 	
> 	/**
> 	 * @see
> org.apache.myfaces.custom.schedule.model.AbstractScheduleModel#loadEntries(java.util.Date,
> 	 *      java.util.Date)
> 	 */
> 	protected Collection loadEntries(Date startDate, Date endDate)
> 	{
> 		ArrayList selection = new ArrayList();
> 		
> 		for (Iterator entryIterator = entries.iterator(); entryIterator
> 				.hasNext();)
> 		{
> 			ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
> 			
> 			if (entry.getEndTime().before(startDate)
> 			|| entry.getStartTime().after(endDate))
> 			{
> 				continue;
> 			}
> 			
> 			selection.add(entry);
> 		}
> 		
> 		return selection;
> 	}
> 	
> 	/**
> 	 * @see
> org.apache.myfaces.custom.schedule.model.AbstractScheduleModel#loadDayAttributes(org.apache.myfaces.custom.schedule.model.Day)
> 	 */
> 	protected void loadDayAttributes(Day day)
> 	{
> 		if (day == null)
> 			return;
> 		String key = holidayFormat.format(day.getDate());
> 		String holiday = (String) holidays.get(key);
> 		if (holiday != null)
> 		{
> 			day.setSpecialDayName(holiday);
> 			day.setWorkingDay(false);
> 		}
> 		else
> 		{
> 			day.setSpecialDayName(null);
> 			day.setWorkingDay(true);
> 		}
> 	}
> 	
> 	/**
> 	 * Remove entry from model
> 	 * <br /><br />
> 	 * @param id identifier of entry to be removed
> 	 * <br /><br />
> 	 * @return true on success and false on failure (in case entry with
> specified id wasn't found)
> 	 *
> 	 */
> 	protected boolean removeEntry(String id)
> 	{
> 		ScheduleEntry entry = null;
> 		String currentId = null;
> 		
> 		for(ScheduleEntry se : (TreeSet<ScheduleEntry>)entries)
> 		{
> 			if((currentId = se.getId()) != null && currentId.equals(id))
> 			{
> 				entry = se;
> 				break;
> 			}
> 		}
> 		
> 		if(entry != null)
> 		{
> 			entries.remove(entry);
> 			entry = null;
> 			
> 			return true;
> 		}
> 		
> 		return false;
> 	}
> }
> 
> 
> On 17/08/07, ignicolist <ignicolist@gmail.com> wrote:
>>
>> i have the class correct without errors. But when i call it  show a blank
>> page!
>>
>> ExtendedScheduleModel x = new ExtendedScheduleModel();
>> x.Remove2("8");
>>
>> I call the class like that. I think its correct! so why the blank page?
>> if i
>> put thouse two code lines in comments dont have the blank page, so the
>> problem is the class! :-((
>>
>>
>>
>>
>>
>>
>> Michał 'Gandalf' Stawicki wrote:
>> >
>> > Try this, remember to set valid package:
>> >
>> >  #####SET ME package #####SET ME
>> >
>> > import java.util.TreeSet;
>> > import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
>> > import org.apache.myfaces.custom.schedule.model.SimpleScheduleModel;
>> >
>> > /**
>> >  * @author mstawick
>> >  */
>> > public class ExtendedScheduleModel extends SimpleScheduleModel
>> > {
>> >
>> >       /** Creates a new instance of ExtendedScheduleModel */
>> >       public ExtendedScheduleModel()
>> >       {
>> >               super();
>> >       }
>> >
>> >       /**
>> >        * Remove entry from model
>> >        * <br /><br />
>> >        * @param id identifier of entry to be removed
>> >        * <br /><br />
>> >        * @return true on success and false on failure (in case entry
>> with
>> > specified id wasn't found)
>> >        *
>> >        */
>> >       public boolean removeEntry(String id)
>> >       {
>> >               ScheduleEntry entry = null;
>> >               String currentId = null;
>> >
>> >               for(ScheduleEntry se : entries)
>> >               {
>> >                       if((currentId = se.getId()) != null &&
>> currentId.equals(id))
>> >                       {
>> >                               entry = se;
>> >                               break;
>> >                       }
>> >               }
>> >
>> >               if(entry != null)
>> >               {
>> >                       entries.remove(entry);
>> >                       entry = null;
>> >
>> >                       return true;
>> >               }
>> >
>> >               return false;
>> >       }
>> >
>> >       private TreeSet<ScheduleEntry> entries;
>> > }
>> >
>> >
>> > On 17/08/07, ignicolist <ignicolist@gmail.com> wrote:
>> >>
>> >> Sorry to bee so boring and noob, but i realy need to do this, i need a
>> >> funcionality to show and occult calendars, and i have a entry
>> associate
>> >> to a
>> >> calendar, so when i need occult  the calendar i need to remove the
>> >> entries
>> >> of that calendar from the model. everything working, just need remove
>> the
>> >> entries.
>> >>
>> >>
>> >>
>> >> ignicolist wrote:
>> >> >
>> >> > Well i am a litle noob to all these, so i cant put your ideas to
>> work!
>> >> > :-((
>> >> >
>> >> > So i am using SimpleScheduleModel, so you say to create that class
>> in
>> >> the
>> >> > component Schedule or in my aplication?
>> >> > Because i create the class in my aplication and don´t work. Dam this
>> is
>> >> so
>> >> > complicated...
>> >> >
>> >> >
>> >> >
>> >> > Michał 'Gandalf' Stawicki wrote:
>> >> >>
>> >> >> I wrote the code in 'on the fly' just to give you idea how should
>> it
>> >> >> look, I didn't try it
>> >> >>
>> >> >> On 17/08/07, Michał 'Gandalf' Stawicki <stawicki@gmail.com>
wrote:
>> >> >>> Simply casting it should be fine:
>> >> >>>
>> >> >>> for(ScheduleEntry e : (TreeSet<ScheduleEntry>)entries)
>> >> >>>
>> >> >>>
>> >> >>> On 17/08/07, ignicolist <ignicolist@gmail.com> wrote:
>> >> >>> >
>> >> >>> > I try what you say but give me a error in: for(ScheduleEntry
e :
>> >> >>> entries)
>> >> >>> > The Error: Type mismatch: cannot convert from element
type
>> Object
>> >> to
>> >> >>> > ScheduleEntry
>> >> >>> >
>> >> >>> > Any idea?
>> >> >>> >
>> >> >>> >
>> >> >>> >
>> >> >>> > Michał 'Gandalf' Stawicki wrote:
>> >> >>> > >
>> >> >>> > > From SimpleScheduleModel.java
>> >> >>> > >
>> >> >>> > >     /**
>> >> >>> > >      * Remove an entry from the model.
>> >> >>> > >      *
>> >> >>> > >      * @param entry
>> >> >>> > >      *            the entry to remove
>> >> >>> > >      */
>> >> >>> > >     public void removeEntry(ScheduleEntry entry)
>> >> >>> > >     {
>> >> >>> > >         entries.remove(entry);
>> >> >>> > >     }
>> >> >>> > >
>> >> >>> > > ...
>> >> >>> > >
>> >> >>> > >     private final TreeSet entries;
>> >> >>> > >
>> >> >>> > > I don't know which model your using, but if it is
>> >> >>> SimpleScheduleModel
>> >> >>> > > than you should extend it and implement your own
method, ex;
>> >> >>> > >
>> >> >>> > > public boolean removeEntry(String id)
>> >> >>> > > {
>> >> >>> > > ScheduleEntry entry = null;
>> >> >>> > >
>> >> >>> > > if(entries != null && id != null)
>> >> >>> > > for(ScheduleEntry e : entries)
>> >> >>> > > {
>> >> >>> > > if(e.getId() != null && e.getId().equals(id))
>> >> >>> > > {
>> >> >>> > > entry = e;
>> >> >>> > > break;
>> >> >>> > > }
>> >> >>> > > }
>> >> >>> > >
>> >> >>> > > if(entry != null)
>> >> >>> > > {
>> >> >>> > > entries.remove(entry);
>> >> >>> > > return true;
>> >> >>> > > }
>> >> >>> > >
>> >> >>> > > return false;
>> >> >>> > > }
>> >> >>> > >
>> >> >>> > >
>> >> >>> > >
>> >> >>> > > On 17/08/07, Michał 'Gandalf' Stawicki <stawicki@gmail.com>
>> >> wrote:
>> >> >>> > >> I believe you have to pass exact reference to
object that was
>> >> added
>> >> >>> to
>> >> >>> > >> schedule, not some other object containing same
data,
>> example:
>> >> >>> > >>
>> >> >>> > >> ScheduleEntry foo = new MyScheduleEntry("bar");
>> >> >>> > >> ScheduleEntry foo2 = new MyScheduleEntry("bar");
>> >> >>> > >>
>> >> >>> > >> model.addEntry(foo);
>> >> >>> > >>
>> >> >>> > >> model.removeEntry(foo2); // wrong
>> >> >>> > >> mode.removeEntry(foo); //ok
>> >> >>> > >>
>> >> >>> > >>
>> >> >>> > >>
>> >> >>> > >> On 17/08/07, ignicolist <ignicolist@gmail.com>
wrote:
>> >> >>> > >> >
>> >> >>> > >> > Yes, because the entry when i select it
remove with
>> >> >>> > >> > model.removeSelectedEntry(); but if i specify
his id:
>> >> >>> > >> entry.setId("1");
>> >> >>> > >> > model.removeEntry(entry); dont eliminate.
And ids are the
>> same
>> >> in
>> >> >>> the
>> >> >>> > >> two
>> >> >>> > >> > situacions.
>> >> >>> > >> >
>> >> >>> > >> >
>> >> >>> > >> >
>> >> >>> > >> >
>> >> >>> > >> > Jurgen Lust-2 wrote:
>> >> >>> > >> > >
>> >> >>> > >> > > In your model implementation, do you
load the persistent
>> >> entry
>> >> >>> from
>> >> >>> > >> the
>> >> >>> > >> > > database, using the supplied id, before
you delete it?
>> >> >>> > >> > >
>> >> >>> > >> > > Jurgen
>> >> >>> > >> > >
>> >> >>> > >> > > Op donderdag 16-08-2007 om 14:01 uur
[tijdzone -0700],
>> >> schreef
>> >> >>> > >> > > ignicolist:
>> >> >>> > >> > >> Its what i am doing but don´t
work!
>> >> >>> > >> > >>
>> >> >>> > >> > >> an example:
>> >> >>> > >> > >>
>> >> >>> > >> > >> DefaultScheduleEntry entry = new
DefaultScheduleEntry();
>> >> >>> > >> > >>
>> >> >>> > >> > >>   entry.setId("1");
>> >> >>> > >> > >>  model.removeEntry(entry);
>> >> >>> > >> > >>
>> >> >>> > >> > >> this code is supose to remove the
entry from de model
>> with
>> >> id
>> >> >>> 1 no?
>> >> >>> > >> i
>> >> >>> > >> > >> just
>> >> >>> > >> > >> want remove de entry from the model,
but a entry specify
>> by
>> >> >>> me.
>> >> >>> > >> > >>
>> >> >>> > >> > >>
>> >> >>> > >> > >>
>> >> >>> > >> > >>
>> >> >>> > >> > >>
>> >> >>> > >> > >> Jurgen Lust-2 wrote:
>> >> >>> > >> > >> >
>> >> >>> > >> > >> > The ScheduleModel.removeEntry()
method expects a
>> >> >>> ScheduleEntry as
>> >> >>> > >> > >> > parameter. I suppose you use
Hibernate for database
>> >> access,
>> >> >>> so
>> >> >>> > >> what you
>> >> >>> > >> > >> > should do is retrieve the
ScheduleEntry from the
>> >> database,
>> >> >>> using
>> >> >>> > >> the
>> >> >>> > >> > >> id,
>> >> >>> > >> > >> > and feed the result to the
removeEntry method. In that
>> >> >>> removeEntry
>> >> >>> > >> > >> > method, you just delete it
with your Hibernate DAO.
>> >> >>> > >> > >> > You could of course add a
method
>> >> >>> removeEntry(String/Long/Whatever
>> >> >>> > >> id)
>> >> >>> > >> > >> > that does all of this.
>> >> >>> > >> > >> >
>> >> >>> > >> > >> > Jurgen
>> >> >>> > >> > >> >
>> >> >>> > >> > >> >
>> >> >>> > >> > >> >
>> >> >>> > >> > >> > Op donderdag 16-08-2007 om
11:20 uur [tijdzone -0700],
>> >> >>> schreef
>> >> >>> > >> > >> > ignicolist:
>> >> >>> > >> > >> >> Hi to all, i want to eliminate
a especific entry in a
>> >> model
>> >> >>> of
>> >> >>> > >> > >> schedule
>> >> >>> > >> > >> >> tomahawk. the example
in remove a selected entry work
>> >> fine,
>> >> >>> but
>> >> >>> > >> how to
>> >> >>> > >> > >> >> eliminate a determinated
entry?
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >> i try with this code:
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >> DefaultScheduleEntry entry
= new
>> DefaultScheduleEntry();
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >>  entry.setId(select);
>> >> >>> > >> > >> >>  entry.setStartTime(start);
>> >> >>> > >> > >> >>  entry.setEndTime(end);
>> >> >>> > >> > >> >>  entry.setTitle(select7);
>> >> >>> > >> > >> >>  entry.setDescription(select2);
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >>  model.removeEntry(entry);
>> >> >>> > >> > >> >>  model.refresh();
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >> i defined every value
for the entry, and then i want
>> to
>> >> >>> remove
>> >> >>> > >> that
>> >> >>> > >> > >> >> entry!
>> >> >>> > >> > >> >> Any help please!
>> >> >>> > >> > >> >>
>> >> >>> > >> > >> >> Tks for all.
>> >> >>> > >> > >> > --
>> >> >>> > >> > >> > Jurgen Lust <Jurgen.Lust@gmail.com>
>> >> >>> > >> > >> >
>> >> >>> > >> > >> >
>> >> >>> > >> > >> >
>> >> >>> > >> > >>
>> >> >>> > >> > > --
>> >> >>> > >> > > Jurgen Lust <Jurgen.Lust@gmail.com>
>> >> >>> > >> > >
>> >> >>> > >> > >
>> >> >>> > >> > >
>> >> >>> > >> >
>> >> >>> > >> > --
>> >> >>> > >> > View this message in context:
>> >> >>> > >>
>> >> >>>
>> >>
>> http://www.nabble.com/Re%3A-Remove-Entry-from-schedule-Tomahawk-tf4281655.html#a12198391
>> >> >>> > >> > Sent from the MyFaces - Users mailing list
archive at
>> >> Nabble.com.
>> >> >>> > >> >
>> >> >>> > >> >
>> >> >>> > >>
>> >> >>> > >>
>> >> >>> > >> --
>> >> >>> > >> Michał Stawicki
>> >> >>> > >>
>> >> >>> > >> stawicki@gmail.com
>> >> >>> > >> http://stawicki.jasliska.pl
>> >> >>> > >>
>> >> >>> > >
>> >> >>> > >
>> >> >>> > > --
>> >> >>> > > Michał Stawicki
>> >> >>> > >
>> >> >>> > > stawicki@gmail.com
>> >> >>> > > http://stawicki.jasliska.pl
>> >> >>> > >
>> >> >>> > >
>> >> >>> >
>> >> >>> > --
>> >> >>> > View this message in context:
>> >> >>>
>> >>
>> http://www.nabble.com/Re%3A-Remove-Entry-from-schedule-Tomahawk-tf4281655.html#a12200949
>> >> >>> > Sent from the MyFaces - Users mailing list archive at
>> Nabble.com.
>> >> >>> >
>> >> >>> >
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> Michał Stawicki
>> >> >>>
>> >> >>> stawicki@gmail.com
>> >> >>> http://stawicki.jasliska.pl
>> >> >>>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Michał Stawicki
>> >> >>
>> >> >> stawicki@gmail.com
>> >> >> http://stawicki.jasliska.pl
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Re%3A-Remove-Entry-from-schedule-Tomahawk-tf4281655.html#a12201958
>> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Michał Stawicki
>> >
>> > stawicki@gmail.com
>> > http://stawicki.jasliska.pl
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Re%3A-Remove-Entry-from-schedule-Tomahawk-tf4281655.html#a12206017
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Michał Stawicki
> 
> stawicki@gmail.com
> http://stawicki.jasliska.pl
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A-Remove-Entry-from-schedule-Tomahawk-tf4281655.html#a12209467
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Mime
View raw message