JSF - 2 a4j:actionParam in one commandlink bug - java

I have such structure in my jsp:
<h:commandLink action=#{docbean.save}>
<a4j:actionParam name="somename" value="bill_all" assignTo="#{billdoc.billType}"/>
<a4j:actionParam name="somename" value="bill_document" assignTo="#{docbean.doctype}"/>
</h:commandLink>
While debugging i saw, that billdoc.billtype and docbean.doctype have the same values: "bill_document".
Is it bug? If not, then how can i put value to my managed-bean?
UPDATED:
Found the answer:
I had two actionParams with one name. ActionParam is f:actionListener + f:param. So, if you have several actionparams with one name, you will have the problem i had. RichFaces and JSF doesn't warn you about it.

First, you need a space here <a4j:actionParamvalue - before value
Second, You may try this instead of <a4j:actionParam>:
<f:setPropertyActionListener value="bill_all" target="#{billdoc.billType}" />
You may need to put immediate="true" on your commandLink if there are validation errors in your form. You can view these errors by adding <rich:messages /> ontop of the page.

Try using an a4j:commandLink. Or - if you stick to h:commandLink - try embedding your a4j:actionParams in an a4j:support tag.

Related

update model value although failing validation phase

First of all, I'm under JSF 1.2, RichFaces 3.3.0 and Tomahawk 1.1.9.
I have a rich:tabPanel which contains one form in each tab:
<h:form>
// This manages error messages thrown by my application:
<jsp:include page="showError.jsp" flush="true" />
<rich:tabPanel switchType="client" selectedTab="#{MyBean.selectedTab}">
<rich:tab name="tab1" label="TAB-1">
<t:subform id="subForm1">
//Some components such as h:inputText and h:selectOneMenu
<t:commandButton actionFor="subform1" action="#{BeanForm1.insertData}" value="INSERT">
<f:setPropertyActionListener target="#{MyBean.selectedTab}" value="tab1" />
</t:commandButton>
</t:subform>
</rich:tab>
<rich:tab name="tab2" label="TAB-2">
<t:subform id="subForm2">
//Some components such as h:inputText and h:selectOneMenu
<t:commandButton actionFor="subform2" action="#{BeanForm2.insertData}" value="INSERT">
<f:setPropertyActionListener target="#{MyBean.selectedTab}" value="tab2" />
</t:commandButton>
</t:subform>
</rich:tab>
</rich:tabPanel>
I want the application to keep the view in the tab where the user has submit the subform, even if it hasn't passed the validations I've defined. At this time, the 'MyBean.selectedTab` value only changes when the subform has been validated and submitted.
Is there any way to force this change even if the form fails the validations? Maybe I'm not focusing the problem in the proper way, how can I get this behaviour?
Thanks in advance.

How to call managed bean in h:outputLink when opening new page

I have a h:outputLink which opens new JSF page and sends h:param.
<h:outputLink id="lnkHidden" action="#{HistoryLinkController.linkValue("test")}" value="HistoryLink.xhtml" style="display:none">
<f:param name="id" value="#{item.aSessionID}" />
</h:outputLink>
I want when I click it to send a value to a second managed bean. I tried to implement it with action="#{HistoryLinkController.linkValue("test")}" but I get error. Is there any attribute that I can use for this purpose?
Try using a <h:commandLink> in the following way and it should work fine
<h:commandLink id="hLink" value="History" action="#{HistoryLinkController.linkValue}" >
<f:param name="sessID" value="#{item.aSessionID}" />
</h:commandLink>
and the bean "HistoryLinkController" should have a method like
public String linkValue(){
// get "sessID" from FacesContext
...
return "/HistoryLink.xhtml";
}
Replace h:outputLink into h:commandLink.
I have also tried to navigate to some view along with passing a value to another bean already but I didn't get it. But what I got is---
U can remain in the same bean class if possible, and use navigation rules in faces-config.xml for navigating to another page.
And In ajax, action will be called earlier than its actionListener.
Hope it helps you finding a way...

primefaces p:message outside the components form

