is it possible to send value from <a4j:support> to bean - jsf

<rich:tree switchType="client" value="#{Bean.tree}" var="one">
<rich:treeNode>
<h:commandLink value="#{one.item1}"
action="#{Bean.getItem()}"
style="color:blue;text-decoration:none;"
title="Click here to view details">
<f:param name="ids" value="#{one.id}">
</f:param>
</h:commandLink>
<a4j:support event="onclick" reRender="productInformation"
action="#{Bean.getItem()}"/>
</rich:treeNode>
</rich:tree>
<rich:panel id="productInformation">
</rich:panel>
hi I have a page in that tree structure will be present if i click on the link the corresponding action should be performed but by using h:commandlink the whole page will be refreshed.So Iam going for I have a problem here in h:commandlink i was able to transfer the parameter to bean by using f:param but by using how can I acess the value to bean please help me out iam new to jsf.

Solved the solution by using a4j:commandlink tag and passing the parameter from a function.
<
a4j:commandLink ajaxSingle="true" value="#{item.Description}(#{item.name})"
action="#{Bean.getProductLink(item.paramID)}" style="color:blue;text-decoration:none;" title="#{item.productDescription}" reRender="addproductGuidForms"/>
is working fine.

Since you are using JSF2 there is no need to pass with f:param just pass it in method args
action="#{Bean.getItem(one.id)}"
b.t.w you better rename the method name into action="#{Bean.retrieveItem(one.id)}"

Related

Use either action or actionListener based on a condition in a PF datatable composite component

I am trying to create a datatable composite component, this component needs to be used by two groups of developers, one who are using Spring web flow and they need an action attribute for the command link inside the composite component datatable and the others need the actionListener attribute.
I would like to use the same xhtml for both cases. Is that feasible?
<composite:attribute name="isWebFlow" />
Would an attribute like above help me configure? The problem is that I have many command links in the datatable composite component and hence I cannot repeat them / render them based on the condition like :
<c:if test="#{cc.attrs.isWebFlow eq 'true'}">
<p:commandLink styleClass="filter #{cc.attrs.styleClass}" action="#{cc.attrs.action}"/>
</c:if>
<c:if test="#{cc.attrs.isWebFlow eq 'false'}">
<p:commandLink styleClass="filter #{cc.attrs.styleClass}" actionListener="#{cc.attrs.actionListener}"/>
</c:if>
Is there any other way to do this and re use the xhtml? Thanks in advance.
Try using rendered attribute:
<p:commandLink styleClass="filter #{cc.attrs.styleClass}" action="#{cc.attrs.action}" rendered="#{isWebFlow}"/> <p:commandLink styleClass="filter #{cc.attrs.styleClass}" action="#{cc.attrs.action}" rendered="#{!isWebFlow}"/>

Reset inputText after Button Click with JSF

Is it possible to reset the value of an inputText after clicking on the commandButton in JSF? The inputText UIElement provides the method ResetValue so I tried something like this:
<h:inputText id="measurementadd" binding="#{inputTextMeasurement}">
<f:validateRegex pattern="[a-zA-Z ]*"/>
<f:ajax event="keyup" render="measurementaddmessage submit" execute="#this"/>
<h:inputText>
<p:commandButton id="submit" action="#{Bean.addMeasurement(inputTextMeasurement.value)}"
value="submit" update="dataTable measurementadd measurementaddmessage"
disabled="#{empty inputTextMeasurement.value or facesContext.validationFailed }" >
<f:ajax event="mouseup" execute="#{inputTextMeasurement.resetValue()}" />
</p:commandButton>
<h:messages for="measurementadd" id="measurementaddmessage"/>
But after clicking the Button the inputTextMeasurement doesn't reset it's value.
Does someone know a good workaround for this?
I'm searching for a solution without JS and JAVA, so a realization in JSF would be very cool.
Your mistake is here in the execute attribute:
<f:ajax event="mouseup" execute="#{inputTextMeasurement.resetValue()}" />
The execute attribute should represent a space separated collection of client IDs to include in the process/decode of the ajax request. However, you specified a listener method there.
You need the listener attribute instead:
<f:ajax listener="#{inputTextMeasurement.resetValue()}" />
(and I omitted event as it defaults here to click which is already the right one)
Interesting detail is that the other <f:ajax> in the same piece of code used the exeucte attribute the right way.
Unrelated to the concrete problem, have you looked at <p:resetInput>? This saves an ajax listener method in the bean. Replace the whole <f:ajax> with
<p:resetInput target="measurementadd" />
Why dont we just use
<input type="Reset"/>
This one is works fine for me! ???
I have solved my problem as below
<p:commandButton id="submit" action="#{Bean.addMeasurement(inputTextMeasurement)}">
Sending back bean UIInput component. Get and Reset value in back bean.
public void addMeasurement(UIInput
String msr = (String) inputTextMeasurement.getValue()
inputTextMeasurement.resetValue();
}

JSF / Richfaces : how to retrieve the backing bean property that served as value for a inputtext

Hie all,
I have a complex form with a list of inputs (inputtext) that have been generated using a foreach over a backing bean property (list).
<c:forEach items="#{myBean.list}" var="elem">
<h:inputText value="#{elem.val}">
<a4j:ajax render="#this"/>
</h:inputText>
</c:forEach>
When one input is changed, I would like to know which one it was, so that I can proceed some immediate update on my model (ie call some update methods in a backing EJB).
I have been looking through ValueChangeEvent, AjaxBehaviorEvent, IUComponent... but did not find where I cloud get a direct reference back to my backing property...
Is there a way to achieve this ?
Thanks for help
Did you try to add a a4j:support like this?
<c:forEach items="#{myBean.list}" var="elem">
<h:inputText value="#{elem.val}">
<a4j:ajax event="onchange" listner="#{someBean.changeValue(elem)}" render="#this"/>
</h:inputText>
</c:forEach>
This way you can get, into the changeValue method, a reference to the element.

a4j:support after h:inputText value change doesn't work

can anyone figure out why the h:outputText doesn't get refreshed after inputText value change?
I've tried both onkeyup and onchange and both don't affect..
When I do some other thing that makes the page refresh, the h:outputText is rendered correctly so it's only a matter of getting the ajax to actually rerender the component.
<h:inputText autocomplete="off" styleClass="propertyInput"
value="#{activesyncDM.userNameDomain}" validator="#{activesyncDM.validate}"
id="userNameDomain" dir="ltr">
<a4j:support event="onkeyup" reRender="domainNameSlash"/>
</h:inputText>
<h:outputText id="domainNameSlash" value="\\" rendered="#{!empty activesyncDM.userNameDomain}"/>
Thanks!!
besides putting ajaxSingle="true" for a4j:support which is mentioned by Cristian , the id attribute in HTML code rendered by the JSF may not be the same as the ID value you set in <h:outputText> . Richfaces provides a function rich:clientId('id') to get these dynamic ID generated by JSF . This function is invoked via the EL expression.
So , you can try :
<a4j:support event="onkeyup" ajaxSingle="true" reRender="#{rich:clientId('domainNameSlash')}"/>
You have to send the value of inputText to the backing bean in order the outputText to reflect the changes so you should put: ajaxSingle="true" for a4j:support
<a4j:support event="onkeyup" ajaxSingle="true" reRender="domainNameSlash"/>

JSF2 and Spring Webflow (<h:commandLink> doesn't respond inside <ui:repeat> facelet tag)

i am trying to have a List of commandLink in every cell of dataTable.
this is small example explaining what i am trying to do
<h:form id="form1">
<p:dataTable id="doctorTable" var="doctor"
value="#{search.medecinsResult}" rowIndexVar="rowIndex">
<p:column headerText="#{search.headerDate[1]}">
<ui:repeat var="seance" value="#{search.column2[rowIndex]}">
<h:commandLink value="#{seance}" action="Reserver"
title="Réservez cette séance">
</h:commandLink>
<br />
</ui:repeat>
</p:column>
</p:datable>
</h:form>
And i define transition on the page viewState in my XML flow:
<view-state id="result">
<transition on="Reserver" to="next">
</transition>
</view-state>
the commandLink work fine outside repeat tag, but when its inside it just reload the webpage
i found JIRA issues for that, but it not resolved.
link to JIRA issue
if there is any workaround it will be great, thank's for your responses.
It's the <ui:repeat> which is the culprit. It doesn't work very well when nested in another repeating component. There are many related issues for that already, the JSF guys are working on that. The usual solution is to pick a "fullworthy" JSF UIData component instead, such as <h:dataTable>. Since you're already using PrimeFaces, I'd suggest to try <p:dataList> instead.

Resources