Display Current Date on JSF Page

后端 未结 4 426
粉色の甜心
粉色の甜心 2020-12-02 17:13

Is it possible to display the current date (today\'s) in JSF without using a backing bean?

I have the following code snippet , but it didn\'t work out.



        
4条回答
  •  抹茶落季
    2020-12-02 17:41

    Or you could do it using Omnifaces. I'm surprised BalusC hasn't told you about this solution (I think he's a great Omnifaces contributor). Maybe it's because using Omnifaces just to display a simple date in a page might be an overkill to some.

    Anyway, if your project already uses Omnifaces, there are 2 managed beans exposed by default and one in particular that you may find handy. As per the tag documentation specifies, once Omnifaces is added to your project, you can use the #{now} managed bean.

    For instance, to set a Primefaces calendar's max date, I just wrote the following :

        
    

    I guess the #{now} managed bean can be used in many more situations, and probably yours as well.

    If your project does not use Omnifaces yet, I suggest you look at their spec and see how helpful it could be for you. For instance, I'm using their validateOrder tag to make sure two dates are properly ordered.

提交回复
热议问题