• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts and QueryString

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I'm working with Struts. I want to pass the querystring through a link tag and read the same in my action class.I'm not clear how to do the same.If anybody has answer please reply.
Thx,
Mahesh
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mahesh,
using a link tag isn't intuitively obvious - but the docs on jakarta/struts explain it.
I'm not sure if the link tag has been upgraded for the 1.1b but in 1.0 you can either include one parameter on your querystring, or you have to put all your parameters into a hashtable and specify that in your link tag.
Which struts version are you using?
 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adam,
Thx for ur reply. I'm using struts 1.0 version. I temporarily did the link through <a> tag only and the querustring part is working. But the link tag gives lot of problems I feel. As my requirement is there will number of Order numbers and the link is for order number to get the details of the same. As I've to pass the order number whichever the Client clicks the Link tag is not working properly.
Any ideas about 1.1 struts please let me know
Thx
Mahesh
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are only using one parameter in your query string and you are using 1.0? That should be easy enough. Where is the user id that you want to use? In the formbean? In a list? Post your link tag here for us to see.
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I couldn't get the following in the code
lotsTO.getLot()??
What is lotsTo in this code.
also I would like to inform you that my link is the one which is dynamic. That is I'm fetching a vector from the Action class and for each row the Order number will be different. I want to pass the order number on which the client clicks
<a href=<%="/servlet.com.wl.orders.OrderDetailsServlet?"+SONo%>><%=SONo%</a>
With the servlet this is working fine. But with link tag I'm still not clear how to do it.The above link will be there for each row of the table.
Thx,
Mahesh
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mahesh,
did you figure out your problem? Seems as if you need to use a logic:iterate tag and provide it with the iterator from the vector (without checking Im not sure if it can use the vector direct) and place your html:link tag inside the iterate tag.
Adam
 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adam,
Thx for your reply I will try that and let you the results.I think it will work.
Thx,
Mahesh
 
tumbleweed and gunslinger
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a general rule, I try to avoid using *any* scriptlets (java code) in my JSP files.
I haven't found a reason yet to justify it...
The way I handle constructing muliple value querystrings (such as rows or linked records) is as follows:
* Construct the object array in Action servlet.
* Call Form bean "set" method for object array.
* Construct object (used to create array) with an additional method called "key". The get method returns a string equiv. to the querystring you need to use based on property values of the object.
* In JSP, inside of your iterate tag, simply call the "key" property of the object using attributes in the link tag (paramid, etc.).
Shown below are snippets of code to demonstrate:
ACTION:
=======
ModelStore[]modelStores;
ModelStoresDBmodelStoreDB = new ModelStoresDB(servlet.getDebug());
modelStores = modelStoreDB.selectAllModelStores();
listForm = (ListForm) form;
listForm.setModelStores(modelStores);
FORM BEAN:
==========
public String getKey() { return (this.ID + "&templateID=" + this.templateID); }
JSP FILE:
=========
<html:link style="portletlink" forward="ModelStore.Edit" paramId="ID" paramName="ModelStore" paramProperty="key"><bean:write name="ModelStore" property="name"/></html:link>
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you find the anchor tag somewhat deficient? I always wonder why the authors didn't give it the ability to take up 5 (or more even) parameters, in the same way that you can give a struts error up to five parameters to substitute into the error message.
 
David Yutzy
tumbleweed and gunslinger
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wondered about that as well, but if you look at the error message source, you can see that they simple overloaded the same function multiple times to account for the various number of parameters.
Not a very efficient implementation, but it works.
I would like to see the paramName and paramProperty attributes be of "list" type, where you could pass in lists of params and it construct the querystring automatically.
However, our single method call works just as well and still allows you to implement pretty complex querystrings, if needed.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic