JSF h:commandLink JavaScript error - jsf

I am using JSF 2.0 tag <h:commandLink> and I'm trying to open an window with target as _blank. In the target I am trying to populate the document which was fetched from the server. But while doing so I am getting an error in jsf.js (function name is jsfcljs) at f.submit().
Declaration is as follows:
<h:commandLink id="viewDocument" value="#{template.orderBean.documentBean.documentName}"
action="#{template.viewCustomDocument}" target="_blank" styleClass="textbold">
<f:param name="documentId" value="#{template.orderBean.documentBean.documentId}"/>
</h:commandLink>
The error I got is
Object doesn't support this property.
If I use <h:commandButton> instead then I am able to call the server and fetch the document.
What can the problem cause be?

Related

<f:ajax execute="newDate" listener="myBean.getResultByNewDate()"> return error message 'Server sent empty response'

Following is my JSF code
<h:input type="newDate">
<h:commandLink>
<f:ajax execute="newDate" listener="myBean.getResultByNewDate()">
</h:commandLink>
In the backing bean, the newDate field is defined as Date and method getResultByNewDate() is also defined. But on click of the command link, I get a error message: "Server sent empty response".
I need to use the newDate's value in the getResultByNewDate(). Any suggestions to fix this issue. Is the syntax correct?
Your JSF code has multiple issues:
1) input should be replaced with inputText.
2) type also has no use here.
3) listener should use proper binding.
4) execute should use the id of the xhtml component which need to be executed on ajax.
Code should be like:
<h:inputText value="#{myBean.newDate}" id="dateInput">
<h:commandLink>
<f:ajax execute="dateInput" listener="#{myBean.getResultByNewDate()}">
</h:commandLink>
Extra point to note, if you would have used commandButton on place of commandLink, you should declare the type="button", otherwise you will face issue with ajax. Because ajax work with type button and commandButton is of type submit by default and commadLink is of type button by default.

<a4j:commandLink> is not working

