join() doesnt allow nulls
ijabz opened this issue · comments
I have this code
private DomContent getPurchasedDetails(String purchaseDateValue, String expiryDateValue)
{
return join(
tr(
td(TextLabel.ABOUT_LICENSED_TO.getMsg()),
td(addDisabledText(LicensePreferences.getInstance().getLicenseEmail())).attr(Html.COLS,"2")
),
iff(purchaseDateValue!=null,
tr(
td(TextLabel.ABOUT_PURCHASEDATE.getMsg()),
td(addDisabledText(purchaseDateValue)).attr(Html.COLS,"2")
)
),
iff(expiryDateValue!=null,
tr(
td(TextLabel.ABOUT_VERSIONEXPIRY.getMsg()),
td(addDisabledText(expiryDateValue)).attr(Html.COLS,"2")
)
)
);
}
}
```but it failed today because iff was evaluating false
java.lang.RuntimeException: You can only join DomContent and String objects
at j2html.tags.DomContentJoiner.join(DomContentJoiner.java:13)
at j2html.TagCreator.join(TagCreator.java:61)
at com.jthink.songkong.server.page.AboutPage.getPurchasedDetails(AboutPage.java:186)
at com.jthink.songkong.server.page.AboutPage.createPage(AboutPage.java:135)
at com.jthink.songkong.server.callback.ServerAbout.processRoute(ServerAbout.java:23)
at com.jthink.songkong.server.CmdRemote.lambda$null$10(CmdRemote.java:97)
at spark.RouteImpl$1.handle(RouteImpl.java:72)
at spark.http.matching.Routes.execute(Routes.java:61)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:530)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:347)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:256)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
at java.lang.Thread.run(Thread.java:745)
Might be nicer if join() did not complain about adding null`especially since I cannot just create join() outside of loop and use a java if and then with() because join() does not support with(). Im actually only using join as a way to return multiple elements that arent the direct children of a container element
i.e https://stackoverflow.com/questions/48421009/how-to-use-j2html-when-have-a-method-that-needs-to-return-multiple-tags
@ijabz I'm actually only using join as a way to return multiple elements that aren't the direct children of a container element
Yeah, that's not how it was intended to be used, but I like the creativity. Do you want to create a PR which makes join
ignore null values?
This has been released in 1.3.0 now