I have a situation where I am suppose to submit a user's payment details to my payment gateway partner.
For this I have a separate non JSF form with hidden values as parameters to be passed.
<form id="hiddenForm" action="#{checkoutBean.payuAction}" method="post" name="payuForm">
<p:outputPanel id="hiddenPanel">
<h:inputHidden id="hash" value="#{checkoutBean.hash}"/>
<h:inputHidden id="txnid" value="#{checkoutBean.txnid}"/>
<h:inputHidden id="amount" value="#{checkoutBean.totoalAmount}"/>
<h:inputHidden id="firstname" value="#{checkoutBean.firstname}"/>
<h:inputHidden id="email" value="#{checkoutBean.email}"/>
<h:inputHidden id="phone" value="#{checkoutBean.phone}"/>
<h:inputHidden id="productinfo" value="#{checkoutBean.productInfo}"/>
<h:inputHidden id="surl" value="#{checkoutBean.sURL}" />
<h:inputHidden id="furl" value="#{checkoutBean.fURL}"/>
</p:outputPanel>
</form>
The above hidden values are generated using ajax at the last step in a wizard (primefaces). The ajax call is happening but I am unable to update the non JSF form. The values are null.
<p:commandButton value="Confirm" actionListener="#{checkoutBean.initPayu}" onsuccess="submitPayuForm()" update=":hiddenForm:hiddenPanel" />
The above button is in a <h:form>.
Now i believe that it is not possible to update non JSF components from JSF components. But I just can't figure out how to tackle this scenario.
Any ideas on how I can tackle this problem?
Using : JSF 2 , Primefaces 3.3
Thanks a ton in advance.
Since your form is not a JSF component you don't need to append its id to ids of your JSF components (:hiddenForm:hiddenPanel).
In other words, try something like this:
<p:commandButton ... update="hiddenPanel" />
Related
I need to reset the form fields and clear the form values onload.
However I used -
public void refresh() {
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
ViewHandler viewHandler = application.getViewHandler();
UIViewRoot viewRoot = viewHandler.createView(context, context
.getViewRoot().getViewId());
context.setViewRoot(viewRoot);
context.renderResponse(); //Optional
}
The above code is working but when I am entering values in fields using in panelgroup , its not working.
<h:panelGroup>
<ui:repeat value="#{formDynAttrbBean.vals}" var="values">
<b:panelGrid columns="6" cellspacing="4">
<b:inputText id="label" value="">
</b:inputText>
<b:selectOneMenu value="">
<f:selectItem itemLabel="SelectType" itemValue="" />
<f:selectItems value="" />
</b:selectOneMenu>
<b:selectBooleanCheckbox value="" />
<b:commandButton actionListener="#{form.types}" />
</b:panelGrid>
</ui:repeat>
<b:commandButton tooltip="Add new attribute" tooltip-position="bottom"
iconAwesome="plus" actionListener="#{form.add}" update="#form" />
<tr />
<b:commandButton value="Save" ajax="true"
actionListener="#{form.submit}" update="#form" />
<tr />
<b:commandButton type="reset" action="#{formController.refresh}"
value="Reset">
</b:commandButton>
</h:panelGroup>
Refresh function is not working in this case when I am entering values in panelgroup and in repeating fields.
I am just a beginner to bootsfaces.Please suggest me an approach.Thankyou in advance.
There are ways to clear the input fields of the form. For example, JSF 2.2 has the resetValues="true" attribute (see the article of Michael Kurz (probably not implemented by BootsFaces). Another option is to use <b:commandButton type="reset">.
But I wonder why you want to reset the values on the client side? You have to clear them because they display some "dirty" (i.e. modified) backend bean. IMHO the better approach is to create a new, empty backend bean.
I'm stuck at pretty simple task: I have a search form where the search criteria are stored is SearchCriteriaSession bean, so it could be remembered and pre-filled. And I want to add reset button to that form that would:
1) clear the criteria from bean, therefore call clearSearchCriteria() method of the bean
2) rerender the form, so the fields would be empty
Here's my code and I have no idea why it's not working:
search.xhtml
...
<h:form id="criteriaForm">
<div class="controls">
<h:inputText type="text" id="testName" value="#handlingBean.criteria.testName}" />
</div>
//more input fields but with same format
<div class="form-actions">
<r:commandButton action="#searchCriteriaSession.clearSearchCriteria}" value="Reset" render="#form :criteriaForm" />
</div>
</h:form>
...
The searchCriteriaSession.clearSearchCriteria just clears criteria. When I debug it I see it correctly cleared. Even when I refresh the page the form clears, so the problem is that the render attribute is not working correctly, I guess.
Does anybody can please help me?
P.S.: I'm using RichFaces, this maven artifact:
<dependency>
<groupId>org.richfaces.compat</groupId>
<artifactId>richfaces-components-rich</artifactId>
<version>4.5.0.Alpha2</version>
</dependency>
Your render attribute needs only #form
<r:commandButton action="#searchCriteriaSession.clearSearchCriteria}" value="Reset" render="#form" />
I have two forms, an one button.
<h:form>
<h:outputLabel value="Form Name: *" />
<p:inputText required="true" value="#{currentTemplate.name}" />
</h:form>
and one button in another form.
<h:form id="orderListForm">
<p:commandButton value="Submit"
action="#{orderListBean.callPersist}" style="margin-top:5px"
id="btnCitySubmit" />
</h:form>
I want to save the value from the first form with the second.
I really appreciate your answer!
Do you want to execute all inputs in both forms? Then process="#all" attribute of <p:commandButton> is for you. It will process all inputs within a page.
Alternatively, you can specify ids of components to be processed, like process="#form :another-form", if to-be-updated form has id="another-form" specified.
Is there a way to assign dynamic ids to h:inputHidden components?
EDIT1
I am trying to assign the ids inside a ui:repeat tag when iterating over a collection of elements.
It is not possible to set the ID based on the iteration value of an <ui:repeat>. But you don't need it anyway. They will by default already get dynamic and unique IDs based on the iteration index.
E.g.
<h:form id="form">
<ui:repeat value="#{bean.list}" var="item">
<h:inputHidden id="hidden" value="#{item.value}" />
</ui:repeat>
</h:form>
will generate this HTML during view render time
<form id="form" name="form">
<input type="hidden" id="form:0:hidden" name="form:0:hidden" value="item1value" />
<input type="hidden" id="form:1:hidden" name="form:1:hidden" value="item2value" />
<input type="hidden" id="form:2:hidden" name="form:2:hidden" value="item3value" />
</form>
If you want to manually control the ID, you'd need to use <c:forEach> instead, because <ui:repeat> doesn't generate multiple JSF components, but lets its children (which is a single <h:inputHidden> in the above example) generate HTML multiple times. The <c:forEach> will generate multiple JSF components which then each generate HTML only once (so you effectively end up with multiple <h:inputHidden> components in JSF component tree).
E.g.
<h:form id="form">
<c:forEach items="#{bean.list}" var="item">
<h:inputHidden id="#{item.id}" value="#{item.value}" />
</c:forEach>
</h:form>
which will basically generate this JSF component tree during view build time
<h:form id="form">
<h:inputHidden id="item1id" value="#{bean.list[0].value}" />
<h:inputHidden id="item2id" value="#{bean.list[1].value}" />
<h:inputHidden id="item3id" value="#{bean.list[2].value}" />
</h:form>
which in turn will generate this HTML during view render time
<form id="form" name="form">
<input type="hidden" id="form:item1id" name="form:item1id" value="item1value" />
<input type="hidden" id="form:item2id" name="form:item2id" value="item2value" />
<input type="hidden" id="form:item3id" name="form:item3id" value="item3value" />
</form>
See also:
JSTL in JSF2 Facelets... makes sense?
They get assigned a dynamic ID by default. You can also specify id="#{..} to customize it.
You can dynamically add any random number also (id="#{}"),but
add functionally related ids to hidden components, that will be helpful
for example if it is employee form ,you may add empid to it.
I'm trying to use one <h:commandButton> with ajax to check some conditions, if it's OK the other <h:commandButton> with no ajax will be display. The one with ajax work well, but the other doesn't although I have specified a return String to another page. I cannot figure out why it failed, the syntaxes are all correct.
<h:form>
<label style="font-weight: bold">Room Code: </label>#{r.code}
<label style="font-weight: bold">Room Type: </label>#{r.roomType}
<label style="font-weight: bold">Price Per Day: </label>#{r.pricePerDay}
<br/>
<h:commandButton value="Check" action="#{bookingController.checkRoom}">
<f:param name="selectedRoomID" value="#{r.id}"/>
<f:ajax execute="#form" render="informer"/>
</h:commandButton>
<h:panelGroup id="informer">
<h:outputText value="#{bookingController.message}" rendered="#{bookingController.checked}"/>
<h:commandButton value="Book now!" action="#{bookingController.doBook}" rendered="#{bookingController.goodToBook}">
<f:param name="selectedRoomID" value="#{r.id}"/>
<f:param name="customerID" value="#{customerLoginController.customerUser.customer.id}"/>
</h:commandButton>
</h:panelGroup>
</h:form>
You've a rendered attribute on the second <h:commandButton>. If it evaluates false during processing of the form submit, then the button's action won't be invoked. This will happen if the bean is request scoped and you don't preserve the same condition for the rendered attribute during the form submit request as it was during displaying the form.
There are several ways to go around this. Since you're using JSF 2.0, best is to put the bean in the view scope instead.
#ManagedBean
#ViewScoped
public class BookingController {
// ...
}
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated