Link to external URL using richfaces - java

I am currently displaying a ticket number like so.
<h:outputText value="#{ticket.ticketNumber}" />
Instead of this I want a hyper-link to a URL.
The address will look similar to this: http://testserver.com/viewer.jsp?ticket=#{ticket.ticketNumber}
So, the new code might look something like this (note the code below doesn't work, just a concept).
<a4j:commandLink action="http://testserver.com/viewer.jsp?ticket=#{ticket.ticketNumber}"
value="#{ticket.ticketNumber}" />

command* controls are generally UICommand instances - for invoking server-side logic. Use an outputLink:
<h:outputLink
value="http://testserver.com/viewer.jsp?ticket=#{ticket.ticketNumber}">
<h:outputText value="#{ticket.ticketNumber}" />
</h:outputLink>

Related

How to render more JSF components by using a ui:repeat component?

I have a question concerning the jsf component . Here is a small code example:
<ui:repeat var="bean" value="myBean.myListToIterate">
<h:selectOneCheckbox value="#{myBean.specificField}" />
#{bean.car.name}
</ui:repeat>
Question 1: Why the expression #{bean.car.name} alone inside the ui:repeat element and why not for example in a
<h:outputLabel value="#{bean.car.name}" />"?
If i use this, nothing will be displayed.
Question 2: Why does this example doesn´t look very well, if i use a
<h:selectOneRadio value="#{myBean.specificField}"/> component
instead of a
<h:selectOneCheckbox value="#{myBean.specificField}"/> component?
Greetz
Marwief
Answer 1 :
EL JSF expressions are allowed in the last JSF versions. So it can be put without any wrapping tag (like <h:outputText />).
Using this <h:outputLabel value="#{bean.car.name}" /> did not give result, because you did not specify for attribute to point to, in order to be rendered as label of its client id, which means, it cannot be used alone.
Answer 2 :
First, this JSF tag <h:selectOneCheckbox /> doesn't exist, maybe you wanted to mean <h:selectBooleanCheckbox />. Replacing this by <h:selectOneRadio ... /> does not look very well, because this last one needs <f:selectItem /> or <f:selectItems /> to hold choices from where the end user will be able to choose between (i.e at least 2 choices), in the contrary of <h:selectBooleanCheckbox /> which can have no child select item(s) tag(s) in the case of one alone choice to (un)check.

f:ajax listener isn't called

I've got a problem considering JSF and AJAX.
I am trying to update some customer details after a visitor inserts the customer id.
Firstly, a excerpt from the xhmtl code:
<h:form>
<h:panelGrid columns="2">
<h:panelGrid columns ="2" border="1" id="customer_grid">
<h:outputLabel value="#{mbean_msg.reservation_lblCustomerNo}" for = "customer_id"/>
<h:inputText id = "customer_id" value="#{reservationHandler.customer.customer_id}">
<f:ajax listener="{reservationHandler.autocompleteCustomerDetails}"
render="customer_grid" />
</h:inputText>
<h:outputLabel value="#{mbean_msg.reservation_lblLastname}" for="lastname"/>
<h:inputText id="lastname" value="#{reservationHandler.customer.lastname}" required ="true"
requiredMessage="#{error_msg.errmsgLastname}" validator="#{reservationHandler.validateCustomer}"/>
<h:outputLabel value="#{mbean_msg.reservation_lblFirstname}" for="firstname"/>
<h:inputText id="firstname" value="#{reservationHandler.customer.firstname}" required ="true"
requiredMessage="#{error_msg.errmsgFirstname}" validator="#{reservationHandler.validateCustomer}"/>
The listener method is implemented within my java file (ReservationHandler.java) like that:
public void autocompleteCustomerDetails(){
System.out.println("Auto Complete"); // for testing
}
Basically I am trying to call the method autocompleteCustomerDetails with the Listener. Unfortunately this method is never called. Anyways, the render seems to work just fine, since the other inputTexts update themselves (visibly).
Does anybody have an idea, why the listener isn't called?
There are two problems in the code shown so far:
First,
<f:ajax listener="{reservationHandler.autocompleteCustomerDetails}" />
this isn't a valid EL expression. EL expessions have the form of #{}, not {}. Fix it accordingly:
<f:ajax listener="#{reservationHandler.autocompleteCustomerDetails}" />
Second,
public void autocompleteCustomerDetails() {
this isn't a valid default signature of a method expression for <f:ajax listener>. The tag documentation clearly tells the following:
signature must match public void processAjaxBehavior(javax.faces.event.AjaxBehaviorEvent event) throws javax.faces.event.AbortProcessingException.
So, you forgot the argument. Add it accordingly. The throws declaration isn't mandatory for unchecked exceptions, so we can just leave it out.
public void autocompleteCustomerDetails(AjaxBehaviorEvent event) {
Or, if you actually intend to get rid of the argument, then you should put parentheses in the EL method expression:
<f:ajax listener="#{reservationHandler.autocompleteCustomerDetails()}" />
Note that this works only if your container supports EL 2.2.
Try this:
<f:ajax listener="{reservationHandler.autocompleteCustomerDetails()}"
render="customer_grid" />
or change the method to:
getAutoCompleteCustomerDetails
just for testing...
Anyhow, you´re not allowed to use any jsf's components library? Like primefaces ?
It gets the job done in such a easy way...
Anyhow, with primefaces I would do that like this:
<p:ajax event="blur" listener="#{prospectoRadarController.atualizarRadar(data)}" update=":mainForm:painelRadar" />
Another guess would be, add the execute="#this" to the ajax flag...
Sorry, those are all wild guesses, but I really want to help.
PLease feedback!

Call rich:modalPanel for every ajax request with out using a4j:status?

I am developing web application using JSF richfaces.I have one rich:modalpanel in main templete. This modalPanel have 'Your request is processing....." message.
I want to show this message(modalPanel) every action(ajax request). But without using a4j:status element.
Is there possible to acheive this(using listener or any otherway)?
How to show the wait modalPanel for all action using listener?
Help me about this.
Thanks in advance.
Update :
If i use my main templete,
<a4j:status id="waittingMessage"
onstart="javascript:Richfaces.showModalPanel('progressWaitModalPanel');"
onstop="javascript:Richfaces.hideModalPanel('progressWaitModalPanel');"/>
And i call the above a4j:status for the following places :
The following each and every component i use more than 100 place in my application
<a4j:commandButton status="waittingMessage"/>
<a4j:commandLink status="waittingMessage"/>
<h:selectOneMenu><a4j:support status="waittingMessage"/> </h:selectOneMenu>
<h:selectOneRadio><a4j:support status="waittingmessage"/></h:selectOneRadio>
<h:selectBooleanCheckbox><a4j:support status="waittingmessage"/></h:selectBooleanCheckbox>
In future,
i don't need to show the progressWaitModalPanel, that time i will delete a4j:status
in main templete.
But what about this status="waittingMessage"? Because this status="waittingmessage" i added more than 1000 places in my whole application.
<a4j:status> is the proper way to do this. I don't know of any other way. Perhaps you can hook to some low-level javascript, but that would be the wrong thing to do.
If the status is in the current form, there is no need to explicitly indicate which is the status - it is used by default.
<a4j:status id="waittingMessage"
onstart="Richfaces.showModalPanel('id_modalPanel')"
onstop="Richfaces.hideModalPanel('id_modalPanel')">
<f:facet name="start">
<label></label>
</f:facet>
<f:facet name="stop">
<label></label>
</f:facet>
</a4j:status>
<ui:include src="/modalPanel.xhtml" />
modalPanel.xhtml can contain display related content.
you can put the content above in a separate file say status.xhtml and then include it in your other pages
as below:
<a4j:outputPanel ajaxRendered="true">
<ui:include src="status.xhtml" />
</a4j:outputPanel>
so any page that has ajax request will display above message window
You need not add any status msg for each a4j:button ,etc.

JSF 2 composite:actionSource exposing commandButtons in ui:repeat

In my composite component, I have a ui:repeat that has, among other static things, a command button, like this:
<ui:repeat var="article" value="#{cc.attrs.articleList}"&gt
<strong>Aricle: #{article}</strong>
<h:commandButton id="addToFavs" value="Subscribe" binding="..." type="..." >
<f:setPropertyActionListener value="#{article}" target="..." />
</h:commandButton >
</ui:repeat>
Now, I'd like to expose this event in the composite interface, so that in my page, I may attach event listeners and tie in f:ajax.
Had it been outside of ui:repeat (i.e., there existed only one such button), that would have been quite easy, like this:
<composite:interface>
<composite:actionSource name="addToFavs" targets="#{cc.clientId}:addToFavs" />
<composite:clientBehavior name="ajax" default="true"
event="action" targets="#{cc.clientId}:addToFavs"/>
</composite:interface>
But that fails in this case, because there's no one component by that ID (addToFavs), but rather a bunch of them. Do you know how should I expose these buttons in the interface?
Regards,
Pradyumna
Updating this post with my best guess, just in case someone wants to know if I could achieve it:
No I couldn't do it. Looks like we can't do it. We can only expose components whose IDs relative to the composite component are known to the component author apriori.

How to hide some nodes in Richfaces Tree (do not render nodes by condition)?

I have a tree of categories and courses in my SEAM application. Courses may be active and inactive. I want to be able to show only active or all courses in my tree.
I've decided to always build complete tree in my PAGE scope component since building this tree is quite expensive operation. I have boolean flag courseActive in the data wrapped by TreeNode<T>. Now I can't find the way to show courses node only if this flag is true.
The best result I've achieved with the following code:
<h:outputLabel for="showInactiveCheckbox" value="show all courses: "/>
<h:selectBooleanCheckbox id="showInactiveCheckbox" value="#{categoryTreeEditorModel.showAllCoursesInTree}">
<a4j:support event="onchange" reRender="categoryTree"/>
</h:selectBooleanCheckbox>
<rich:tree id="categoryTree" value="#{categoryTree}" var="item" switchType="ajax"
ajaxSubmitSelection="true" reRender="categoryTree,controls"
adviseNodeOpened="#{categoryTreeActions.adviseRootOpened}"
nodeSelectListener="#{categoryTreeActions.processSelection}"
nodeFace="#{item.typeName}">
<rich:treeNode type="Category" icon="..." iconLeaf="...">
<h:outputText value="#{item.title}"/>
</rich:treeNode>
<rich:treeNode type="Course" icon="..." iconLeaf="..."
rendered="#{item.courseActive or categoryTreeEditorModel.showAllCoursesInTree}">
<h:outputText rendered="#{item.courseActive}" value="#{item.title}"/>
<h:outputText rendered="#{not item.courseActive}" value="#{item.title}" style="color:#{a4jSkin.inactiveTextColor}"/>
</rich:treeNode>
</rich:tree>
the only problem is if some node is not listed in any rich:treeNode it just still shown with title obtained by Object.toString() method insted of being hidden.
Does anybody know how to not show some nodes in the Richfases tree according to some condition?
Update
For better understanding what I'm trying to do I can provide simple example:
Imagune that I have a filesystem with files and directories and there are normal and hidden files (in my case I have no hidden directories but it's not important).
I want to read files and directories once and store the tree in the model (org.richfaces.model.TreeNode) and then be able to show only directories on one page and only directories and not hidden files by default on another page with possibility to show all files and directories using checkbox on this page.
There is not enough to hede(/not render) rish:treeNode element in facelet since if there is a node which is not mentioned in any of rendered rich:treeNode this node is rendered using default icons and title. One may think about rich:treeNode like about an elemnt only to add custom visual style to nodes of some types but not as an element responsible for rendering of a node.
I'm really not sure, but maybe you could try to use a Facelets . Would the EL would be evaluated correctly, since c:if is a build-time tag?
See: http://wiki.java.net/bin/view/Projects/FaceletsFAQ#Why_doesn_t_my_c_if_ui_repeat_ui
Have you tried the <s:fragment>?
<s:fragment rendered="#{item.flag == 'true'}">
Show some stuff here when flag returns true
</s:fragment>
<s:fragment rendered="#{not item.flag}">
Show some stuff here when flag is NOT true
</s:fragment>
Update
I am not sure what your question really is, however I am guessing you want to hide a treenode
In your example it would look like this:
<s:fragment rendered="#{item.courseActive}">
<rich:treeNode type="Category" icon="..." iconLeaf="...">
<h:outputText value="#{item.title}"/>
</rich:treeNode>
</s:fragment>
<s:fragment rendered="#{not item.courseActive}">
<rich:treeNode type="Course" icon="..." iconLeaf="...">
<h:outputText value="#{item.title}"/>
</rich:treeNode>
</s:fragment>
It looks like there are two ways to solve my problem.
First one: I can use rich:recursiveTreeNodesAdaptor and in my recursive getter function I can skip some nodes. This aproach may be hard to use with drag and drop for moving items in the tree.
Second one: Attach detach some nodes on the server side. Disadvantage of this approach is a lot of Java code for recursive iterations through the tree.
I think I'll use the second way since I need drag and drop tree editor.
The same question was discussed in the JBoss comunity forum one year ago: http://community.jboss.org/message/64929
and the second way was also advised

Categories