How to use <p:spinner with attribut max=current year - jsf

I want to use <p:spinner where attribut max equals current year in jsf but without using backend bean.
I use jsf 2.
thanks.

You can use #{now} from OmniFaces http://showcase.omnifaces.org/managedbeans/now
Example:
#{of:formatDate(now, 'yyyy')}

Related

How to increment +1 day in mindate of <p:calendar>

I need to add +1 day in mindate (or) I don't want to accept the condition as in the image, effective date and expiration date as same.
Here is the code:
<p:calendar id="Jurisdiction_Expiration_Date"
styleClass="calender_style" pattern="MM/dd/yyyy"
required="true" size="10" readonlyInput="true" showOn="both"
mindate="#{ApplicationManagedBean23.saveRequestMap['JurisdictionEffectiveDate']}">
Couple of things here:
p:calendar is deprecated. Please use p:datePicker.
Use value-binding as demonstrated in the basic example: https://www.primefaces.org/showcase/ui/input/datepicker/datePickerJava8.xhtml
Use a modern Java 8 date (only) type like LocalDate which makes it easy to add a day: localDate.plusDays(1).
Add an Ajax listener where you set the min date based on the changed value and update the component with the min date (which you bind to the bean property).
Make sure you are using the correct bean scope.
See also:
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
How to choose the right bean scope?

How to add tooltip to f:selectItems

For example the f:selectItems component doesn't support the title attribute in some versions of JSF.
Would it be possible to replace JSF Components by their plain HTML counterparts using JSFC and do something like this?
<select jsfc="h:selectOneMenu" value="#{cc.data}">
<option jsfc="f:selectItems" value="${cc.listItems}" var="item" title="#{item.tooltip}"></option>
</select>
instead of
<h:selectOneMenu value="#{cc.data}">
<f:selectItems value="#{cc.listItems}" />
</h:selectOneMenu>
Doing exactly so, replacing the latter by the above, I'm getting "<f:converter> Parent not an instance of ValueHolder: javax.faces.component.html.HtmlPanelGroup" Facelet TagExceptions
Would it be possible to replace JSF Components by their plain HTML counterparts using JSFC and do something like this
Nope. Ultimately, such a HTML element with jsfc attribute will be turned into a true JSF component in the JSF component tree and only the attributes supported by the component in question would be parsed and set as component attribute. The title attribute isn't among the supported attributes of UISelectItem component. I'm not sure what exactly you mean with "some versions of JSF". The standard JSF API already doesn't support it in first place. JSF spec issue 529 describes this shortcoming and is currently still open.
If you're using JSF 2.2, make use of passthrough attributes. You only need to replace <f:selectItems> by <c:forEach><f:selectItem>, see also Using f:selectItems var in passtrough attribute
<... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<c:forEach value="#{bean.items}" var="item">
<f:selectItem itemValue="#{item}" a:title="#{item.tooltip}" />
</c:forEach>
Based on your question history you seem to be not using JSF 2.2 yet. If you can't upgrade, you basically need a custom renderer for <h:selectOneMenu>.
While creating the custom renderer, you could make use of the unused(!) description property of the UISelectItem class. I've answered this before on a similar question targeted at <p:selectManyCheckbox>: Primefaces tooltip for p:selectManyCheckbox or other p:selectMany*/One*.
<f:selectItems ... var="item" itemDescription="#{item.tooltip}" />
Noted should be that creating the custom renderer for <h:selectOneMenu> is a pain, particularly if you intend to be JSF implementation independent. Theoretically, a custom ResponseWriter should be able to catch this, but unfortunately, the <h:selectOneMenu> only passes itself when writing <option>, instead of the UISelectItem in question.
In my case (JSF 2.2 / Mojarra 2.2.14), itemDescription worked out of the box. I.e:
<c:forEach items="#{bean.items}" var="item">
<f:selectItem itemValue="#{item}" itemLabel="#{item}" itemDescription="#{item.tooltip}" />
</c:forEach>

How to get current year in jsf without using backend bean [duplicate]

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.
<div class="leftSide">Today's date #{currentDate}</div>
or
<f:facet name="header">
<h:outputText value="Today's date" />
</f:facet>
<h:outputText value="#currentDate">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
You could register an instance of java.util.Date as a request scoped bean in faces-config.xml.
<managed-bean>
<managed-bean-name>currentDate</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
This way it's available as #{currentDate} without the need for a custom backing bean class.
Update: the JSF utility library OmniFaces has such a bean already registered as #{now}. So if you happen to use OmniFaces already, you can just make use of it directly.
<h:outputText value="#{now}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
In JSF you could use the implicit EL object session that provides access to the current HttpSession. The HttpSession#getLastAccessedTime time ...
... returns the last time the client sent a request associated with this
session, as the number of milliseconds since midnight January 1, 1970
GMT, and marked by the time the container received the request.
So you could use the following code snippet in your facelet:
<h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
This will be server time and may differ from client time with respect to different time zones.
But you could also use a javascript solution, as discussed here:
How do I get the current date in JavaScript?
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 :
<p:calendar id="myCalendar" pattern="dd/MM/yyyy"
value="#{mybean.myDate}" maxdate="#{now}"/>
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.
You can use the tag which PrimeFaces provide.
<p:clock pattern="HH:mm:ss dd-MM-yyyy"/>

How get row index of <ace:dataTable> in every row?

In searching I found that we can do something with rowStateVar or rowIndex attributes of <ace:datatable>, but how?
I tried using <h:outputText value="#{myDataTableVar.rowIndex}"> but it shows an error message that myDataTableVar has no property rowIndex.
For a component library independent way, just use UIData#getRowIndex() as every component library specific datatable extends from this base component.
In the below example, x: can be anything: standard JSF h:, ICEfaces ice: or ace:, PrimeFaces p:, RichFaces rich:, etc.
<x:dataTable binding="#{table}" ...>
<x:column>#{table.rowIndex}</x:column>
</x:dataTable>
Note: the binding="#{table}" is as-is! You don't need to bind it to some managed bean property.
I found the solution <ace:datatable id='tbl' rowIndexVar="row"> and then just print like that <h:outputtext value="#{row}">Very simple
First, set varStatus:
<ice:dataTable varStatus="status">
An then, inside that dataTable, use:
#{status.index}

How do I dynamically include the backing bean value in jsf 1.2

Hi i have the following code
creatPage1.jsp
<h:inputText id="inputId1" value="#{createPage.item.name}"/>
i have updatePage1.jsp
<h:inputText id="inputId1" value="#{updatePage.item.name}"/>
I want to be able to do include (via ui:include or jsp:include) and be able to pass in the value dynamically (the base backing bean to be createPage or updatePage).
So the result should be
<ui:include src="Page1.jsp" basebean="#{createPage}"/>
Page1.jsp
<h:inputText id="inputId1" value="#{baseBean.item.name}"/>
Whats the best way to do this in jsf?
You can use ui:param :
<ui:include src="Page1.jsp">
<ui:param name="basebean" value="#{createPage}"/>
</ui:include>
You will probably need to create your own custom tag. Check this out: http://www.ibm.com/developerworks/java/library/j-facelets/

Resources