I'm using JSF 2.0 and Primefaces 3.2.
I'm using Facelets for templating, and I've built a 3-column layout:
Left column - mainContent column - Right column. Each column got it's own template xhtml file with ui:composition which I insert in a mainTemplate.
In the mainContent column I've got a info-button (p:commandButton):
<h:form id="mainForm">
<p:commandButton id="infoButton" value="Info" actionListener="#{faceletsAttachment.addInfo}"/>
</h:form>
But I want the info to show in the right column, with a
<h:form id="rightColumnForm">
<p:message for="infoButton">
</h:form>
This obviously does not work, because does not find the infoButton. Any idea how I can make this work? I tried
<p:message for="mainForm:infoButton">
too, but no cigar.
The reason I want to use a p:message is that I want the message to position itself on the y-position the infoButton has. If you got an alternative solution to how I can do this, I would also appreciate it.
If you are adding messages manually from server side you can do the following
<p:message id="myInfoButton" for="myInfoButton" />
and send messages from server to myInfoButton like this
FacesContext.getCurrentInstance.addMessage("myInfoButton ", new FacesMessage("My Message", "Some Text goes here..."));
also add :rightColumnForm id to update of the <p:commandButton id="infoButton"

#all in JSF Ajax does not work

This line is inside a form tag:
<p:commandLink actionListener="#{questionBean.removeQuestion(question)}"
value="Delete" styleClass="delete" update="#all"/>
However, it only works with #form. Nothing happens when I have #all. I want to be able to update not only the form but also other parts of the page.
Seems that update="#all" not supported by primefaces
although its a bit diff question update="#all" is not working with "ui:include ..."
but still its being said several time that
update="#all" does not work with PimeFaces.
another ref : Issue 2026: update="#all" is not working PrimeFaces ajax.
Try with process="#all" as explained here.
<p:commandLink actionListener="#{questionBean.removeQuestion(question)}"
value="Delete" styleClass="delete" process="#all"/>
I think it may be a bug. Even if you use JSF's <f:ajax render="#all">, it may also does not work. To solve this, I think you can simply set the id attribute of the body tag to, for example, mySexyBody. Then you can do update="mySexyBody".

No component found to process as 'ajaxSingle'

Found strange problem, possibly bug.
I have 2 identical web-pages with Richfaces:suggestionbox.
On the first one my suggestionBox is doing well, everything works fine, but on another one i have some problems. SuggestionBox doesn't show my suggestions. In logs i have something like this:
WARNING: No component found to process as 'ajaxSingle' for clientId remains-form:konta-suggest
2010.1.9 12:02:29 org.ajax4jsf.component.AjaxViewRoot processPhase
Any conclusions?
UPD:
<h:inputText value="#{repobean.kont}" id="kont" label="Payer" style="width:230px;"/>
<rich:suggestionbox onobjectchange="printObjectsSelected(#{rich:element('konta-id')}, #{rich:component('konta-suggest')}, 'id');" usingSuggestObjects="true" width="230" var="result" fetchValue="#{result.kont}" suggestionAction="#{kontabean.suggest}" id="konta-suggest" for="kont">
<h:column>
<h:outputText value="#{result.kont}"/>
</h:column>
<h:column>
<h:outputText value="#{result.kontName}"/>
</h:column>
</rich:suggestionbox>
<h:inputHidden id="konta-id" value="#{repobean.kontId}" />
Javascript inside onobjectchange is a function which prints id into konta-id.
The code of jsp on the second page is copy-pasted from the first page.
I know, the question is 5 years old, but we had this same error (with different components)
In our case we have changed the outer ui:repeat to an a4j:repeat.
After that, our components worked as expected.
What you can do, when you encounter Ajax problems, is to add the <a4j:log> component:
<a4j:log popup="false"/>
This will create a box in your page with all the Ajax logs from Richfaces. Eventually, you can set popup="true" and then display the popup by Ctrl + Shift + L
There are many logs in this panel, but generally the important things to look at is the WARN or ERROR messages.
Other concern about your error message: it is talking about some ajaxSingle processing. In your JSF code, you have no ajaxSingle attribute defined. When does this error happens? When you start typing some characters in your inputText component?
Isn't there any conditional rendering (rendered="#{some expression}") around this input and suggestion components? Or an iteration?
Does .suggest() action get invoked before this error?
Situations like you've described happen when an action-related (causing) component is within a conditional render (or an iteration) which does not allow a component to be created on RestoreView phase. Then action is not called at all and component-id is not found in the component tree.
Example: if you have something like this:
<h:panelGroup rendered="#{not empty myBean.valueSetInActionHandler}">
<h:commandLink id="action1" action="#{myBean.callOtherAction" value="appears after action"/>
</h:panelGroup>
<h:commandLink id="action2" action="#{myBean.setValueInActionHandler}" value="display button above"/>
First render - only one, second button is rendered. If setValueInActionHandler sets some value and displays the same page - first button ("appears after action") will get rendered too. But clicking it won't fire a callOtherAction - because on second request, during RestorePhase valueInActionHandler is empty again, so action1 will not be available...
Hope I managed to make myself clear :)
I think a4j taglib is missing on the page.

Categories

Resources