• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Problem with JSP include and Model-2 Framework....

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Pals,I have a JSP called JSPLeft.jsp which has 5 buttons
on it and it's included on every page using <jsp:include > tag.
Now, because each including(Parent)JSP has it's unique form name
as in <Form name="formName" action="Controller"> .The form name is used within a Javascript function ,which is invoked on clicking any button on these JSPs.
This function assigns a value(The Destination page of the button)
to the hidden field which is checked in the dispatcher within the
controller servlet.So,i have this statement in my Function for each button:
document.formName.hiddenFieldName.value="DestinationPage.jsp";
Question:
The problem is how can i include the same JSPLeft.jsp on all my JSP pages since these Parent(including) JSPs have their own uniques names and a Form can only have a name .The Script below appears in all pages included on a Parent page.
<SCRIPT language="Javascript">

function setDestinationPage(varName)
{
switch(varName)
{
case 'buttonOne':
document.formName.hiddenFieldName.value="DestinationPage1.jsp";
break;
case 'buttonTwo':
document.formName.hiddenFieldName.value="DestinationPage2.jsp";
break;
..................................................

}
}

</SCRIPT>
Please all ideas are welcomed.Cheers.
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, this is not a good answer but, why not change each pages' form to have the same name?
I used to do something similar to yours. A frame of buttons which upon clicking...submit via JS the form on another frame.

------------------
Thank you.
- Simon See
[email protected]
-after office hours-
necro-mani-cide
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not define a scripting variable that holds the formName in the Parent including page ... then use an include directive instead of jsp:include to include JSPLeft.jsp ... you would then reference the form name variable in the JS function using an expression like ..


document.<%=parentFormName%>.hiddenFieldName.value="DestinationPage1.jsp";

 
Gabriel Fox
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks A lot Simon & Bill.Your ideas are just OKAY.
1.The idea of making all forms the same name was the first to cross my mind ,but i thought that was crude.But, after analysing
the flow of the application i saw that uniqueness in form names is of no special importance.Since,a form is processed at a time on the front-end and all i've been using the formName for is dispatching via ControllerServlet.That seems the last resort to
avoid complications in adding scriplets on all existing (functioning) pages.
2.Bill, Your idea is superb .That is what i'm doing at the moment,but in a slightly different way.Because i am making use
of the dynamic include <jsp:include > ,which includes the variable holding the formname to the included page at compilation time.I need to add chunks of codes on individual JSPs.The <%@include> would have help as U said.But,NOT WHEN YOUR PAGES(included pages) have duplicate declaration of say,variables
or methods or <jsp:useBean>for Different Logic(or processing).
The <%@include> is fussy in that case since inclusion is done at
translation time.
3.The use of the JSP expression tag ie <%=variableName%> within a JavaScript Function is what i have not used before.I think it's going to be very handy.Cheers.
Thanks once again. I am still out for ideas.Enjoy!!!
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic