You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by babu <sb...@calsoft.co.in> on 2004/10/09 06:33:05 UTC

found difficult in displaying hashtable in view

herewith i enclosed the file which contains the actionclass,form bean,view part

in this enclosed file the  attachment and url are KEY and VALUE pairs in hashtable ie) which i got from DB.
and i've to display these value in textfiled[url] based on the key selected  in the html:options.

i need help to identify.


This is my Form bean

package com.calsoft.ecm;

import java.util.Collection;
import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;


public class AttachForm extends ActionForm{
    
 private Hashtable values = new Hashtable();
 private Collection webLink = null;
 private String linkVal = null;
 private String url = null;
 private String attachment = null;
 
 public void setValue(String attachment,Object url)
 {
  values.put(attachment,url);
  
 }
 public Object getValue(String attachment)
 {
  return values.get(attachment);
 }
 

 public void reset(ActionMapping mapping,HttpServletRequest request)
 {
  values = new Hashtable();
 }
 
 /**
  * @return Returns the linkVal.
  */
 public String getLinkVal() {
  return linkVal;
 }
 /**
  * @param linkVal The linkVal to set.
  */
 public void setLinkVal(String linkVal) {
  this.linkVal = linkVal;
 }
 /**
  * @return Returns the url.
  */
 public String getUrl() {
  return url;
 }
 /**
  * @param url The url to set.
  */
 public void setUrl(String url) {
  this.url = url;
 }
 
 
 /**
  * @return Returns the attachment.
  */
 public String getAttachment() {
  return attachment;
 }
 /**
  * @param attachment The attachment to set.
  */
 public void setAttachment(String attachment) {
  this.attachment = attachment;
 }
 
 /**
  * @return Returns the webLink.
  */
 public Collection getWebLink() {
  return webLink;
 }
 /**
  * @param webLink The webLink to set.
  */
 public void setWebLink(Collection webLink) {
  this.webLink = webLink;
 }
}
******************************************************************
My Action Class

package com.calsoft.ecm;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class AttachAction extends Action {
 
  Hashtable hswebLink = new Hashtable();
    Enumeration enu;
    Collection collect = null;
    ArrayList arrayCollect = new ArrayList();
    String weblink = new String();
    String attachment = null;
    Object webUrl = null;
    String userLink = null;
    String userUrl = null;
 public ActionForward execute (ActionMapping mapping,
      ActionForm form,HttpServletRequest request,
      HttpServletResponse response)throws IOException, ServletException 
  {
  try {
   hswebLink = new Hashtable();  
   AttachForm attachForm = (AttachForm) form;
   userLink = attachForm.getAttachment();
   
   WeblinkConfigDAO web = new WeblinkConfigDAO(); 
   hswebLink = web.getWebLinks();
   
   enu = hswebLink.keys();
             //  hswebLink.values();
   while(enu.hasMoreElements())
   {
        weblink =(String) enu.nextElement();
        arrayCollect.add(weblink); // here the pbms
        collect = arrayCollect;
          webUrl = hswebLink.get(weblink);
    //   webUrl = hswebLink.get(weblink).toString();
      System.out.println("****[weblink]****"+weblink); it works fine
      System.out.println("****[webUrl]****"+webUrl); it works fine
         
   }
 attachForm.setWebLink(collect); // here the pbms 
  attachForm.setValue(weblink,webUrl);
  String userUrl = (String) attachForm.getValue(userLink);
  attachForm.setUrl(userUrl);   

   
  } catch (Exception e) {
    e.printStackTrace();
  }
  return (mapping.findForward("attachment"));
 
}
}

**************************************************************
my jsp 
 <TR> 
    <TD width=144  class="td_oddrows"> <div align="left">Attachment Name</div></TD>
    <TD width="159"  class="td_oddrows">
    <html:select property="attachment" name="attachForm">
  <html:options  property="webLink"    />
   </html:select>
    
     </TD>
  </TR>
  <TR> 
    <TD  class="td_evenrows"> <div align="left">URL </div></TD>
    <TD class="td_evenrows"> <html:text property="url"  /></TD>
  </TR>

***********************************************************
in this enclosed file the  attachment and url are KEY and VALUE pairs in hashtable ie) which i got from DB.
and i've to display these value in textfiled[url] based on the key selected  in the html:options.







Re: found difficult in displaying hashtable in view

Posted by Rick Reumann <st...@reumann.net>.
Can you please fix your computer's system time. Time goes by fast 
enough. I don't want to think it's October before I need to:)

babu said the following on 10/9/2004 12:33 AM:

> herewith i enclosed the file which contains the actionclass,form bean,view part
> 
> in this enclosed file the  attachment and url are KEY and VALUE pairs in hashtable ie) which i got from DB.
> and i've to display these value in textfiled[url] based on the key selected  in the html:options.
> 
> i need help to identify.
> 
> 
> This is my Form bean
> 
> package com.calsoft.ecm;
> 
> import java.util.Collection;
> import java.util.Hashtable;
> 
> import javax.servlet.http.HttpServletRequest;
> 
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionMapping;
> 
> 
> public class AttachForm extends ActionForm{
>     
>  private Hashtable values = new Hashtable();
>  private Collection webLink = null;
>  private String linkVal = null;
>  private String url = null;
>  private String attachment = null;
>  
>  public void setValue(String attachment,Object url)
>  {
>   values.put(attachment,url);
>   
>  }
>  public Object getValue(String attachment)
>  {
>   return values.get(attachment);
>  }
>  
> 
>  public void reset(ActionMapping mapping,HttpServletRequest request)
>  {
>   values = new Hashtable();
>  }
>  
>  /**
>   * @return Returns the linkVal.
>   */
>  public String getLinkVal() {
>   return linkVal;
>  }
>  /**
>   * @param linkVal The linkVal to set.
>   */
>  public void setLinkVal(String linkVal) {
>   this.linkVal = linkVal;
>  }
>  /**
>   * @return Returns the url.
>   */
>  public String getUrl() {
>   return url;
>  }
>  /**
>   * @param url The url to set.
>   */
>  public void setUrl(String url) {
>   this.url = url;
>  }
>  
>  
>  /**
>   * @return Returns the attachment.
>   */
>  public String getAttachment() {
>   return attachment;
>  }
>  /**
>   * @param attachment The attachment to set.
>   */
>  public void setAttachment(String attachment) {
>   this.attachment = attachment;
>  }
>  
>  /**
>   * @return Returns the webLink.
>   */
>  public Collection getWebLink() {
>   return webLink;
>  }
>  /**
>   * @param webLink The webLink to set.
>   */
>  public void setWebLink(Collection webLink) {
>   this.webLink = webLink;
>  }
> }
> ******************************************************************
> My Action Class
> 
> package com.calsoft.ecm;
> 
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Enumeration;
> import java.util.Hashtable;
> 
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> 
> import org.apache.struts.action.Action;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionMapping;
> 
> 
> public class AttachAction extends Action {
>  
>   Hashtable hswebLink = new Hashtable();
>     Enumeration enu;
>     Collection collect = null;
>     ArrayList arrayCollect = new ArrayList();
>     String weblink = new String();
>     String attachment = null;
>     Object webUrl = null;
>     String userLink = null;
>     String userUrl = null;
>  public ActionForward execute (ActionMapping mapping,
>       ActionForm form,HttpServletRequest request,
>       HttpServletResponse response)throws IOException, ServletException 
>   {
>   try {
>    hswebLink = new Hashtable();  
>    AttachForm attachForm = (AttachForm) form;
>    userLink = attachForm.getAttachment();
>    
>    WeblinkConfigDAO web = new WeblinkConfigDAO(); 
>    hswebLink = web.getWebLinks();
>    
>    enu = hswebLink.keys();
>              //  hswebLink.values();
>    while(enu.hasMoreElements())
>    {
>         weblink =(String) enu.nextElement();
>         arrayCollect.add(weblink); // here the pbms
>         collect = arrayCollect;
>           webUrl = hswebLink.get(weblink);
>     //   webUrl = hswebLink.get(weblink).toString();
>       System.out.println("****[weblink]****"+weblink); it works fine
>       System.out.println("****[webUrl]****"+webUrl); it works fine
>          
>    }
>  attachForm.setWebLink(collect); // here the pbms 
>   attachForm.setValue(weblink,webUrl);
>   String userUrl = (String) attachForm.getValue(userLink);
>   attachForm.setUrl(userUrl);   
> 
>    
>   } catch (Exception e) {
>     e.printStackTrace();
>   }
>   return (mapping.findForward("attachment"));
>  
> }
> }
> 
> **************************************************************
> my jsp 
>  <TR> 
>     <TD width=144  class="td_oddrows"> <div align="left">Attachment Name</div></TD>
>     <TD width="159"  class="td_oddrows">
>     <html:select property="attachment" name="attachForm">
>   <html:options  property="webLink"    />
>    </html:select>
>     
>      </TD>
>   </TR>
>   <TR> 
>     <TD  class="td_evenrows"> <div align="left">URL </div></TD>
>     <TD class="td_evenrows"> <html:text property="url"  /></TD>
>   </TR>
> 
> ***********************************************************
> in this enclosed file the  attachment and url are KEY and VALUE pairs in hashtable ie) which i got from DB.
> and i've to display these value in textfiled[url] based on the key selected  in the html:options.
> 
> 
> 
> 
> 
> 
> 


