4 Replies Latest reply on Jun 26, 2009 5:57 PM by daxxy

    Neither s:link nor s:button giving correct results with onclick

    daxxy

      I am tearing my hair out over what I think must be a simple problem.


      I'm trying to add a button that, when you click it, takes you to an external web page. I think this is the HTML I want, but I can't figure out how to get Seam to render this HTML:


      <button onclick="location.href='http://smc.ba.ssa.gov'" type="button">SMC</button>


      I would simply use the HTML, but I want the button to match all the others.  And anyway, this should work, right??

      I have tried
      <s:button> and <s:link> and the code is never rendered correctly.


      Here is the rendering of the s:link :


      <a href="/newOnd/ONDResultPage.seam" onclick="location.href='http://smc.ba.ssa.gov'">SMC</a>


      Here is the rendering of the s:button:


      <input onclick="location.href='http://smc.ba.ssa.gov'; location.href='/newOnd/ONDResultPage.seam; return false;" value="SMC" type="button" />


      I have seen a previous forum posting advising people to stay away from s:button and style your s:link as a button. Fine. I'm happy to do that. But s:link isn't working either!  Argh. This is making me nuts.


      Using the latest and greatest Seam.


      TDR

        • 1. Re: Neither s:link nor s:button giving correct results with onclick
          sherkan777

          Hi,
          Why do you want to use s:button if u can do all u want by


          <button...>



          without changing your code, also with conversation support.


          • 2. Re: Neither s:link nor s:button giving correct results with onclick
            swd847

            what happens if you put a return false after your location.href?

            • 3. Re: Neither s:link nor s:button giving correct results with onclick
              daxxy

              Why don't I just use the button tag?  Um, I guess because I wanted the button to be styled like the other buttons and I didn't know how to do it otherwise.  However, I really cannot get anything else to work so I guess I'm going to have to figure out how to style it to look like the others.


              I added return false after my location.href and still it did not work.  The button tag also did not work with it.


              I just realized I forgot to include in my original posting the code I tried.  I must have deleted it accidentally.


              Here it is FWIW:


              <button onclick="location.href='http://smc.ba.ssa.gov'" type="button" >SMC</button>
              <s:button value="SMC" onclick="location.href='http://smc.ba.ssa.gov'" />
              <s:link  value="SMC" onclick="location.href='http://smc.ba.ssa.gov'" />


              • 4. Re: Neither s:link nor s:button giving correct results with onclick
                daxxy

                I realized I needed conditional rendering so here is what I finally decided on:


                <h:outputLink rendered="#{_device.smc}"
                                                             value="http://smc.ba.ssa.gov">
                                                             <button type="button">SMC</button>
                                                        </h:outputLink>


                I still need to figure out how to style the button to look like a richfaces component.