jakartaee / jakartaee/faces

Provide mechanism for component to declare scoped variables

Open
#1,048 5 comments 0 reactions 0 assignees View on GitHub
Component: Components/Renderers Priority: Minor Type: New Feature
Dominant language
Java
Stars
127
Forks
59
Avg merge
23h
Merged PRs (30d)
7

Description

In JSF a component can put a variable into a scope to make it usable for its child components, or possibly other components on the page.

E.g.

```

```

In this example the ui:repeat component selects a value from someBean.items and makes that available under the name item.

In order for tools to validate the correctness of the item.name expression, they currently make use of hardcoded knowledge of what well known components do. This means that components from libraries that are not explicitly supported by such tools can't be validated. Custom components made by users are thus never validated.

I would like to propose adding a mechanism to JSF for components to declare they make (scoped) variables available.

E.g.

```
@FacesComponent("components.CustomComponent")
public class CustomComponent extends UIComponentBase {

@Attribute
@VariableName(type="#{attributes.value[0]}" scope="component")
private String var;

@Attribute
@VariableSource
private List value;
```

In this example, the component declares that the var attribute is the name for data that is made available during the 'scope of the component' and that the type of this data is an element from the value attribute.

Additionally, it should also be possible that a fixed type is specified, e.g:

```
@FacesComponent("components.CustomComponent")
public class CustomComponent extends UIComponentBase {

@Attribute
@VariableName(type="com.example.SomeType" scope="component")
private String var;
```

Of course the given syntax is just a quick sketch of the idea. Maybe @VariableExportName is a better name, @VariableSource might not be needed, etc.

This issue is somewhat related to #594

Contributor guide

Open the contributing guide

Research direction

Start with the issue description and related issue #594, then assess how JSF components currently expose scoped variables to tools. Done means agreeing on a concrete declaration mechanism, including variable names, scopes, and type sources, rather than only the sketch shown here.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.