-- 
Rick

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


RE: Validator with DispatchAction...help!...newbie

Posted by lixin chu <li...@yahoo.com>.
There is an interesting article talking about
validation in DispatchAction. That may not be what you
are looking for but I would like to know if the method
suggestted by the author is a good choice or not:
http://www.reumann.net/struts/articles/request_lists.jsp

Another common practice is to have a isMutable()
method in ActionForm. However, it relies on the
Actions to play around the 'mutable' property
carefully. And is something goes wrong and the
property is set/reset properly, then things may go
wild. 

Any comments ?

lixin


--- Robert Taylor <rt...@mulework.com> wrote:

> ValidatorForm, ValidatorActionForm,
> DynaValidatorForm, and DynaValidatorActionForm allow
> you to leverage the validation framework in Struts.
> 
> How you use DispatchAction determines what you need
> to do to make it
> work with the validation framework.
> 
> For example there are two basic approaches:
> 
> 1. Differentiate different validation routines based
> on form name.
>    Using DispatchAction you could use the same form
> and identify it
>    with different names in the struts-config.xml
> file. You can then
>    ensure that each action mapping using the
> DispatchAction used the
>    appropriate form name to invoke the appropriate
> validation rules
>    in validation.xml.
> 
> 
> 2. Differentiate different validation routines based
> on action mapping.
>    Using DispatchAction you could use the same form
> with the same
>    identity. You can then use different action
> mappings which all map
>    to the same DispatchAction using the same form.
> Each unique action
>    mapping would then invoke the appropriate
> validation rules in
>    validation.xml.
> 
> 
> 
> There are other variations of DispatchAction such as
> MappedDispatchAction
> and LookupDispatchAction. Each of these might be
> leveraged differently
> to work with the validation framework. I've yet to
> use them, so I can't
> offer any advice; however, recently, there have been
> some healthy threads
> on both. Just don't ask Rick about
> LookupDispatchAction and you'll be okay :)
> 
> 
> Now, it gets kind of tricky when you want to use
> DispatchAction (or some variant
> there of) to perform different validation routines
> using the same form name and
> the same action mapping. This is typical when you
> have a single form with multiple buttons, where each
> button invokes a different
> operation on the DispatchAction and
> you want to use different validation routines for
> each operation.
> 
> Since validation routines basically key off of the
> name attribute of the form
> element in validation.xml, you can modify/override
> the getValidationKey() in
> XXXXValidatorForm or XXXXValidatorActionForm to
> return a name including the invoked operation. There
> are probably other ways
> to do this and most likely more elegant. I think you
> can also use the form name
> in conjunction with the page attribute as the
> validation key but I haven't done this
> yet.
> 
> 
> Digging around the source code always helps me to
> understand how things work.
> 
> 
> 
> robert
> 
> > -----Original Message-----
> > From: O. Oke [mailto:research_labs@yahoo.co.uk]
> > Sent: Tuesday, September 14, 2004 8:04 PM
> > To: Struts Users Mailing List
> > Subject: Validator with
> DispatchAction...help!...newbie
> >
> >
> >  --- Matt Bathje <mp...@ntsource.com> wrote:
> > > O. Oke wrote:
> > >
> > > > Can anyone please tell me how to use the
> Struts
> > > > Validator with DispatchAction.
> > > >
> > > > This article in bugzilla does not seem to deal
> > > with
> > > > the issue:
> > > >
> > >
> >
>
http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633
> > > >
> > > > Thank you.
> > > >
> > > > Ola
> > > >
> > >
> > >
> > > Ola - we more information to be able to help
> you. I
> > > can't even tell what
> > > your problem is, or why you think that bugzilla
> > > report is/isn't related
> > > to it. (Also, there are hundreds of bugzilla
> reports
> > > that do not apply
> > > to your problem...that doesn't mean they are
> helpful
> > > to explain what is
> > > going on.)
> > >
> > >
> > > Matt
> > >
> > >
> >
> > Matt,
> >
> > Please find further detail below:
> >
> >
> > GENERAL INFORMATION
> > ===================
> > My understanding is that the Stuts validator is
> not
> > designed to work with classes that extend
> > DispatchAction (as against Action).  However, the
> > information I have found on the internet appears
> to
> > suggest that there is a way to make them work with
> > each other.  This article
> >
>
(http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633)
> > is meant to be an explanation of howto, but on
> closer
> > examination, it did not seem to deal with the
> issue.
> >
> > Can you please tell me how to make them work with
> each
> > other?
> >
> > Thank you.
> >
> > Ola.
> >
> >
> >
> >
> >
> >
>
___________________________________________________________ALL-NEW
> Yahoo! Messenger - all new features - even more fun!
> http://uk.messenger.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


