I'm using JSF 1.1 in WAS 5 (Websphere Application Server 5), and I need to know what Column in my HtmlDataTable was clicked, I have tried by many ways but I can not get a Success result, the only thing I need is to pass a parammeter to an action.
I have something like
<h:form>
<h:datatable value=#{bean.list} var="row">
<h:column>
<f:facet name="header">
<h:outputText value=""/>
</f:facet>
<h:commandButton value="Test!" action="#{bean.saludar}">
<f:param name="cod" value="#1"/>
</h:commandButton>
</h:column>
</h:datatable>
</h:form>
In my BackingBean I have
public class Bean {
......
......
public String saludar() {
FacesContext context = FacesContext.getCurrentInstance();
Object value = context.getExternalContext().getRequestMap().get("cod");
//value IS NULL !!!!!!!!!!!!!!!!!!! HELP HERE OR BEFORE ....
}
}
I have tried many ways, I don't know if the problem is because I am inside a HtmlDataTable or something like that, I can know the selected Row by binding de table to one HtmlDataTable and accesing to the method table.getRowData(); I have almost 3 days And i can not find a solution, I have tested in JSF 1.2 With Glassfish 3.1 and it worked, but I dont know how to get work that in WAS 5 with Java 1.4
Thnkxx !!
In JSF 1.x, the <f:param> is not supported in command buttons. This support is since JSF 2.0 only.
There are several ways to achieve your concrete requirement (btw, the requirement to know the clicked column is quite strange, perhaps you actually meant "row" when you said "column"?).
Use <h:commandLink> instead of <h:commandButton>. It supports <f:param>.
Use <f:setPropertyActionListener> instead of <f:param>.
Use UIData#getRowData() or DataModel#getRowData() instead to obtain the current row.
Install JBoss EL and just pass the row itself directly like so action="#{bean.saludar(row)}".
See also:
Communication in JSF
Using datatables (in JSF 1.x)
Invoking methods with parameters by EL in JSF 1.2
Related
How can I use (eg ajax) to show a specific jsf element if I click the button where the ajax tag belongs to? But without having to use any backing bean, just by JSF components without JavaScript?
Is that possible?
Luiggi is right , You better use js for client side toggling
But ,
I think you can bind like this
<h:inputText id="first" binding="#{someViewButNonManagedBeanObject}"`...
and than
<h:inputText id="second" render="#{no empty someViewButNonManagedBeanObject}"`...
or
<h:inputText id="second" render="#{someViewButNonManagedBeanObject.value eq 'wow'}"`...
(Not tested)
I'm in the process of migrating our primary application from Seam 2.2 to Seam 2.3beta1, in order to get some of the benefits of JSF 2.0 and JPA 2.0. For the most part, it's going smoothly. However, some of the Ajax changes in JSF 2.0 and Richfaces 4.x are proving to be problematic in porting the code.
I have a series of components that are populated based on the contents of the others. For example, the first menu selects the item category. When a value is selected, the subcategories of that category are retrieved from the database and act as the selection items for the second menu. This entire process is Conversation scoped. Currently, the code looks like this:
<h:selectOneMenu value="#{newObjAction.category}"
required="true"
requiredMessage="You must select a category"
style="width:300px;">
<s:selectItems var="cat"
value="#{newDesignAction.designCategories}" label="#{cat.name}"
noSelectionLabel="Select a category..."
hideNoSelectionLabel="true" />
<s:convertEntity />
<a:support event="onchange" reRender="subCategoryPanel"
limitToList="true" ajaxSingle="true" status="subCategoryStatus" />
</h:selectOneMenu>
This works with no problem in Seam 2.2 with JSF 1.2. However, has been removed from JSF 2.0. I've tried something like this in its place:
<f:ajax listener="#{newObjAction.handleCategoryChange}">
It fires the event as expected, but there's one large problem: it is not propagating the conversation. As a result, when the listener object is about to be called it is intercepted and the user is redirected to the defined no-conversation-view-id from pages.xml. Is there any way to propagate the conversation when using <f:ajax />? Is there a better way to accomplish this? At this point the entire migration is at a stand still, as this is a major component in the application.
I'd REALLY appreciate any help or advice.
I have JSF page has two drop down lists and I want to load the second one with values based on what was chosen in the first one. However, the "onchange" event is only detected the second time I change the selection!
Web page Code snippet:
<h:form id="selectRegion">
<h:selectOneMenu id="governorate"
value="#{SearchView.governorate}"
styleClass="mediumInput" immediate="true"
valueChangeListener="#{SearchView.goverValueChanged}"
onchange="submit();">
<f:selectItems value="#{SearchView.goverItemsList}" id="govItems" />
</h:selectOneMenu>
<h:selectOneMenu id="district"
value="#{SearchView.district}"
styleClass="mediumInput">
<f:selectItems value="#{SearchView.districtItemsList}" id="distItems" />
</h:selectOneMenu>
</h:form>
<h:form id="SearchFor">
<hx:commandExButton
id="button1" styleClass="btn" type="submit"
value="Search" action="#{SearchView.searchAction}"
onclick="document.getElementById('selectRegion').submit();">
</hx:commandExButton>
</h:form>
The problem is that goverValueChanged(ValueChangeEvent event) is invoked only when I modify the value of the governorate for the second time but not for the first time (I put system out in goverValueChanged(ValueChangeEvent event) to know that).
Does anyone have an idea regarding what might be wrong? Thanks in advance! I am using JSF 1.1 and run on IBM WAS
It has been a long time ago I fighted with IBM and JSF 1.1 for last time, but I vaguely recall some ancient JSF 1.1 bug which caused that the valueChangeListener won't be fired when the initial value is null. I'd suggest to set the initial value (the property behind value="#{SearchView.governorate}") to an empty string or to something else.
You can of course also upgrade JSF 1.1 to the latest build JSF 1.1_02. It has pretty a lot of functional bugfixes, maybe it will also fix this (and other) problems. IBM WAS 5.x namely ships with a very early version of JSF 1.1 which is cluttered of some odd bugs like that. Or maybe you're using IBM WAS 6.x, then you can also dump JSF 1.1 altogether and go for the much improved JSF 1.2. You can download JSF libraries from the archives right here.
I have a rich:togglePanel with two facets. I want the contents of the togglepanel, whatever facet is active at that case, to have width=100% and height="100%". For this I have created the expandAll.
The problem is that the facet "renders" a div named togglePanel_open, whose content (the panelGrid) has class expandAll, but itself (the togglePanel_open) does not. As such, its contents "stretch" to their parent, which unfortunately does not "stretch" to its own parent, which is what I would like to achieve.
Has anyone any idea how to overcome this?
Cheers!
<rich:togglePanel id="treeTogglePanel"
styleClass="expandAll" value="open" switchType="client"
stateOrder="open,closed">
<f:facet name="open">
<h:panelGrid styleClass="expandAll"
...
</h:panelGrid>
...
</f:facet>
<f:facet name="closed">
<h:panelGrid styleClass="expandAll"
...
</h:panelGrid>
...
</f:facet>
UPDATE: What I currently do to work around the problem (not solve it) is that I explicitly define in the CSS the style of the element #togglePanel_open. But this is a very nasty hack (or as we say in Greece, a very "Tarzan-like" thing to do:-) ), because if in the next Richfaces version they name the generated divs differently, this will stop to work.
I have a Hashtable<Integer, Sport> called sportMap and a list of sportIds (List<Integer> sportIds) from my backing bean. The Sport object has a List<String> equipmentList. Can I do the following using the unified EL to get the list of equipment for each sport?
<h:dataTable value="#{bean.sportIds}" var="_sportId" >
<c:forEach items="#{bean.sportMap[_sportId].equipmentList}" var="_eqp">
<h:outputText value="#{_eqp}"></h:outputText>
<br/>
</c:forEach>
</h:dataTable>
I get the following exception when trying to run this JSP code.
15:57:59,438 ERROR [ExceptionFilter] exception root cause
javax.servlet.ServletException: javax.servlet.jsp.JspTagException:
Don't know how to iterate over supplied "items" in <forEach>
Here's a print out of my environment
Server: JBossWeb/2.0.1.GA
Servlet Specification: 2.5
JSP version: 2.1
JSTL version: 1.2
Java Version: 1.5.0_14
Note: The following does work using a JSF tag. It prints out the list of equipment for each sport specified in the list of sportIds.
<h:dataTable value="#{bean.sportIds}" var="_sportId" >
<h:outputText value="#{bean.sportMap[_sportId].equipmentList}">
</h:outputText>
</h:dataTable>
I would like to use the c:forEach tag. Does anyone know if this is possible? If not, anyone have suggestions? In the end I want a stacked list instead of the comma seperated list provided by equipmentList.toString(); (Also, don't want to override toString()).
#keith30xi.myopenid.com
Not TRUE in JSF 1.2. According to the java.net wiki faq they should work together as expected.
Here's an extract from each faq:
JSF 1.1 FAQ
Q. Do JavaServer Faces tags interoperate with JSTL core tags, forEach, if, choose and when?
A. The forEach tag does not work with JavaServer Faces technology, version 1.0 and 1.1 tags due to an incompatibility between the strategies used by JSTL and and JavaServer
Faces technology. Instead, you could use a renderer, such as the Table renderer used by the dataTable tag, that performs its own iteration. The if, choose and when tags work, but the JavaServer Faces tags nested within these tags must have explicit identifiers.
This shortcoming has been fixed in JSF 1.2.
JSF 1.2 FAQ
Q. Do JavaServer Faces tags interoperate with JSTL core tags, forEach, if, choose and when?
A. Yes. A new feature of JSP 2.1, called JSP Id Consumer allows these tags to work as expected.
Has anyone used JSF tags with JSTL core tags specifically forEach?
I had the same problem once, and I couldn't find a solution using dataTable.
The problem is that the var _sportId can be read only by the dataTable component.
If you need to do a loop inside a loop, you can use a dataTable inside a dataTable:
<h:dataTable value="#{bean.sportIds}" var="_sportId" >
<h:dataTable value="#{bean.sportMap[_sportId].equipmentList}" var="_eqp">
<h:outputText value="#{_eqp}"></h:outputText>
</h:dataTable>
</h:dataTable>
But in this case each of yours equipmentList items is printed inside a table row. It was not a great solution form me.
I chose to use a normal html table instead of a dataTable:
<table>
<c:forEach items="#{bean.sportIds}" var="_sportId">
<tr>
<td>
<c:forEach items="#{bean.sportMap[_sportId].equipmentList" var="_eqp">
<h:outputText value="#{_eqp} " />
</c:forEach>
</td>
</tr>
</c:forEach>
</table>
It works. If you need some specific dataTable functionality like binding and row mapping, you can obtain it in an easy way using the f:setPropertyActionListener tag.
Two issues:
A dataTable can only have the following children: header facet, footer facet, column. Anything else is not going to be evaluated correctly.
JSTL tags cannot be interweaved with JSF components. The JSTL tags are evaluated when the component tree is created. JSF components are evaluated when the page is rendered. Thus, the c:forEach tag is only evaluated once - when the component tree is created, which is likely before "#{bean.sportIds}" is available.
Either use a JSF component library that provides the looping like you desire, build one that does the looping you desire, or refactor the beans so that instead of looping over the sportIds, loop over a list of sports where each sport has its id and equipment.