in my JSF 2.2 application I was trying to create an AJAX request using RichFaces 4.3.2 with .
The rendered HTML is:
<a href="#" id="x" name="x" onclick="RichFaces.ajax(x;,event,{x:x} );return false;">
The problem is that after clicking the link, nothing happens and an error in my Chrome Console appears:
Uncaught TypeError: Object #<Object> has no method 'ajax'
When I type RichFaces into console I get some autocomplete possibilities like `Event, valueOf' etc. but it doesn't see any specific RichFaces functions.
It looks like the RichFaces library wouldn't be attached at all but I have no idea why.
Why is it happening?
The code of the commandLink:
<ui:repeat value="#{commonsOperations.newsList}" var="n">
<li>
<a4j:commandLink action="#{commonsOperations.setSelectedNews(n)}"
value="#{n.title}" render="content" />
</li>
</ui:repeat>
I found out the problem why RichFaces libraries were not loaded properly was the conflict between RichFaces and PrimeFaces. After removing PrimeFaces from POM, all RichFaces javascript files are loaded.

onclick tag giving error in h:commandLink

I'm using JSF 1.2 and I was trying to add onclick tag to h:commandLink which is throwing runtime error.
The code I'm trying to write in jsp is:
<h:commandLink id="btn" styleClass="button" onclick="performAction();">
<h:outputText value="some value" />
</h:commandLink>
It is giving me an error:" Unable to locate tag attribute info for tag attribute onclick. "
Any help is appreciated.
Thank you.
From h:commandLink it says...
The commandLink tag renders an HTML "a" anchor element that acts like a form submit button when clicked.The commandLink tag is used to submit an action event to the application.
Use <h:commandLink> tag to represent a link to POST form data.
h:commandLink tag must include a nested outputText tag, which represents the text the user clicks to generate the event.
The generated HTML uses syntax.
The commandLink tag will render JavaScript. If you use this tag, make sure your browser is JavaScript-enabled.
The onclick attribute is automatically populated with Javascript to submit the form.
Setting type = “reset” makes the link a reset button.
Use the action attribute to associate the link with a JavaBean’s method.
You should check the source code via view source and check for java script errors via Firefox.

Call another form from the command button

When I submit a form it should call another form so that I can render it. I use primefaces and I want it to work something like below. But it is throwing an error.
xhtml
<h:form id="from1">
<h:inputText=......
<h:outputText=....
<p:commandButton id="submit" actionlistener="#{bean.method}" value="submit" process="form2"/>
<h:form id="form2">
<h:outoutText value="it is working" render="#{bean.boolean}" />
</h:form>
error
[Faces Servlet]] (http--127.0.0.1-8080-2) Servlet.service() for servlet Faces Servlet threw exception: javax.faces.FacesException: Cannot find component with identifier "form2" referenced from "form1_submit".
Updated
<h:form id="from1">
<h:inputText=......
<h:outputText=....
<p:commandButton id="submit" actionlistener="#{bean.method}" value="submit" update=":form1"/>
</h:form>
There are two mistakes:
Relative component client IDs are releative to the closest parent UINamingContainer component (which is in your case thus the <h:form id="form1">). The client ID "form2" does not exist anywhere within the context of "form1". You need to use an absolute client ID instead, prefixed with the naming container separator character which defaults to :. This will search for components from the view root on.
process=":form2"
You cannot process another from by a submit of one form. All of the fields which you need to be processed are not been submitted at all (note that this is not a JSF limitation, but a HTML limitation). Just enclose the fields which you need to process in the very same form as you need to submit.
There is another solution with p:remoteCommand and JS with onclick described
HERE.

JSF 2.0 navigating on commandLink and commandButton doesn't work

I'm using JSF 2.0 and I have a problem with navigation after both commandLink and commandButton. I use following code:
<h:commandLink action="login?faces-redirect=true"
value="#{showElementBean.showElement()}"> Login </h:commandLink>
<h:commandButton action="login?faces-redirect=true" value="Move to login.xhtml" />
These tags are inside a form, login is just an example. Result of clicking on rendered controls is always POST with refresh of a current page. What do I wrong?
Edit:
According to comments of BalusC I' adding real code fragment:
<h:commandLink actionListener="#{showElementBean.showElement(element)}"
value="View" > </h:commandLink>
I have a page with a list of elements and I want to add links that leads to element view page. Thus I need to pass this element to a show page. I'm JSF primer, e.g. in Rails I'd use GET and URL params, but I don't know how to do it 'in JSF-way'.
There are a lot of possible causes for this behaviour. They are all cited in the following answer, along with solutions: commandButton/commandLink/ajax action/listener method not invoked or input value not updated.
However, in your particular case, you seem rather to be interested in plain GET requests instead of POST requests, as all you want is simple page-to-page navigation. In that case, you need a <h:link> or <h:button> instead:
<h:link outcome="login" value="Login" />
<h:button outcome="login" value="Move to login.xhtml" />
(I have no idea what you're trying to do with both #{showElementBean.showElement()} and Login as command link value, so I omitted the former)
See also:
When should I use h:outputLink instead of h:commandLink?
Refer this info: JSF HTML Tags
h:commandButton
The commandButton tag renders an HTML submit button that can be
associated with a backing bean or ActionListener class for event
handling purposes. The display value of the button can also be
obtained from a message bundle to support internationalization (I18N).
Example
<h:commandButton id="button1" value="#{bundle.checkoutLabel}" action="#{shoppingCartBean.checkout}" />
HTML Output
<input id="form:button1" name="form:button1" type="submit" value="Check Out" onclick="someEvent();" />
h:commandLink
The commandLink tag renders an HTML anchor tag that behaves like a
form submit button and that can be associated with a backing bean or
ActionListener class for event handling purposes. The display value of
the link can also be obtained from a message bundle to support
internationalization (I18N).
Example
<h:commandLink id="link1" value="#{bundle.checkoutLabel}" action="#{shoppingCartBean.checkout}" />
HTML Output
Check Out
Noticed that backing bean method is not called if the form is for file upload:
<h:form name="searchForm" enctype="multipart/form-data" method="post" action="/search">
I also faced with that issue and adding the
<h:form><h:commandLink></h:commandLink> </h:form>
solved my problem.

Resources