Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can JTE have the directive function #420

Open
leeaee opened this issue Jan 16, 2025 · 3 comments
Open

Can JTE have the directive function #420

leeaee opened this issue Jan 16, 2025 · 3 comments
Labels
question Further information is requested

Comments

@leeaee
Copy link

leeaee commented Jan 16, 2025

I have a custom tag that corresponds to a Java class behind it, which can return custom data. Currently, the sidebar menu is returned by the server, and I hope to automatically retrieve values from a class to handle some common data.

@casid
Copy link
Owner

casid commented Jan 18, 2025

Hi @leeaee, I'm not entirely sure what problem you want to solve.

Can you maybe provide a bit more context, or some example jte+Java Code?

@casid casid added the question Further information is requested label Jan 18, 2025
@leeaee
Copy link
Author

leeaee commented Jan 30, 2025

Hi @casid,

I encountered a situation while using JTE that I'm unsure how to handle.

For example, I have customized a JTE select template as shown below:

<select id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

Current Approach

Based on my understanding, the typical approach for using this template is as follows:

Pass the select option values from Spring:

model.addAttribute("options", optionList);

Use the select template in the desired pages.

Problem

The issue arises when this select element is required on multiple pages. In this case, I would have to pass the select options through many Spring methods, wherever the select element is used.

Desired Solution

What I would like to achieve is the ability to automatically retrieve the select options from a single source or a custom tag class whenever the select template is used in JTE. This would help simplify backend code management and avoid having to pass the options repeatedly.

Question

Is there a way to use JTE similarly to how Freemarker uses directives? If so, this would be a perfect solution.

For reference: Freemarker Directives

@casid
Copy link
Owner

casid commented Jan 31, 2025

Hey @leeaee,

with jte, there are two options to access data from a template, without the need to pass a parameter to it.

Static method, that is called by the template.

Static method, that is called by the template, with a thread local behind it (if you need that data on a request base, e.g. localized stuff etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants