<a4j:ajax> is not recognised in jsf 1.2 - jsf

I'm using jsf1.2... and in order to use ajax... I've imported ajax4js jar
but somehow it's throwing error as unknown tag
<h:panelGroup style="padding-left:3px">
<h:commandButton id="submitVisaDetails"
value="Submit Request"
action="#{VtsIdAutogenerateBB.submitVisaDetails}"
onclick="return validateVisaEntries(this,this.form);"
styleClass="btn"
onmouseover="this.className='btn btnhov'"
onmouseout="this.className='btn'" >
<a4j:ajax execute="#form" />
</h:commandButton>
</h:panelGroup>

I hope that you are using Richfaces(ajax4jsf) 3 if so its not <a4j:ajax> its <a4j:support>. Ref: Ajax Support.
If you are using Richfaces 4 then its only supports JSF 2, so either upgrade to JSF 2 of use Richfaces 3.

Related

f:ajax render referencing iterated component

I have xhtml with following structure:
<h:form id="frmMain2">
<f:subview id="sub1">
<ui:repeat var="vatId" value="#{someBean.suppliesKeys()}" id="rep1">
<fieldset>
<legend>vatId</legend>
<h:panelGroup id="panel">
<ui:repeat var="item" value="#{someBean.supplies[vatId]}" id="rep2">
<f:subview id="sub2">
<h:commandLink id="command">
${item}
<f:ajax
event="click"
render=":frmMain2:sub1:rep1:0:panel">
</f:ajax>
</h:commandLink>
</f:subview>
</ui:repeat>
</h:panelGroup>
</fieldset>
</ui:repeat>
</f:subview>
</h:form>
This is running in Websphere Portlet via portlet bridge which means I am stuck with Myfaces 2.0.
The problem I am facing is that I am getting following error:
javax.portlet.PortletException: Component with id::frmMain2:sub1:rep1:0:panel not found
Notice that I am trying to reference first iteration of panel inside f:ajax render (:frmMain2:sub1:rep1:0:panel).
If I referenced something else (outside iterated part), e.g. :frmMain2:sub1:rep1, component is found and portlet works.
I am unable to find how do I reference some iterated component in render attribute.
Found following post where this problem is described as resolved in Mojarra newer version, but Myfaces 2.2.7 does not solve the problem: How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
So, Is there a way to reference the component I want to render in f:ajax?
Since you only want to render the first iteration, you could create a custom component, tag, or template that encapsulates the components that you are iterating over as a workaround:
<fieldset>
<legend>vatId</legend>
<h:panelGroup id="panel">
<ui:repeat var="item" value="#{someBean.supplies[vatId]}" id="rep2">
<f:subview id="sub2">
<h:commandLink id="command">
${item}
<f:ajax
event="click"
render=":frmMain2:sub1:rep1:0:panel">
</f:ajax>
</h:commandLink>
</f:subview>
</ui:repeat>
</h:panelGroup>
</fieldset>
Then you could hard code the first option. Here's some example code (you'll definitely need to adapt this since I don't have all the info about your model data):
<h:form id="frmMain2">
<f:subview id="sub1">
<custom:component id="first" items="#{someBean.supplies[hardcodedFirstKey]}">
<f:ajax event="click" render="#this" />
</custom:component>
<ui:repeat var="vatId" value="#{someBean.suppliesKeys()}" id="rep1">
<custom:component items="#{someBean.supplies[vatId]}" rendered="#{!key eq hardcodedFirstKey}">
<f:ajax event="click" render=":frmMain:sub1:first" />
</custom:component>
</ui:repeat>
</f:subview>
</h:form>

h:commandButton not working [duplicate]

How to update a div and do partial submission using <h:commandButton>, I have previously used <p:commandButton> to do partial submission by setting the ajax attribute to true and the update attribute to :statusBlock, where the id of the <h:panelGroup> is statusBlock. I am having some designing issues with <p:commandButton> so I cannot use it so I have to use <h:commandButton>.
This is to be done by nesting a <f:ajax> in it.
In effects,
<p:commandButton ... process="#form" update=":statusBlock" />
does exactly the same as
<h:commandButton ...>
<f:ajax execute="#form" render=":statusBlock" />
</h:commandButton>
Note that the subtle difference with the PrimeFaces equivalent is that PrimeFaces defaults to #form in the process/execute, while the <f:ajax> one defaults to #this, so you might need to explicitly specify execute="#form" over all place where you didn't specify the process attribute in the PrimeFaces component.
See also:
Communication in JSF 2.0 - Ajax (asynchronous) POST form
You can just use the standard components alongside f:ajax e.g.
<h:form id="myForm">
<h:commandButton value="Push Me">
<f:ajax execute="myForm" render="statusBlock" />
</h:commandButton>
<h:panelGroup id="statusBlock">
</h:panelGroup>
</h:form>

render="#form" with Omnifaces 2.0 and Richfaces 4.5 not working

We're using a <a4j:commandLink ... /> with an action and render="#form". Since we've upgraded to Omnifaces 2.0 the action won't be invoked unless we replace #form with #this or an explicit id. The bean providing the action method is annotated with #javax.faces.view.ViewScoped.
Before with Omnifaces 1.8.1 it has worked well.
(We're using Java 8, JSF 2.2.6, Richfaces 4.5 and Wildfly 8.)
<a4j:commandLink id="#{cc.attrs.buttonId}"
action="#{cc.attrs.action}"
oncomplete="#{cc.attrs.oncomplete}"
onbegin="#{cc.attrs.onbegin}"
render="contentForm:contentSaveHandler contentToolbar #form"
execute="#this">
<h:outputText value="Test" />
</a4j:commandLink>
If I change #form to #this it works.

The attribute update is not defined in the component commandButton

I have this JSF commandButton which I use to delete rows from table:
<h:commandButton id="deleterow" value="HiddenDelete" action="#{BatteryProfileTabGeneralController.saveData}" style="display:none" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
In Netbeans 7.3 I get this error:
The attribute update is not defined in the component commandButton
I use update attribute to display message when I successfully delete row. Can I replace this attribute with similar attribute?
The update attribute is specific to PrimeFaces <p:commandButton>. It's a convenience replacement of the standard JSF equivalent <f:ajax render>.
So, basically, the <p:commandButton ... update="growl" /> does essentially the same as:
<h:commandButton ...>
<f:ajax render="growl" />
</h:commandButton>
Note that when the <p:growl id="growl"> is not inside the same form, then you should refer it using an absolute client ID instead, perhaps <f:ajax render=":growl">. If you would like to update the current form as well, then use <f:ajax render="#form :growl">. This is perhaps your case as you've currently already a render="#form" but still keeps asking about explicitly updating the growl, which suggests that it is actually not enclosed in the form at all.

How can we use multiple <h:messages> tags or <h:message> tags in a single JSF page?

My problem is that I have 2 forms in a single JSF page each having its <h:message> or <h:messages> tag. As we know the message/messages tags print any validation errors, so what happens is, suppose I leave the fields of any of the 2 forms empty it should print "Fields cannot be left blank" or some kind of message. It gives this message, but it gives twice as there are two forms. So I see the same error/validation message at each of the two forms.
So what I need is the <h:messages> or the <h:message> tag should display error/validation message only once for each of their respective forms!!
So any help would greatly be appreciated!!
If you're using JSF 2, then you could just submit and update the form by ajax. This allows for partially updating the view.
<h:form>
<h:messages />
...
<h:commandButton ...>
<f:ajax execute="#form" render="#form" />
</h:commandButton>
</h:form>
<h:form>
<h:messages />
...
<h:commandButton ...>
<f:ajax execute="#form" render="#form" />
</h:commandButton>
</h:form>
Or if you can't/don't want to use ajax for some unobvious reason, or are still using the legacy JSF 1.x, then check in the rendered attribute of <h:messages> if the desired form is been submitted or not.
<h:form binding="#{form1}">
<h:messages rendered="#{form1.submitted}" />
...
<h:commandButton ... />
</h:form>
<h:form binding="#{form2}">
<h:messages rendered="#{form2.submitted}" />
...
<h:commandButton ... />
</h:form>
The <h:message> shouldn't have this problem by the way, in contrary to what you're implying in your question.

Resources