filtering <rich:column> in composition component - jsf

Hopefully someone can help, because I am quite stuck on this issue. I cannot find much help elsewhere...
The high-level goal: creating a custom tag that will aid in the reuse of an extendedDataTable in Richfaces. I have a custom tag that I would like to be similar to:
<mytag:customTable bean="#{myBean}"/>
The (simplified) file that contains code for the table is as follows (table.xhtml)
<!--...header stuff -->
<ui:component>
<a4j:outputPanel>
<h:form>
<rich:extendedDataTable
value="#{bean.theData}"
var="entity"
id="table">
<rich:column filterMethod="#{...}">
<f:facet name="header">
<h:inputText value="#{bean.filterValue}">
<a4j:support event="onkeyup" reRender="table"/>
</h:inputText>
</f:facet>
<h:outputText value="#{entity.item}"/>
</rich:column>
</rich:extendedDataTable>
</h:form>
</a4j:outputPanel>
</ui:component>
Due to the constraints of the application, using the filterBy="#{...}" attribute inside the <rich:column> tag does not give me what I need.
Accordingly, I have to use the filterMethod attribute. When I hardcode the table with,
<rich:column filterMethod="#{bean.filterFunction}">
then everything works fine. However, I would like to keep the tag more general and NOT hardcode this. Instead, I would like
to also pass the name of the filtering function (e.g. <mytag:customTable bean="#{myBean}" flFcn="#{myBean.filterFunction}"> ). The problem is that
I cannot get any version of this to work properly.
From searching other threads, I see that the way to pass a method to an 'action' attribute has a syntax like: action="#{bean[fcnName]}" where fcnName is just a String (see http://digitaljoel.nerd-herders.com/2009/08/25/passing-action-methods-in-facelets-using-array-notation/).
I have confirmed that this way works correctly when it's an action . However,
this does not seem to help me in this case with filterMethod (perhaps b/c the function signature is different?). Based on those solutions, I would need something like:
<mytag:customTable bean="#{myBean}" flFcn="filterFunction"> with <rich:column filterMethod="#{bean[flFcn]}">
I have not found anything among the many permutations of EL syntax that works. Everytime, this approach throws an exception saying that 'bean' resolved to null.
To check that the bean was actually recognized, I had it print a String via <h:outputText value="#{bean.someString}"/>
(removing the offending filterMethod=...)and there is NO problem. Therefore the problem seems to lay entirely on whatever filterMethod receives. I found what I believe to be a very similar issue here, but that does not seem to be answered.
Thanks in advance!

I'm facing the same problem using RichFaces 3.3.3 and JSF 1.2 without having a usable solution.
Found a JIRA-entry at RichFaces which is still open and thus probably will not be fixed anymore.

Related

JSF Combine ui:param with composite component

you have saved me many times ago with this forum, but now I am really stuck and don't now where to search any longer...
I always get the following error message (warning level, but method is also not executed correctly):
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'editor' resolved to null: javax.faces.FacesException: #{cc.attrs.selectionListener}
I have isolated the problem to a few lines of code:
This is my main file:
<c:forEach items="#{myBean.getEditors()}" var="currentEditor" >
<ui:include src="#{currentEditor.getPanel()} >
<ui:param name="editor" value="#{currentEditor} />
</ui:include>
</c:forEach>
The bean.getEditors() (session scoped) just returns a list with one single entry at the moment. The 'editor' is a POJO with some simple attributes and two listener methods. The listener method does only write a log entry. (Should of course do more in future)
The file which is included looks like this:
<h:selectOneMenu value="#{editor.menuValue}>
<f:selectItem itemValue="Value 1" />
<f:selectItem itemValue="Value 2" />
<a4j:ajax event="change" listener="#{editor.menutListener()}" />
</h:selectOneMenu>
<myComponent:treeComponent id="tree" selectionListener="#{editor.treeListener()} />
The component I created consists of a richfaces tree and when clicking on a node the following method is called:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.selectionListener} />
I am quite confident that the composition itself is ok because I use it also at different places. When I remove the action from the a4j:jsFunction it also works perfect.
For me it smells a bit like the bug JSF 1223
The workaround does not work for me - probably because I create the param in the forEach.
I had similar problems (ui:param + component) before, but was able to solve them with giving the full path as attribute instead of a parameter. But this does not work here because it is used in too many different places.
Please help, I cannot be the only one with this problem, but I simply do not find any other threads for this.
Edit:
Today with a fresh mind I came even closer to the problem. You can forget the whole include/ forEach stuff...
<myComponent:treeComponent id="tree" selectionListener="#{myBean.getSingleEditor().treeListener()} />
Does work, while
<ui:param name="editor" value="#{myBean.getSingleEditor()} />
<myComponent:treeComponent id="tree" selectionListener="#{editor.treeListener()} />
does not work.
Well the JAVA code is performed, but the error is written to the log and the render and oncomplete method of the jsFunction do not work.
I also tried to use "data" instead of "action" for testing. No error is written to log, but JAVA method is not even called.
After many days of try&error I found a solution that is working for me:
I splitted up the listener method to one parameter with the JAVA class and one parameter with the the method name (as simple String)
The action method now looks like:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass[cc.attrs.listenerMethodName]}" />
Not nice but working... Perhaps it helps someone - or anybody can explain more...
By the way, the following was not working for me:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass[staticMethodName]}" />
While this was ok...
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass.staticMethodName()}" />
Don't know - perhaps my head is running agains the same wall again and again...

What does <f:facet> do and when should I use it?

I have been having trouble with the tag <f:facet>. I am working form other examples of code which use it, but I'm not sure exactly what purpose it serves.
I have written some code which in method is exactly the same as other code I have seen which works, except there's is wrapped in a <f:facet name=actions> tag. When I add this around my code the drop down box I am wrapping it around disappears when I deploy. Anyone able to suggest a reason for this or give me an insight into how and when to use facet?
Here is my code, I won't bother adding the bean code as they're just basic getters and setters and I don't think they're causing the trouble.
<f:facet name="actions">
<p:selectOneMenu id="SwitchWeekDrpDwnMenu"
value="#{depotWorkloadBean.selectView}"
partialSubmit="true">
<p:ajax update="mainForm"
listener="#{depotWorkloadBean.updateView}" />
<f:selectItem itemLabel="Day view" itemValue="Day"/>
<f:selectItem itemLabel="01/01/2014" itemValue="Week"/>
</p:selectOneMenu>
</f:facet>
If I remove the facet tag the dropdown box displays, but doesn't function as it should with the beans.
A facet represents a named section within a container component. For example, you can create a header and a footer facet for a dataTable component.
https://web.archive.org/web/20170828020413/http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_facet.html
It's useful when you want to create component that uses some code from user (let's say wrapper).
ie. when you want to create component that hides long text and shows short version of it. You can use just the element body, but then you will get only one value, if you want to get from user the short AND the long version then you can not do it in one value (without using some discriminant), just use facet and say which one is the long and which is the short version.
<textShortener>
<f:facet name="short">
This text is short.
</f:facet>
<f:facet name="long">
This text is too <b>long</b> to be showed when page loads. User have to click the button after the short text to show this.
</f:facet>
</textShortener>
Yes, this can (and should) be done with jsf templating, but I hope you got it.
To question: you defined facet just in the wild xml, nobody requested it so nobody processed it - that's why it did not throw error nor showed anything.

Filtering issues (no change in contents) in datatable primefaces 3.5, sorting works

Primefaces 3.5 doesn't seem to filter data at all from the datatable, oddly enough it somehow reorders them as I type, so, there must be some AJAX calls firing, but obviously not the right ones.
<h:panelGroup id="table-wrapper-component">
<prime:dataTable
rendered="#{artifactSelectionBackingBean.visibleComps}"
value="#{artifactSelectionBackingBean.components}"
var="tagInfoObject" emptyMessage="No tags found with given criteria"
filteredValue="#{artifactSelectionBackingBean.filteredComponents}">
<prime:ajax event="filter" global="false" />
<prime:column sortBy="#{tagInfoObject.tagId}"
headerText="Identifier" filterMatchMode="contains" filterBy = "#{tagInfoObject.tagId}">
<h:outputText value="#{tagInfoObject.tagId}" />
</prime:column>
<prime:column sortBy="#{tagInfoObject.type.tagTypeId}"
headerText="Tag Identifier" filterMatchMode="contains" filterBy ="#{tagInfoObject.type.tagTypeId}">
<h:outputText value="#{tagInfoObject.type.tagTypeId}" />
</prime:column>
<prime:column sortBy="#{tagInfoObject.title}" headerText="Title" filterMatchMode="contains" filterBy="#{tagInfoObject.title}">
<h:outputText value="#{tagInfoObject.title}" />
</prime:column>
<prime:column filterBy="#{tagInfoObject.description}"
filterMatchMode="contains" sortBy="#{tagInfoObject.description}"
styleClass="wrap" headerText="Component Description">
<h:outputText value="#{tagInfoObject.description}" />
</prime:column>
</prime:dataTable>
</h:panelGroup>
Any help is appreciated! All the Beans and method calls exist and return the appropriate data, just that the filtering doesn't seem to work at all.
Also, note that sorting functions properly only filtering does not!
The issue was that you always need to wrap any filtering/sorting attributes in a data table with an h:form tag. This is not explicitly specified in the documentation of PrimeFaces, however, it is in the showcase here. I wrapped the whole thing in form tags.
So, don't forget to wrap your data tables in a form if you want any type of interaction provided by primefaces.
Your managed Bean Code will do a lot of good
Post your managed bean code.
May be you have not set the value for artifactSelectionBackingBean.filteredComponents in the managed bean

RichFaces rich:panel header not appearing

I specified this
<rich:panel>
<f:facet name="header">
Panel #1. Changing Style Synchronously
</f:facet>
Each component in the RichFaces has a pre-defined set of classes you can manipulate with. If defined, those
classes overwrite the ones come from the skin.
</rich:panel>
from the RichFaces demo, in my JSF page and no header appears, although I've nothing in my css which would interfere. What might be the reason for this?
Thanks
i dont see any problem with using f:facet
try
<f:facet name="header">
<div><h:graphicImage value="/images/search.png" />
<h:outputText value=" Action Logs Search" /></div>
</f:facet>
in order to regenerate the error you mentioned
Mine disappeared when I accidentally included the panel's facets in the panel form. The facets must be children of the modal panel:
<rich:panel>
<a4j:form> <!-- This is trouble! -->
<f:facet name="header">
Panel #1. Changing Style Synchronously
</f:facet>
Each component in the RichFaces has a pre-defined set of classes you can manipulate with. If defined, those
classes overwrite the ones come from the skin.
</a4j:form>
</rich:panel>
OK, do please feel free to comment on why the f:facet tag is not working, but I get my nice shiny headers when I change the code so it's like this instead:
<rich:panel header="header">
Each component in the RichFaces has a pre-defined set of classes you can manipulate with. If defined, those
classes overwrite the ones come from the skin.
</rich:panel>

Formatting a double in JSF

I have a problem similar to the one found here : JSF selectItem label formatting.
What I want to do is to accept a double as a value for my and display it with two decimals. Can this be done in an easy way?
I've tried using but that seems to be applied on the value from the inputText that is sent to the server and not on the initial value in the input field.
My code so far:
<h:inputText id="december" value="#{budgetMB.december}" onchange="setDirty()" styleClass="StandardBlack">
<f:convertNumber maxFractionDigits="2" groupingUsed="false" />
</h:inputText>
EDIT: The above code actually works. I was fooled by JDeveloper that didn't update the jsp page even when I did a explicit rebuild of my project and restarted the embedded OC4J server. However, after a reboot of my computer everything was fine.
If I'm not misunderstanding your requirement, I was able to achieve formatting of the value in the input box during the rendering of the view with:
<h:inputText id="text1" value="#{...}">
<f:convertNumber pattern="#,###,##0.00"/>
</h:inputText>
I was using the Standard Faces Components in my vendor-branded Eclipse so I'm assuming the pattern attribute is part of standard JSF.
If what you are trying to do is make the value of the input text field change on screen (to correct user input), you should probably look into using one of the JSF ajax frameworks like Rich Faces.
A possible example would look like this:
<h:inputText id="december" value="#{budgetMB.december}" styleClass="StandardBlack">
<f:convertNumber maxFractionDigits="2" groupingUsed="false" />
<a4j:support event="onblur" reRender="december" />
</h:inputText>
I haven't tested this, but I think it may work.
It seems you're actually formatting a currency. There already exists a specific formatter to handle currencies that you can assign many options to:
<f:convertNumber type="currency" />
Some interesting attributes of this tag are: locale, currencyCode, integerOnly, currencySymbol and pattern.

Resources