Use currently checked value as a itemValue in ListBox - java

I have this JSF page:
<h:selectOneRadio id="regions">
<f:selectItem id="eu" value="EU"/>
<f:selectItem id="us" value="US"/>
</h:selectOneRadio>
<h:selectOneListbox>
<f:selectItems value="#{dataFetcherBean.regions}" itemLabel="..."/>
</h:selectOneListbox>
dataFetcherBean.regions is a HashMap<String, List<String>> collection. What I want, is to show different data in ListBox depending on what radio button is selected.
Is there a way to get the currently selected value in regions radio buttons to itemLabel in the ListBox?

You have 2 solutions :
1 - Use a listener to update your <h:selectOneListbox> after the event onchange of your <h:selectOneRadio>is triggered.
2 - Use <f:ajax> if you don't want to reload the full page.
See both here : SelectOneMenu updates other SelectOneMenu

Related

Table is not being refreshed after valueChangeListener is executed

I have a table that shows info from a backing bean's list attribute.
I also have a selectOneRadio that clears that list on its valueChangeListener.
Finally the table should show empty after that valueChangeListener but it keeps showing the previous info.
This is the key components in my jsp file:
The selectOneRadio:
<tr:selectOneRadio id="selectValue"
value="#{myBean.value}"
autoSubmit="true"
valueChangeListener="#{myBean.changeValue}"
layout="horizontal">
<f:selectItems value="#{myBean.values}" />
</tr:selectOneRadio>
The table:
<trh:tableLayout inlineStyle="width: 100%;" partialTriggers="selectValue">
<tr:table partialTriggers="selectValue"
id="tableResults" var="var" emptyText="No records" width="100%"
value="#{myBean.listInfo}"
selectedRowKeys="#{myBean.selectedElements}"
rowBandingInterval="1" rowSelection="multiple">
As I said, when I click the radio button the method changeValue(event) of MyBean is executed clearing the listInfo list but the table keeps showing the elements that were in the list dispite of the partialTriggers attribute.
What is wrong with this approach? Is there another way to refresh the table so it will display empty after clicking the radio button?
Thanks very much.
By removing the enclosing tableLayout tag the table gets refreshed properly as espected of partialTriggers.
I don't understand why was this happening and it would be nice if anyone can explain it but I consider the question closed.

jsf primefaces, show itemLabel not itemvalue on update

I have 2 items:
radiobuttons
outputtext
What I'm trying to do is: When the user checks a radiobutton -> get the itemLabel of the checked radiobutton in my outputtext. (not itemValue)
I have following code which shows the itemValue in the output text:
<h:form>
<p:selectOneRadio layout="pageDirection" id="test" name="testy" value="#{myBean.testValue}">
<p:ajax update="testOutput"/>
<p:selectItems value="#{myBean.getAllTestItems()}" var="selecter" itemLabel="#{selecter.label}" itemValue="#{selecter.val}"/>
</p:selectOneRadio>
<h:outputText id="testOutput" value="#{myBean.testValue}"/>
</h:form>
When i select one of the radiobuttons, I get the itemValue in the outputText. However I would like to get the itemLabel of the selected item in the outputText.
How do I get the label instead of the value of the radiobutton?
Several ways.
Get it based on the collection behind #{myBean.getAllTestItems()} which already contains the items with both the label and the value. Find the item matching the selected value in there and then get the label.
Submit #{selecter} instead of #{selecter.val} as radio button item value. This way you can display the label by #{myBean.testValue.label}. You only need to provide a Converter to convert between String (in HTML and HTTP request parameter) and Selecter (in Java model).
See also:
Our selectOneMenu wiki page
How to create Primefaces radioButtons from List? (for the case you'd like to use Selecter as value)

Call listener by clicking pencil (primefaces 2.2.1 rowEditor)

How can I call listener after clicking pencil on rowEditor?
I want to prepare text from dataTable for editing (clear html tags for tabs and return carriages).
Do you have any ideas?
Thank you.
Actually,there is no event for pencil in datatable.If you want to call listener after pencil click,you can do like that.Wrap rowEditor into commandLink.I did and it works.
<p:commandLink id="rowEditLink" action="#{teamMB.initCombo}" ajax="true"
update=":formContent:teamTable>
<p:rowEditor />
</p:commandLink >
This won't work for version 2.2.1, but it can still be relevant for others
2 year old question but it's one of the top Google results.
There is a way to do this without using <p:commandLink>
The Primefaces User Guide on page 154 talks about ajax events. There are three events of interest rowEdit, rowEditInit, rowEditCancel.
rowEditInit is the event that triggers when a row switches to edit mode
rowEditCancel is the event that triggers when a row edit is cancelled
So your code should look like this
<p:ajax event="rowEditInit" listener="#{tableBean.onEditInitCleanUp}" update="#form">
Then your listener would do the appropriate clean up.

Primefaces datatable: what 'onRowSelectUpdate="display"' means?

I'm using the primefaces datatable and I've seen many times the onRowSelectUpdate event calling "display"?
What "display" means? is it a public method of the component or something?
It refers the ID of the component which is to be ajax-updated whenever you select a row. For example, a detail display.
<p:dataTable id="mytable" onRowSelectUpdate="mydisplay">
...
</p:dataTable>
...
<p:someComponent id="mydisplay">
<p>This component will be ajax-updated whenever a row is selected.
</p:someComponent>
From the PrimeFaces user guide, page 127:
Component(s) to update instantly after a row is selected.
Sounds like it works in the same way as the Ajax update attribute, but is activated when a row is selected in a data table. I've never used it myself so I don't have any code samples to share.

Struts 2 radio button value.?

i have following code in jsp used with struts2 radio button i want to know which radio button is selected in my action class so can anyone give me solution on this.
code:
<div>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'Postponed To'}"/>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'Suspended'}"/>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'cancelled'}"/>
</div>
i use diffrent radio with same name so that are displayed each in new row...
I dint understand why you need all the radio buttons with the same name.. If the names are different add the getter/setter for all the radio buttons in the actions with there same names, the in action exectute() method check the values of the radio button for true or false as
if(formFieldRadio == true)
u get to know its checked or not
You are doing it wrong, you should do it like this:
<s:radio name="selectAction" list="#{1:'Postponed To', 2: 'Suspended', 3: 'cancelled'}" />
Then in your action you should expect a numeric value (in this case, 1, 2 or 3) in an selectAction variable.
make sure you have the theme="simple" attribute so you can play freely with your css.

Categories

Resources