You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Kamil (JIRA)" <ji...@apache.org> on 2017/06/13 14:54:01 UTC

[jira] [Commented] (WICKET-6396) Model should provide other Optional's methods

    [ https://issues.apache.org/jira/browse/WICKET-6396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16047985#comment-16047985 ] 

Kamil commented on WICKET-6396:
-------------------------------

There are plenty of them...
for example:
{code}
public UserPage(PageParameters parameters) {
	this.model = new Model<>();
	StringValue id = parameters.get(PARAMETER_ID);
	Optional.ofNullable(id.toOptionalString())
		.filter(StringUtils::isNoneBlank)
		.flatMap(userRepository::findById)
		.ifPresent(model::setObject);
		
	User user = model.orElseThrow(() -> new UserNotFountException());
	//do something with user
}
{code}
Or something that you do many times
{code}
model.ifPresent(user -> user.setActive(false));
{code}

or
{code}
panel.setVisible(model.isPresent())
{code}

> Model should provide other Optional's methods
> ---------------------------------------------
>
>                 Key: WICKET-6396
>                 URL: https://issues.apache.org/jira/browse/WICKET-6396
>             Project: Wicket
>          Issue Type: Improvement
>    Affects Versions: 8.0.0-M6
>            Reporter: Kamil
>            Priority: Minor
>
> Model should provide
> {code}
> public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
> {code}
> {code}
> public boolean isPresent();
> {code}
> {code}
> public void ifPresent(Consumer<? super T> consumer);
> {code}
> methods for the sake of consistency with Optional API



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)