Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:Link not able to retrieve ActionForward

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All

I have following snippets of my struts-config.xml file
and the jsp file which is using html:link tag


Struts-Config
<action path="/QGPARAMETERS"
type="com.symantec.qg.action.QGParametersAction"
name="QGPARAMETERS">
<forward name="success" path="QG_PARAMETERS_TILE"/>
<forward name="qgParametersChanged" path="HOMEPAGE_TILE"/>
<forward name="forwardName" path="/some.jsp"/>
</action>


JSP
<html:form action="/QGPARAMETERS">
<table border=0 width="100%">
<tr>
<td class="leftnav-primary" width = "75%">
<html:link forward="symantecExpress" >
<font size='2' color = 'black'> Express</font>
</html:link><br>
<html:link forward="forwardName">
<font size='2' color = 'black'>Government</font>
</html:link><br>
<html:link forward="forwardName">
<font size='2' color = 'black'>Academic</font>
</html:link><br>
<html:link forward="forwardName">
<font size='2' color = 'black'>Rewards</font>
</html:link>
</td>
<td>
</td>
</tr>
</table>
</html:form>



but I am gretting Cannot retrieve ActionForward named forwardName' Error
If anyone has idea on what could be going wrong and can share that will be of great help
Thanks in advance

:roll: :roll:
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


forward identifies the name of the global forward element that
will receive control of the forwarded request not forward within action tag.

So you have to use global-forward tag in struts-config.xml



Remember one more thing in xml files, the position of tags are also very important.

Naseem
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch
I have one more query
Is there any way we can set a request parameter value in a bean using the

html:link tag I know paramId and paramName are there but do we have to define a bean in struts-config.xml file whose name matched that of paramName

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do we have to define a bean in struts-config.xml file whose name matched that of paramName

No. The bean just has to be in some scope (request, session, application, or page).

So, for this tag:

<html:link forward="myForward" paramId="parm1" paramName="myBean" paramProperty="foo" />

As long as you have a bean named myBean in some scope (request, for example) Struts will find it and execute getFoo() on it to retrieve the value to be placed in parm1 of the url.
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply
It will be great if you clarify one more doubt that do we need to define bean usig bean tags of struts or bean tag of jsps
<jsp:useBean> shall be preferred or <bean efine name=myBean scope=request> should suffice



Thanks in advance



:roll:
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither.

Just put the bean in a scope. This would normally be done in an action class prior to forwarding to the page.

Example:

in your Action class:

MyBean myBean = new MyBean();
myBean.setFoo("whatever");
request.setAttribute("myBean", myBean);

in your JSP:

<html:link forward="myForward" paramId="parm1" paramName="myBean" paramProperty="foo" />

In this example, you don't need either a <jsp:useBean> or a <bean:define> The bean has alread been put in request scope by the action.

If you want to put the bean in scope in the JSP itself, you can do that with either a <jsp:usebean> or a <bean:define> tag. Either will work, just take your choice. Once the bean is in a scope, the <html:link> tag will find it.

Example: The following would call a link with ?parm1=foo.

<bean:define id="myStringBean" value="foo" />
<html:link forward="myForward" paramId="parm1" paramName="myStringBean" />
[ July 23, 2006: Message edited by: Merrill Higginson ]
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton again Merril
I have one last question (Please correct me if I am wrong)

the paramid and paramvalue tags on html:link sets the value of bean only on clicking the link right?

Our database is down so I couldn't check it.

Please confirm if possible
Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are asking whether the forward specified in <html:link> is permanently changed by the paramId and ParamValue parameters, the answer is no, it is not. It is modified for this link only.
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I was asking if we have multiple html:link on a jsp and each link tries to set a diff value to paramId parameter so those values will be set only on clicking of that link


<html:link forward="myForward" paramId="parm1" paramName="myBean" paramProperty="foo" >show 1 </html:link>

<html:link forward="myForward" paramId="parm2" paramName="myBean" paramProperty="foo" >show 2 </html:link>


If he clicks link show 1 then foo property will be set to value parm1
and if he clicks link show 2 then it will be set to parm2

Correct me if I am wrong

Thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic