aspose file tools*
The moose likes JSF and the fly likes using javascript function in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "using javascript function in JSF" Watch "using javascript function in JSF" New topic
Author

using javascript function in JSF

umesh annegirikar
Greenhorn

Joined: May 09, 2011
Posts: 28
hello friends..
I am new to JSF & richfaces 4.0 devlopment.I am facing the problem that i don't know how to use the javascript in the JSF.
the requirement is i want to check all the checkbox & after clicking the delete button the datagrid contents are deleted.
but the javascript function cannot be executed in the

The source code is:

<h:panelGroup rendered="#{manageBean.listStatus}">
<rich:dataTable id="customer_list" value="#{manageBean.customers}" var="customer" height="200px" style="width : 100%;">
<rich:column style="border-color: #FBEFEF; column-color: #EFFBF5">
<f:facet name="header">
<input type="checkbox" name="header" onclick="checkAll()"/>
<h:commandButton value="s" action="#{manageBean.getCustomerListChecked}" immediate="true" >
<f:param name="VALIDATE" value="false" />
</h:commandButton>
</f:facet>
</h:panelGroup>


And the javascript function is:


function checkSelect()
{
var i=document.frm.elements.length;
var berror=true;
for(var k=0;k<i;k++)
{
if(document.frm.elements[k].name==fieldName)
{
if(document.frm.elements[k].checked==false)
{
berror=false;
break;
}
}
}
if(berror==false)
{
document.frm.allCheck.checked=false;
}
else
{
document.frm.allCheck.checked=true;
}
}

But it shows the exception as

Element type "i" must be followed by either attribute specifications, ">" or "/>".

So what is the error i don't understand the error.

So please tell me the solution as i am new to the JSF,richfaces environment.

Thanking you..

Umesh



Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 542
    
    4

Hello Umesh,

First thing I noticed was that you don't close your datatable and column tags. Perhaps a good idea to use a code block for your code and give a stacktrace instead of just the one sentence.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
umesh annegirikar
Greenhorn

Joined: May 09, 2011
Posts: 28
Dieter Quickfend wrote:Hello Umesh,

First thing I noticed was that you don't close your datatable and column tags. Perhaps a good idea to use a code block for your code and give a stacktrace instead of just the one sentence.


Ok...

So this is my jsf code

<rich:column style="border-color: #FBEFEF; column-color: #EFFBF5">
<f:facet name="header">
<input type="checkbox" name="header" onclick="checkAll()"/>
<h:commandButton value="s" action="#{manageBean.getCustomerListChecked}" immediate="true" >
<f:param name="VALIDATE" value="false" />
</h:commandButton>
</f:facet>
<h:panelGroup rendered="#{!manageBean.checked}">
<input type="checkbox" name="#{customer.id}" value="#{customer.id}" />
</h:panelGroup>
<h:panelGroup rendered="#{manageBean.checked}">
<input type="checkbox" name="#{customer.id}" value="#{customer.id}" checked="checked"/>
</h:panelGroup>
</rich:column>


the javascript function is:

function checkAll(frm1)
{
var a=document.getElementById('frm1');
if(checked==false)
{
checked=true
}
else
{
checked=false
}
for(var i=0;i<a.elements.length;i++)
{
a.elements[i].checked=checked;
}
}




The Exception stack trace is:

javax.faces.view.facelets.FaceletException: Error Parsing /content/customerListContent.xhtml: Error Traced[line: 45] Element type "a.elements.length" must be followed by either attribute specifications, ">" or "/>".
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:394)
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:368)
at com.sun.faces.facelets.compiler.Compiler.compile(Compiler.java:124)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.createFacelet(DefaultFaceletFactory.java:297)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.access$100(DefaultFaceletFactory.java:92)
at com.sun.faces.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:162)
at com.sun.faces.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:161)
at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:83)
at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:79)
at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:119)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:62)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:248)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:366)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:108)
at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:103)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:178)
at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366)
at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:108)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:55)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:167)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:82)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:82)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:744)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:284)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:322)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1714)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)









Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 542
    
    4

Hey Umesh,




I don't see any form, or anything... I think it would be best if you just pasted the whole thing into a code block (click the code button in your screen, you can even choose the language that it uses). Obviously, things are wrong with your xhtml. You're using regular form inputs instead of JSF inputs and I don't even see a form.
 
Don't get me started about those stupid light bulbs.
 
subject: using javascript function in JSF