Using JSF 2.1
We have a form that encapsulates blocks of search results. Each block has a "Delete" button that talks to the View scoped backing and removes the block (from a Session scoped bean).
Visually something like this:
-- group
-- block (delete button)
-- search result
-- block
-- search result
...
When the last block is deleted the entire group disappears.
Anyways. The follow implementation of a delete works fine:
<h:commandButton
styleClass="delete"
action="#{backing.taBortFranTrafflista(sokning)}"
value="#{backing.getText('trafflista.taBort')}"
onclick="return confirm('#{backing.getText('FR100', sokning.sokbegrepp, backing.aktuelltAntalTraffar(sokning))}');"
rendered="#{backing.javascriptEnabled}"
disabled="#{commons.trafflistaLast}">
<f:ajax render="#form" />
</h:commandButton>
However, the following implementation with a confirmation do in JQuery works but NOT with the last search result whereby the action (assigned to the h:commandButton) is never called:
<ui:fragment rendered="#{backing.javascriptEnabled}">
<div id="dialog#{sokning.hashCode()}" title="Ta bort" class="dialog">
<p>#{backing.getText('FR100', sokning.sokbegrepp, backing.aktuelltAntalTraffar(sokning))}</p>
<h:commandButton
styleClass="delete dialog-button"
action="#{backing.taBortFranTrafflista(sokning)}"
value="#{backing.getText('trafflista.taBort')}"
onclick="closeDialog('dialog#{sokning.hashCode()}')"
disabled="#{commons.trafflistaLast}">
<f:ajax render="#form" onerror="ajaxError"/>
</h:commandButton>
<input
type="submit"
data="dialog#{sokning.hashCode()}"
class="closeDialog dialog-button"
value="#{backing.getText('trafflista.avbryt')}" />
</div>
<ui:fragment rendered="#{not commons.trafflistaLast}">
<input
type="submit"
data="dialog#{sokning.hashCode()}"
class="delete showDialog"
value="#{backing.getText('trafflista.taBort')}" />
</ui:fragment>
<ui:fragment rendered="#{commons.trafflistaLast}">
<input
type="submit"
class="delete showDialog"
value="#{backing.getText('trafflista.taBort')}"
disabled="disabled"/>
</ui:fragment>
</ui:fragment>
Reason faces-redirect=true works is that DOM components inside the form match up with the server representation. The JQuery dialog was rendered outside the form at the bottom of the page. Doing a render equal #all solved the problem. Another solution was to render the dialog inside the form.
Related
I want to create a form which when it's submitted it renders and executes a second form:
<h:form id="paymentform">
<div>
.....
</div>
<h:commandButton id="buy" type="submit" value="Put" action="#{dashboard.calculateProcessing}" >
<f:ajax render="#form formdddasd" execute="#form formdddasd"/>
</h:commandButton>
</h:form>
Second form which must be reloaded and refreshed:
<h:form id="formdddasd">
<h:dataTable id="formdd" value="#{orders.cdList}" var="cd"
rendered="#{orders.cdList ne null}"
...........
</h:dataTable>
</h:form>
The first form is executed and rendered but the second form is not. Is it possible to implement this functionality?
Is it possible to implement this functionality?
Yes
try this
<f:ajax render="#form :formdddasd" execute="#form :formdddasd"/>
I have two panels, an outer one "outer_lst_panel" and an inner one "inner_lst_panel". The inner one is embedded in the outer one. The problem is that I cannot remove an item from the inner panel. The button "Remove inner item" does not work. If I look in the generated code (see below) it seems to be a problem with the generation of a real id ("mojarra.ab(this,event,'action',0,'inner_lst_panel')"). If I hard code
<h:commandButton
value="Remove inner item"
action="#{bean.do_delete_inner_item(mas, mav)}">
<f:ajax render="aform:j_idt13:0:inner_lst_panel" /> <!-- Hard coded!!! -->
</h:commandButton>
it works. What's wrong?
JSF 2.3.2 from https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.3.2/javax.faces-2.3.2.jar
Bean:
#Named
#ViewScoped
public class Bean
...
<h:form id="aform">
<h:panelGroup id="outer_lst_panel">
<ui:repeat
var="mas"
value="#{bean.mas_lst}">Outer item
<h:panelGroup id="inner_lst_panel">
<ui:repeat
var="mav"
value="#{mas.mav_lst}">Inner item
<h:commandButton
value="Remove inner item"
action="#{bean.do_delete_inner_item(mas, mav)}">
<f:ajax render="inner_lst_panel" /> <!-- Not working!!! -->
</h:commandButton>
</ui:repeat>
<h:commandButton
value="Add inner item"
action="#{bean.do_add_inner_item(mas)}">
<f:ajax render="inner_lst_panel" />
</h:commandButton>
</h:panelGroup>
<h:commandButton
value="Remove outer item"
action="#{bean.do_delete_outer_item(mas)}">
<f:ajax render="aform:outer_lst_panel" />
</h:commandButton>
</ui:repeat>
</h:panelGroup>
<h:commandButton
value="Add outer item"
action="#{bean.do_add_outer_item()}">
<f:ajax render="aform:outer_lst_panel" />
</h:commandButton>
</h:form>
Generated code:
<form
id="aform"
name="aform"
method="post"
action="test.xhtml"
enctype="application/x-www-form-urlencoded">
<input
name="aform"
value="aform"
type="hidden"> <span id="aform:outer_lst_panel"> Outer item <span
id="aform:j_idt13:0:inner_lst_panel"> Inner item <input
id="aform:j_idt13:0:j_idt35:0:j_idt31"
name="aform:j_idt13:0:j_idt35:0:j_idt31"
value="Remove inner item"
onclick="mojarra.ab(this,event,'action',0,'inner_lst_panel');return false"
type="submit"><input
id="aform:j_idt13:0:j_idt42"
name="aform:j_idt13:0:j_idt42"
value="Add inner item"
onclick="mojarra.ab(this,event,'action',0,'aform:j_idt13:0:inner_lst_panel');return false"
type="submit"></span><input
id="aform:j_idt13:0:j_idt43"
name="aform:j_idt13:0:j_idt43"
value="Remove outer item"
onclick="mojarra.ab(this,event,'action',0,'aform:outer_lst_panel');return false"
type="submit"></span><input
id="aform:j_idt44"
name="aform:j_idt44"
value="Add outer item"
onclick="mojarra.ab(this,event,'action',0,'aform:outer_lst_panel');return false"
type="submit"><input
name="javax.faces.ViewState"
id="j_id1:javax.faces.ViewState:0"
value="-2796149469970124814:8174359678892564468"
autocomplete="off"
type="hidden">
</form>
Update:
No, my question is not answered by How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
It's yet unclear for me why the render attribute from the ajax tag doesn't get a real reference for inner_lst_panel with an continual counter. From my opinion it should be rendered to
onclick="mojarra.ab(this,event,'action',0,'aform:j_idt13:0:inner_lst_panel')
but it doesn't. It becomes
onclick="mojarra.ab(this,event,'action',0,'inner_lst_panel')
and that's wrong and doesn't work.
As a workaround (no, I cannot use render="#form" for other reasons) I can use the following:
<h:form id="aform">
<h:panelGroup id="outer_lst_panel">
<h:panelGroup id="inner_lst_panel" binding="#{foo}">
...
<f:ajax render="#{foo.clientId}" />
...
When page rendered first time textbox was empty and when i click a button and called a action and update the value like this it worked and textbox updated with new value
Flash flash = FacesContext.getCurrentInstance().getExternalContext()
.getFlash();
flash.put("errorMessage",featuesObj.getName() + "Some Error came");
<h:inputText value="#{flash.errorMessage }" id="mymessage" />
But now made a little changes in textbox and added a rendered now text box not displayed even pressing command button while #{flash.errorMessage} already have some String value
<h:inputText value="#{flash.errorMessage}" rendered="#{flash.errorMessage.length() gt 0 }" id="mymessage" />
Even i tried below code as well
<h:inputText value="#{flash.errorMessage.length()}" id="mymessage" />
Its always showing false in textbox even i press the button.
Can someone please let me know what can be issue?
This is the answer of my problem
Ajax rendering of content which is by itself conditionally rendered
Ajax rendering takes place fully at the client side and expects the to-be-updated HTML element to be already in the JSF-generated HTML output.
Following will not work when #{bean.renderResult} defaults to false:
<h:form id="form">
<h:commandButton value="Submit" action="#{bean.toggleRenderResult}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:outputText id="result" value="#{bean.result}" rendered="#{bean.renderResult}" />
You need to ensure that the render ID points to a component which is already present in the JSF-generated HTML output.
Following will work:
<h:form id="form">
<h:commandButton value="Submit" action="#{bean.toggleRenderResult}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:panelGroup id="result">
<h:outputText value="#{bean.result}" rendered="#{bean.renderResult}" />
</h:panelGroup>
http://balusc.blogspot.in/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichIsByItselfConditionallyRendered
I want to pass user input to another page as a parameter. Here is my code:
<h:form>
<h:inputText value="#{indexBean.word}"/>
<h:commandLink value="Ara" action="word.xhtml">
<f:param value="#{indexBean.word}" name="word"/>
</h:commandLink>
</h:form>
Well, this is not working. I can read the inputtext value in my backing bean but I can't send it to word.xhtml.
Here is another approach I tried:
<h:form>
<h:inputText binding="#{indexBean.textInput}"/>
<h:commandLink value="Ara" action="word.xhtml">
<f:param value="#{indexBean.textInput.value}" name="word"/>
</h:commandLink>
</h:form>
This is also not working.
So, what am I doing wrong?
Your concrete problem is caused because the <f:param> is evaluated when the page with the form is requested, not when the form is submitted. So it remains the same value as on the initial request.
The concrete functional requirement is not exactly clear, but the particular functional requirement can be solved in basically two ways:
Use plain HTML.
<form action="word.xhtml">
<input type="text" name="word" />
<input type="submit" value="Ara" />
</form>
Send a redirect in action method.
<h:form>
<h:inputText value="#{bean.word}" />
<h:commandButton value="Ara" action="#{bean.ara}" />
</h:form>
with
public String ara() {
return "word.xhtml?faces-redirect=true&word=" + URLEncoder.encode(word, "UTF-8");
}
i have a div which consists of set of checkboxes built through foreach as follows:
<ice:panelGroup id="myDiv">
<c:forEach items="#{myBean.myCheckBoxes}" var="entry" varStatus="loop">
<input type="checkbox" name="myCheckBoxes" value="#{entry.value}" />
<span class="#{fn:contains(entry.value,'g') ? 'bold-style' : ''}">#{entry.key}</span>
</c:forEach>
</ice:panelGroup>
and i have an icefaces button in the same form of that div, and the button makes partial submit, i don't want to make full form submit.
<ice:commandButton value="Find" action="#{myBean.find}" partialSubmit="true">
<f:ajax execute="#this" render="myDiv" />
</ice:commandButton>
the search method:
public void find() {
// changes the map of the iteration
}
what happens, is that after executing search some components doesn't get removed from the div, although that they are not in the map, guess that the div is not getting refreshed/populated with data correctly, please advise, thanks.
solved by using ui:repeat instead of foreach.