我是java脚本的新手。 我尝试使用java脚本从p:dialog获取值,但我无法获得值,我在下面发布我的代码,这用于前端验证。帮我解决这个问题。
home.xhtml
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:b="http://bootsfaces.net/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<f:view contentType="text/html" locale="en">
<pe:head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<link href="../../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../../css/css.css" ></link>
<h:outputScript library="primefaces" name="../../js/jquery-1.11.2.min.js" />
<script>
function myvalidation(obj){
var bla = document.getElementById(obj).value
alert("hai"+bla)//hai undefined
}
function myvalidation1(){
var bla = $('#obj').val();
alert("hai1"+bla)//hai undefined
}
</script>
</pe:head>
<pe:layout fullPage="true">
<pe:layoutPane position="north" closable="false" resizable="false" size="14%">
<h:form>
<p:graphicImage value="/images/header.jpg" width="100%" height="100%"></p:graphicImage>
</h:form>
</pe:layoutPane>
<pe:layoutPane header="Dashboard" position="west" size="20%" resizable="true">
<f:facet name="header">
Main Menu
</f:facet>
<h:form>
<ui:include src="../../menu.xhtml" />
</h:form>
</pe:layoutPane>
<pe:layoutPane position="center" size="80%" resizable="true" id="centerIDContent" closable="false">
<h:form enctype="multipart/form-data" id="center_content">
<ui:insert name="content"></ui:insert>
</h:form>
</pe:layoutPane>
</pe:layout>
</h:body>
</f:view>
</ui:composition>
下面提到代码(home1.xhtml),我使用两个对话框
home1.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" template="../../pages/xhtml/home.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:b="http://bootsfaces.net/ui"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<p:commandLink styleClass="image-align" action="#{FormMB.loadDialogBox}" update=":center_content:dialogPanel" oncomplete="PF('Dialog').show();">
<p:graphicImage value="/images/registration.jpg"></p:graphicImage>
</p:commandLink>
<p:commandLink styleClass="image-align" action="#{FormMB.loadDialogBox1}" update=":center_content:dialogPanel1" oncomplete="PF('Dialog1').show();">
<p:graphicImage value="/images/view.jpg"></p:graphicImage>
</p:commandLink>
<p:dialog header="Registration" id="dlg" appendTo="@(body)" widgetVar="Dialog" modal="true" showEffect="fade" hideEffect="fade" width="75%" resizable="false" visible="#{FormMB.vendorFlag}">
<p:outputPanel id="dialogPanel">
<h:form id="ven">
<p:panelGrid columns="5" style="text-align:left" columnClasses="ui-grid-col-2,ui-grid-col-3,ui-grid-col-1,ui-grid-col-2,ui-grid-col-3" layout="grid" styleClass="ui-panelgrid-blank">
<h:outputText class="label_ui" value="Firm Name " for="vfname"/>
<p:inputText value="#{FormMB.number}" id="vfname" styleClass="inputTxt" onblur="myvalidation('center_content:dialogPanel:vfname')">
<p:ajax event="valueChange" process="@this" immediate="true" update="@all"></p:ajax>
</p:inputText>
</p:panelGrid>
<br></br>
<center><p:commandButton value="Submit" process="@this" immediate="true" action="#{FormMB.Register}" oncomplete="PF('Dialog').hide();" ></p:commandButton>
</center>
</h:form>
</p:outputPanel>
</p:dialog>
<p:dialog header="Registration" id="dlg" appendTo="@(body)" widgetVar="Dialog1" modal="true" showEffect="fade" hideEffect="fade" width="75%" resizable="false" visible="#{FormMB.vendorFlag}">
<p:outputPanel id="dialogPanel1">
<h:form id="ven">
<p:panelGrid columns="5" style="text-align:left" columnClasses="ui-grid-col-2,ui-grid-col-3,ui-grid-col-1,ui-grid-col-2,ui-grid-col-3" layout="grid" styleClass="ui-panelgrid-blank">
<h:outputText class="label_ui" value="Firm Name " for="vfname"/>
<p:inputText value="#{FormMB.number}" id="vfname" styleClass="inputTxt" onblur="onblur="myvalidation1()">
<p:ajax event="valueChange" process="@this" immediate="true" update="@all"></p:ajax>
</p:inputText>
</p:panelGrid>
<br></br>
<center><p:commandButton value="Submit" process="@this" immediate="true" action="#{FormMB.Register}" oncomplete="PF('Dialog1').hide();" ></p:commandButton>
</center>
</h:form>
</p:outputPanel>
</p:dialog>
</ui:define>
</ui:composition>
因为我使用了jquery和java-script,但都给出了相同的错误(未定义)。