You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Shane Smith <sa...@gmail.com> on 2005/08/12 01:46:21 UTC

RDC options class in SelectOne.java

Hey Folks,

In using the Select1 RDC, I've found that I won't always use a
configuration file to set my options, but will also set them
dynamically using the available method to add.  The problem is, when I
use dynamic data, the method to add only allows me to specify the
utterance and the value.  I intend to also set the dtmf and accept
attributes of the option tag.  I reworked the class a bit, adding
overloaded methods to allow for a range of options with option. Here
it is, please point out any glaring reasons not to do this....

Also attached as txt, in case my or your email reader hates tabs:

public static class Options implements Serializable {
	
	private List values;
	private List utterances;
	private List dtmfs;
	private List accepts;
	
	/**
	 * Constructor
	 *
	 */	
	public Options() {
		values = new ArrayList();
		utterances = new ArrayList();
		dtmfs = new ArrayList();
		accepts = new ArrayList();
	}
		/**
	 * Add this option to the list. Option contains an utterance
	 * and an optional value, dtmf, and accept.
	 *
	 */		
		public void add(String option_utterance) {	
		this.add("",option_utterance,"",false); 
	}
	
	public void add(String option_utterance, boolean option_approximate) {
		this.add("",option_utterance,"",option_approximate);
	}
	
	public void add(String option_value, String option_utterance) {
		this.add(option_value,option_utterance,"",false);
	}
	
	public void add(String option_value, String option_utterance, boolean
option_approximate) {
		this.add(option_value,option_utterance,"",option_approximate);
	}
	
	public void add(String option_value, String option_utterance, String
option_dtmf) {
		this.add(option_value,option_utterance,option_dtmf,false);
	}
	
	public void add(String option_value, String option_utterance, String
option_dtmf, boolean option_approximate) {
		values.add(option_value);
		utterances.add(option_utterance);
		dtmfs.add(option_dtmf);
		if (option_approximate == true)
			accepts.add("approximate");
		else accepts.add("exact");
	}
	
	/**
	 * Generate the markup of the vxml &lt;option&gt; elements as a String
	 *
	 * @return String the VXML markup
	 */		
	public String getVXMLOptionsMarkup() {
		String options = "";
		for (int i=0; i < utterances.size(); i++) {
			String val = (String) values.get(i);
			String utt = (String) utterances.get(i);
			String dtm = (String) dtmfs.get(i);
			String acc = (String) accepts.get(i);				
			if (StringUtils.isNotEmpty(utt)) {
				options += "<option";
				
				if (StringUtils.isNotEmpty(val)){
					options += " value=\"" + val.trim() + "\"";
				} 					
				if (StringUtils.isNotEmpty(dtm)) {
					options += " dtmf=\"" + dtm.trim() + "\"";
				}					
				if (StringUtils.isNotEmpty(acc)) {
					options += " accept=\"" + acc.trim() + "\"";
				}					
				options += ">" + utt.trim() + "</option>";					
			}
		}
		return options;
	}
| // end class Options{}


Thanks,
Shane Smith

Re: RDC options class in SelectOne.java

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
Shane Smith <sa...@gmail.com> wrote on 08/12/2005 12:22:52 PM:
> Any reason not to also add a:
> 
> public int count() { 
>   return values.size();
> }
> 
> method to the class? (or is there a more appropriate way to name it)

What would be the purpose? Are you planning to use count to make the 
select1 "smarter"?

-Rahul

> 
> -Shane

Re: RDC options class in SelectOne.java

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
Shane Smith <sa...@gmail.com> wrote on 08/12/2005 12:40:41 PM:
> Okay, Scratch that. I guess a count isn't needed if the only thing you
> can do is generate the output vxml anyways.
> 
> Question though... I'll write the code if folks think it would be 
> useful to add 
> 
> count()      <-- length of lists
> remove(3) <-- drop one element 
> get(1)        <-- show one element
> 
> This would allow the developer to look at the list and modify it as
> necessary.  Taking that a step further... I'd also like to overload
> the getVXMLOptionsMarkup()
> method, allowing you to specify an optional start and end point of the 
list.
> 
> getVXMLOptionsMarkup(1,4)
> 
> What do you folks think?  Should I just keep my data elsewhere until
> I'm ready to turn it into markup, or shoud we allow the developer to
> dynamically modify the list?  My scenario is a rdc:select1, where I
> may have 15 options from a database, but I would like to present only
> 5 at a time to the caller.  The backend action populates my option
> list, but I would like to be able to just pull a few at a time from
> the list on the jsp side. Thoughts?

So, something like: (erring on the side of being verbose, just want to 
make sure we're on the same page ;-)

System (first turn): (relevant VoiceXML options bit below, leaving aside 
attributes of option elements as they are not relevant to this discussion)

<option>option one</option>
<option>option two</option>
<option>option three</option>
<option>option four</option>
<option>option five</option>
<option>next</option>

User: next

System (second turn - paging/scrolling):

<option>previous</option>
<option>option six</option>
<option>option seven</option>
<option>option eight</option>
<option>option nine</option>
<option>option ten</option>
<option>next</option>

User: option nine

This would be a good enhancement. I'd be +1 to adding 
getVXMLOptionsMarkup(int begin, int end), which could in turn produce the 
previous, next bits as needed by checking list size (so I'm not sure what 
count() or remove(int) and get(int) gives us). We will have to take a 
similar approach with picking the relevant subset of options in case they 
come from an options file. 

In any case, are you planning on filing your earlier enhancement 
request?[1] I'd like to separate these two, we already closed on your 
earlier suggestion, and I'd like you to get all the credit for it ;-)

-Rahul

[1] http://marc.theaimsgroup.com/?l=taglibs-dev&m=112380398730865&w=2 

> 
> Thanks,
> Shane

Re: RDC options class in SelectOne.java

Posted by Shane Smith <sa...@gmail.com>.
Okay, Scratch that. I guess a count isn't needed if the only thing you
can do is generate the output vxml anyways.

Question though... I'll write the code if folks think it would be useful to add 

count()      <-- length of lists
remove(3) <-- drop one element    
get(1)        <-- show one element

This would allow the developer to look at the list and modify it as
necessary.  Taking that a step further... I'd also like to overload
the getVXMLOptionsMarkup()
method, allowing you to specify an optional start and end point of the list.

getVXMLOptionsMarkup(1,4)

What do you folks think?  Should I just keep my data elsewhere until
I'm ready to turn it into markup, or shoud we allow the developer to
dynamically modify the list?  My scenario is a rdc:select1, where I
may have 15 options from a database, but I would like to present only
5 at a time to the caller.  The backend action populates my option
list, but I would like to be able to just pull a few at a time from
the list on the jsp side. Thoughts?

Thanks,
Shane

On 8/12/05, Shane Smith <sa...@gmail.com> wrote:
> Any reason not to also add a:
> 
> public int count() {
>  return values.size();
> }
> 
> method to the class? (or is there a more appropriate way to name it)
> 
> -Shane
> 
> On 8/11/05, Rahul P Akolkar <ak...@us.ibm.com> wrote:
> > tvraman@almaden.ibm.com wrote on 08/11/2005 11:19:58 PM:
> > > good job, now others are writing our code for us:-)
> >
> > Well, we really should have got this one right ourselves ;-) Thanks again
> > Shane.
> >
> > -Rahul
> >
> >
>

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


Re: RDC options class in SelectOne.java

Posted by Shane Smith <sa...@gmail.com>.
Any reason not to also add a:

public int count() {	
  return values.size();
}

method to the class? (or is there a more appropriate way to name it)

-Shane

On 8/11/05, Rahul P Akolkar <ak...@us.ibm.com> wrote:
> tvraman@almaden.ibm.com wrote on 08/11/2005 11:19:58 PM:
> > good job, now others are writing our code for us:-)
> 
> Well, we really should have got this one right ourselves ;-) Thanks again
> Shane.
> 
> -Rahul
> 
>

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


Re: RDC options class in SelectOne.java

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
tvraman@almaden.ibm.com wrote on 08/11/2005 11:19:58 PM:
> good job, now others are writing our code for us:-)

Well, we really should have got this one right ourselves ;-) Thanks again 
Shane.

-Rahul

Re: RDC options class in SelectOne.java

Posted by "T. V. Raman" <tv...@us.ibm.com>.
good job, now others are writing our code for us:-)