RE: Validator with DispatchAction...help!...newbie

Posted by Robert Taylor <rt...@mulework.com>.
ValidatorForm, ValidatorActionForm, DynaValidatorForm, and DynaValidatorActionForm allow
you to leverage the validation framework in Struts.

How you use DispatchAction determines what you need to do to make it
work with the validation framework.

For example there are two basic approaches:

1. Differentiate different validation routines based on form name.
   Using DispatchAction you could use the same form and identify it
   with different names in the struts-config.xml file. You can then
   ensure that each action mapping using the DispatchAction used the
   appropriate form name to invoke the appropriate validation rules
   in validation.xml.


2. Differentiate different validation routines based on action mapping.
   Using DispatchAction you could use the same form with the same
   identity. You can then use different action mappings which all map
   to the same DispatchAction using the same form. Each unique action
   mapping would then invoke the appropriate validation rules in
   validation.xml.



There are other variations of DispatchAction such as MappedDispatchAction
and LookupDispatchAction. Each of these might be leveraged differently
to work with the validation framework. I've yet to use them, so I can't
offer any advice; however, recently, there have been some healthy threads
on both. Just don't ask Rick about LookupDispatchAction and you'll be okay :)


Now, it gets kind of tricky when you want to use DispatchAction (or some variant
there of) to perform different validation routines using the same form name and
the same action mapping. This is typical when you have a single form with multiple buttons, where each button invokes a different
operation on the DispatchAction and
you want to use different validation routines for each operation.

Since validation routines basically key off of the name attribute of the form
element in validation.xml, you can modify/override the getValidationKey() in
XXXXValidatorForm or XXXXValidatorActionForm to
return a name including the invoked operation. There are probably other ways
to do this and most likely more elegant. I think you can also use the form name
in conjunction with the page attribute as the validation key but I haven't done this
yet.


Digging around the source code always helps me to understand how things work.



robert

