Как извлечь значение из входного текста страницы JSF, используя JavaScript - PullRequest
1 голос
/ 07 ноября 2011

Привет всем, я пытаюсь извлечь значение из поля страницы JSF, используя document.getElementById ("someid")

вот фактический код

      <h:form id="hell">
                <h:panelGrid columns="12" border="0">
                    <h:outputLabel>Airlines</h:outputLabel>
                    <h:selectOneMenu  value="#{planeMngr.PM.airline_no}" styleClass="inputbox" style="width:150px">
                        <f:selectItems value="#{projectUtil.airlineList}" var="AList" itemLabel="#{AList.name}" itemValue="#{AList.name}"/>
                    </h:selectOneMenu>
                    <h:outputLabel>Source</h:outputLabel>
                    <h:selectOneMenu  value="#{planeMngr.PM.source}" styleClass="inputbox" style="width:150px">
                        <f:selectItems value="#{projectUtil.contyList}" var="RList" itemLabel="#{RList.country_Name}" itemValue="#{RList.country_Name}"/>
                    </h:selectOneMenu>
                    <h:outputLabel>Destination</h:outputLabel>
                    <h:selectOneMenu value="#{planeMngr.PM.destination}" styleClass="inputbox" style="width:150px">
                        <f:selectItems value="#{projectUtil.contyList}" var="RList" itemValue="#{RList.country_Name}"/>
                    </h:selectOneMenu>

                    <h:outputLabel>Departure Date</h:outputLabel>
                    <h:inputText id ="depday" value="#{planeMngr.PM.departure_date}" label="dd/mm/yyyy" >
                        <f:convertDateTime pattern="dd/MM/yyyy" dateStyle="full" ></f:convertDateTime>

                    </h:inputText>



                    <h:outputLabel>Departure Time </h:outputLabel>
                    <h:inputText id="deptime" value="#{planeMngr.PM.departure_time}" label="HH:MM"  >
                        <f:convertDateTime pattern="HH:mm"></f:convertDateTime>
                    </h:inputText>



                    <h:outputLabel value="Status"/>
                    <h:selectOneMenu  label="Status" value="#{planeMngr.PM.status}">
                        <f:selectItem  itemLabel="PreFlight" itemValue="PreFlight" />
                        <f:selectItem  itemLabel="Open" itemValue="Open" />
                        <f:selectItem  itemLabel="Restricted CheckIn" itemValue="Restricted_CheckIn" />
                        <f:selectItem  itemLabel="Restricted" itemValue="Restricted" />
                        <f:selectItem  itemLabel="Closed" itemValue="Closed" />
                        <f:selectItem  itemLabel="Released" itemValue="Released" />
                    </h:selectOneMenu>
                </h:panelGrid>
                <h:commandButton onclick="return datevalidate()" action="#{planeMngr.ADD}" value="save" ></h:commandButton>
            </h:form>

вот мой код JS. в котором я просто проверяю, какое значение имеет поле, заполненное пользователем.

 function datevalidate()
{
  var dat = document.getElementById("hell:deptime");
var day = document.getElementById("hell:depday");
alert(dat +" time "+day); // this gives "[object HTMLInputElement] time [object HTMLInputElement]" as an out put
return false;   
}

скажи мне, что я здесь не так делаю?

Ответы [ 2 ]

1 голос
/ 07 ноября 2011

В JavaScript для получения значений из HTMLInputElement используйте его поле значения:

alert(dat.value +" time "+day.value);
0 голосов
/ 11 декабря 2018
<h:form  id="myform">
 <h:inputText  id="name" value="#{beanClass.name}" 
                a:placeholder="Enter Client Title"> </h:inputText>
</h:form>

Это небольшой пример jsf inputText. Теперь я напишу код JavaScript, чтобы получить значение указанного выше компонента jsf:

    var x = document.getElementById('myform:name').value; //here x will be of string type

   var y= parseInt(x,10); //here we converted x into Integer type and can do the 
                           //arithmetic operations as well
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...