-- 
Best Regards,
--raman
------------------------------------------------------------
T. V. Raman:  PhD (Cornell University)
IBM Research: Human Language Technologies
Architect:    RDC --- Conversational And Multimodal WWW Standards
Phone:        1 (408) 927 2608   T-Line 457-2608
Fax:        1 (408) 927 3012     Cell: 1 650 799 5724
Email:        tvraman@us.ibm.com
WWW:      http://almaden.ibm.com/u/tvraman      (google:tv raman 
AIM:      emacspeak
GPG:          http://www.almaden.ibm.com/cs/people/tvraman/raman-almaden.asc
Snail:        IBM Almaden Research Center,
              650 Harry Road
              San Jose 95120

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


Re: RDC options class in SelectOne.java

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
Shane Smith <sa...@gmail.com> wrote on 08/11/2005 07:46:21 PM:
> Hey Folks,
> 
> In using the Select1 RDC, I've found that I won't always use a
> configuration file to set my options, but will also set them
> dynamically using the available method to add.  The problem is, when I
> use dynamic data, the method to add only allows me to specify the
> utterance and the value.  I intend to also set the dtmf and accept
> attributes of the option tag.  I reworked the class a bit, adding
> overloaded methods to allow for a range of options with option. Here
> it is, please point out any glaring reasons not to do this....
<snip/>

We don't have this already ;-? Please file a bugzilla ticket and attach a 
patch.

I have some minor nits (thanks for your suggestion and your code, this is 
not a criticism):
1) Use real spaces (4) instead of tabs (the recent boatload of commits 
from me was to correct that in the first place ;-)
2) Use braces around single line if/else blocks
3) We should use a StringBuffer (moresoever now that the rendering bit is 
a little more involved)
4) Please make sure you compile against the latest RDC nightly (eg: 
StringUtils.isNotEmpty should be replaced by !RDCUtils.isStringEmpty)

-Rahul

> 
> Also attached as txt, in case my or your email reader hates tabs:
> 
> public static class Options implements Serializable {
> 
>    private List values;
>    private List utterances;
>    private List dtmfs;
>    private List accepts;
> 
>    /**
>     * Constructor
>     *
>     */ 
>    public Options() {
>       values = new ArrayList();
>       utterances = new ArrayList();
>       dtmfs = new ArrayList();
>       accepts = new ArrayList();
>    }
>       /**
>     * Add this option to the list. Option contains an utterance
>     * and an optional value, dtmf, and accept.
>     *
>     */ 
>       public void add(String option_utterance) { 
>       this.add("",option_utterance,"",false); 
>    }
> 
>    public void add(String option_utterance, boolean option_approximate) 
{
>       this.add("",option_utterance,"",option_approximate);
>    }
> 
>    public void add(String option_value, String option_utterance) {
>       this.add(option_value,option_utterance,"",false);
>    }
> 
>    public void add(String option_value, String option_utterance, boolean
> option_approximate) {
>       this.add(option_value,option_utterance,"",option_approximate);
>    }
> 
>    public void add(String option_value, String option_utterance, String
> option_dtmf) {
>       this.add(option_value,option_utterance,option_dtmf,false);
>    }
> 
>    public void add(String option_value, String option_utterance, String
> option_dtmf, boolean option_approximate) {
>       values.add(option_value);
>       utterances.add(option_utterance);
>       dtmfs.add(option_dtmf);
>       if (option_approximate == true)
>          accepts.add("approximate");
>       else accepts.add("exact");
>    }
> 
>    /**
>     * Generate the markup of the vxml &lt;option&gt; elements as a 
String
>     *
>     * @return String the VXML markup
>     */ 
>    public String getVXMLOptionsMarkup() {
>       String options = "";
>       for (int i=0; i < utterances.size(); i++) {
>          String val = (String) values.get(i);
>          String utt = (String) utterances.get(i);
>          String dtm = (String) dtmfs.get(i);
>          String acc = (String) accepts.get(i); 
>          if (StringUtils.isNotEmpty(utt)) {
>             options += "<option";
> 
>             if (StringUtils.isNotEmpty(val)){
>                options += " value=\"" + val.trim() + "\"";
>             } 
>             if (StringUtils.isNotEmpty(dtm)) {
>                options += " dtmf=\"" + dtm.trim() + "\"";
>             } 
>             if (StringUtils.isNotEmpty(acc)) {
>                options += " accept=\"" + acc.trim() + "\"";
>             } 
>             options += ">" + utt.trim() + "</option>"; 
>          }
>       }
>       return options;
>    }
> | // end class Options{}
> 
> 
> Thanks,
> Shane Smith
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org