Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Spring-Thymeleaf How to invoke with EL an action method from a Bean

 
Ranch Hand
Posts: 45
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Spring/SpringMVC 5.x version, with Thymeleaf and Bootstrap on Tomcat server.

I need to ask something that maybe it might look to you very "st@pid" question.

In my html view I have the following button or a link:



I don't need to submit something, so I just use a simple button, so I think I don't need any form for it (except if I need for this).

In this html view (because of the thymeleaf library I added in the html tag), I need to add somehow, (but I don't know how), to this button or in the link, an expression of Spring EL or Thymeleaf EL, so I can invoke a method from a Spring bean, that I passed in the view, via a model which I added in my controller, e.g.:



If this is not understandable I can update my question with some code (I believe that Spring developers understand what I am talking about).

I don't know how to pass this expression. What attribute of button or link tag to use? I used "action" attribute for the button:



or "href" attribute in the link tag:



Very significant info

When I started my tomcat running the page, the actions in the EL are run successfuly on the load of the page. When I pressed the button or the link nothing happened.

I know that I cannot use "onclick" attribute because there we write JS code. But I need to run Java Spring code.

Any ideas about solving my problem?
Thanks in advance
 
Saloon Keeper
Posts: 24865
174
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
You seem to be consistently missing the closing brace in your EL samples. Without it, the EL won't parse properly and so I wouldn't expect it to work.

I recently did something similar to this on a JSF View Template and it worked well for me.
 
Thomas Mylonas
Ranch Hand
Posts: 45
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim

No I have writing these snippets via smartphone. I missed them accidentally when describing the issue.
In my code there are these brackets.

Well, I found solution yesterday in a 80% and I will post what I did little bit later.
If I am in a hurry I make mistake writing the solution.

Thanks a lot
Regards
 
Thomas Mylonas
Ranch Hand
Posts: 45
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After searching and googling, I did not use a button for this job. Button needs a form to work.

That is why I used a link, where the method from the bean is called like a charm, like the following snippet:



And next is a snippet from the bean:



So, the code from the bean IS invoked successfuly.
I guess this is the solution to my issue.
 
reply
    Bookmark Topic Watch Topic
  • New Topic