> -----Original Message-----
> From: O. Oke [mailto:research_labs@yahoo.co.uk]
> Sent: Tuesday, September 14, 2004 8:04 PM
> To: Struts Users Mailing List
> Subject: Validator with DispatchAction...help!...newbie
>
>
>  --- Matt Bathje <mp...@ntsource.com> wrote:
> > O. Oke wrote:
> >
> > > Can anyone please tell me how to use the Struts
> > > Validator with DispatchAction.
> > >
> > > This article in bugzilla does not seem to deal
> > with
> > > the issue:
> > >
> >
> http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633
> > >
> > > Thank you.
> > >
> > > Ola
> > >
> >
> >
> > Ola - we more information to be able to help you. I
> > can't even tell what
> > your problem is, or why you think that bugzilla
> > report is/isn't related
> > to it. (Also, there are hundreds of bugzilla reports
> > that do not apply
> > to your problem...that doesn't mean they are helpful
> > to explain what is
> > going on.)
> >
> >
> > Matt
> >
> >
>
> Matt,
>
> Please find further detail below:
>
>
> GENERAL INFORMATION
> ===================
> My understanding is that the Stuts validator is not
> designed to work with classes that extend
> DispatchAction (as against Action).  However, the
> information I have found on the internet appears to
> suggest that there is a way to make them work with
> each other.  This article
> (http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633)
> is meant to be an explanation of howto, but on closer
> examination, it did not seem to deal with the issue.
>
> Can you please tell me how to make them work with each
> other?
>
> Thank you.
>
> Ola.
>
>
>
>
>
> ___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun!
http://uk.messenger.yahoo.com

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



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


Validator with DispatchAction...help!...newbie

Posted by "O. Oke" <re...@yahoo.co.uk>.
 --- Matt Bathje <mp...@ntsource.com> wrote: 
> O. Oke wrote:
> 
> > Can anyone please tell me how to use the Struts
> > Validator with DispatchAction.
> > 
> > This article in bugzilla does not seem to deal
> with
> > the issue: 
> >
>
http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633
> > 
> > Thank you.
> > 
> > Ola
> > 
> 
> 
> Ola - we more information to be able to help you. I
> can't even tell what 
> your problem is, or why you think that bugzilla
> report is/isn't related 
> to it. (Also, there are hundreds of bugzilla reports
> that do not apply 
> to your problem...that doesn't mean they are helpful
> to explain what is 
> going on.)
> 
> 
> Matt
> 
> 

Matt,

Please find further detail below:


GENERAL INFORMATION
===================
My understanding is that the Stuts validator is not
designed to work with classes that extend
DispatchAction (as against Action).  However, the
information I have found on the internet appears to
suggest that there is a way to make them work with
each other.  This article
(http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633)
is meant to be an explanation of howto, but on closer
examination, it did not seem to deal with the issue.

Can you please tell me how to make them work with each
other?

Thank you.

Ola.


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com

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


Re: Validator with DispatchAction...help!...newbie

Posted by Matt Bathje <mp...@ntsource.com>.
O. Oke wrote:

> Can anyone please tell me how to use the Struts
> Validator with DispatchAction.
> 
> This article in bugzilla does not seem to deal with
> the issue: 
> http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633
> 
> Thank you.
> 
> Ola
> 


Ola - we more information to be able to help you. I can't even tell what 
your problem is, or why you think that bugzilla report is/isn't related 
to it. (Also, there are hundreds of bugzilla reports that do not apply 
to your problem...that doesn't mean they are helpful to explain what is 
going on.)


Matt

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


Validator with DispatchAction...help!...newbie

Posted by "O. Oke" <re...@yahoo.co.uk>.
Can anyone please tell me how to use the Struts
Validator with DispatchAction.

This article in bugzilla does not seem to deal with
the issue: 
http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633

Thank you.

Ola




	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com

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


Struts Validator with DispatchAction...help!...newbie

Posted by "O. Oke" <re...@yahoo.co.uk>.
Can anyone please tell me how to use the Struts
Validator with DispatchAction.

This article in bugzilla does not seem to deal with
the issue: 
http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=8633

Thank you.

Ola


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com

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