Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

showing/hiding pages using JSP/JSTL etc

Options
  • 01-12-2006 8:04am
    #1
    Registered Users Posts: 6,240 ✭✭✭


    Hi

    I have a page (jsp) and it will render one of two files .. depending on a radio button

    I'm just wondering if there is an easy way to do this in JSP without submitting the form etc

    the logic :

    Radio
    <option =page1>page 1</o>
    <option =page2>page 2</o>
    <jsp: ... render page selected .. if none selected render default.jsp>

    so when a user clicks on the radio the pageX.jsp will be rendered
    this is supposed to dynamic so when ever the user clicks the radio button the whichever option he chooses will be displayed

    I guess a javascript call to OnChange will be able to determine if the button is clicked
    but how to dynamically render the new page ..

    Any suggestions welcome!


Comments

  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    Why change the page with a radio button? Is it a requirement for the application your building?

    My guess would be that you're looking for an onClick event handler. something like
    <input type="radio" id="someradiooption" onClick="document.location.href='thispage.html'" />
    

    The only way I can think of rendering the page based on input criteria WITHOUT a form submission is AJAX. This seems over complicated tho.

    Can you explain what your app is trying to do? Maybe some sample JSP? Where does JSTL come into the equation?


  • Registered Users Posts: 6,240 ✭✭✭hussey


    Yeah it's in the specs ...

    they want something fancy .. just trying to avoid AJAX as too much work for something simple

    Basicially when you get to Create a client .. you have two types of client
    lets say A & B

    A has a different set of fields than B

    so have a radio button that says ..
    do you want to create [radio page=A.jsp] Type A, [radio=B.jsp] Type B

    when you click on A I wanted to show the fields (which is in A.jsp) and when click on B .. show B.jsp

    It was meant to be smooth, as it it would render on fly rather than submit pages etc .. it's not a big deal, probably will go with javascript thing

    JSTL .. I was just using this throughout my app .. just wondering if there was a function that could be used with <jsp:include> etc


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    If "they" think javascript is fancy.. hmm.. I wont continue that.

    I understand what you're saying now..

    Try a toggle. that's pretty neat. So keep both of the JSPs in separate files. And use javascript to toggle div visibility.

    Then do this, in the head of the statement.
    <script language="javascript">
    function toggle(id, show){
    if(show){
    document.getElementById(id).style.visibility = 'visible';
    } else {
    document.getElementById(id).style.visibility = 'hidden';
    }
    }
    
    function hideAll(){ // function to hideAll divs..
    if(document.all){
      toggle("pageA",false);
      toggle("pageB",false);
    }
    </script>
    
    Then in the main body of your page.
    <div id="page_toggler"><!-- :) //-->
    <input type="radio" id="divA" onClick="toggle('pageA',true);toggle('pageB',false);" />
    
    <input type="radio" id="divB" onClick="toggle('pageB',true);toggle('pageA',false);" />
    </div>
    <div id="pageA">
      <jsp:include page="pageA.jsp" flush="true" />
    </div>
    <div id="pageB">
      <jsp:include page="pageB.jsp" flush="true" />
    </div>
    <script language="javascript">hideAll()</script>
    </div>
    

    That should do it. However if your includes are weighty, you might see them flash temporarily before they are hidden. There is a way of preventing this from happening but I cant remember. And I just moved to AJAX, so .. dont need it.

    Let me know how you get on..


Advertisement