如何使用 JavaScript 从 JSF 页面的输入文本中提取值

发布于 2024-12-13 19:45:05 字数 3319 浏览 2 评论 0原文

大家好,我尝试使用 document.getElementById("someid") 从 JSF 页面的字段中提取值

,这是实际的代码

      <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;   
}

告诉我我在这里做错了什么?

hello everyone i am try to extract value from the field of a JSF page using document.getElementById("someid")

here is the actual code

      <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>

here is my JS code. in which i am just checking what are the value in the field that is filled by user.

 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;   
}

tell me what i am doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

已下线请稍等 2024-12-20 19:45:05

在 JavaScript 中,要从 HTMLInputElement 获取值,请使用其值字段:

alert(dat.value +" time "+day.value);

In JavaScript to get values from HTMLInputElement use its value field:

alert(dat.value +" time "+day.value);
愿得七秒忆 2024-12-20 19:45:05
<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
<h:form  id="myform">
 <h:inputText  id="name" value="#{beanClass.name}" 
                a:placeholder="Enter Client Title"> </h:inputText>
</h:form>

This is a small example of jsf inputText. Now I will write javascript code to get the value of the above jsf component:

    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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文