jakartaee / jakartaee/faces

Default value for viewParam

Open
#1,341 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Components/Renderers Priority: Major Type: Improvement
Dominant language
Java
Stars
127
Forks
59
Avg merge
23h
Merged PRs (30d)
7

Description

What about allowing the definition of a default value for a view-parameter?

**Example**

Defining number of displayed items (pagination feature) as a view-parameter but still keeping default value within xhtml and not java bean.

Following example is a very clean approach provinding a default value.

```

```

Currently there are two workarounds which have no clean separation between markup and java code:

**Workaround 1**

Passing the default value to bean.

```

```
```
private int pageSize;

public void initPreRenderView(int pageSize)
{
if (this.pageSize == 0)
this.pageSize == pageSize;
}
```

**Workaround 2**

Hardcoding the default value in bean. But markup should be responsible and not bean.

```

```
```
private int pageSize = 10;
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the XHTML f:viewParam value is processed when the request omits pageSize. The change is complete when a declared default such as 10 is used without Java-bean initialization, while an explicitly supplied parameter still takes precedence.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.