You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Sven Meier (JIRA)" <ji...@apache.org> on 2017/08/18 21:35:00 UTC
[jira] [Comment Edited] (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=16056203#comment-16056203 ]
Sven Meier edited comment on WICKET-6396 at 8/18/17 9:34 PM:
-------------------------------------------------------------
@eximius Your examples didn't convince me that any more method is necessary.
Yes, #isPresent() could be useful. But the other methods should not be in IModel: Wicket will not call them and your code can equally well just work without any model involved:
{code}
public UserPage(PageParameters parameters) {
StringValue id = parameters.get(PARAMETER_ID);
setModel(Model.of(
Optional.ofNullable(id.toOptionalString())
.filter(StringUtils::isNoneBlank)
.flatMap(userRepository::findById)
.orElseThrow(() -> new UserNotFoundException())
));
{code}
was (Author: svenmeier):
@eximius Your examples didn't convince me that any more method is necessary.
Yes, #isPresent() could be useful. But the other methods should not be in IModel: Wicket will not call them and your code can equally well just work without any model involved:
{code}
public UserPage(PageParameters parameters) {
StringValue id = parameters.get(PARAMETER_ID);
Optional.ofNullable(id.toOptionalString())
.filter(StringUtils::isNoneBlank)
.flatMap(userRepository::findById)
.ifPresent(user -> setModel(Model.of(user))
.orElseThrow(() -> new UserNotFountException());
{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)