简体   繁体   中英

Changing calendar value by input - Prime Faces

I have own calendar in label:

    <cust:customField label="test" forId="calendarId">
      <p:calendar id="calendarId"
                                    value etc...
                                    pattern="yyyy-MM-dd HH:mm:ss"
                                    mask="true"
                                    styleClass="ui-inputdate"
                                    readonlyInput="true"
                                    locale="pl"
                                    required="true"
      </p:calendar>
    </cust:customField>

under that I have input:

            <h:panelGroup>
                <p:inputText id="newHour">
                    <p:ajax event="change" update="calendarId"/>
                </p:inputText>
                <h:outputText value="h"/>
            </h:panelGroup>

I try to make that if anyone send value to "newHour" it would be update "HH" value in "calendarId". Is that possible?

.xhtml:

<p:inputText id="newHour" value="#{myBean.hours}>
    <p:ajax listener="#{myBean.changeHours()}" update="calendarId"/>
</p:inputText>

myBean:

private int hours;
private Date date;

public void changeHours(){
    Calendar calendar = Calendar.getInstance();   
    calendar.setTime(date);
    calendar.set(Calendar.HOUR_OF_DAY, hours);
    date = calendar.getTime();
}

//getter + setter

Note that date.setHours() would also work instead of using an extra calendar, but the constructor is deprecated because of some issues with internationalization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM