I would like to nest multiple setPropertyActionListener's in my commandLink but only one works. How do you attempt this? This command link sets properties and then opens a dialog so its basically initializing the dialog.
How is this accomplished?
<p:commandLink update=":dreamWebSearchFrm" value="#{bundle['dreamModify.search.link.TEXT']}" oncomplete="webSearchDlg.show()">
<f:setPropertyActionListener value="false" target="#{dreamSearchBean.shouldRender}"/>
<f:setPropertyActionListener value="true" target="#{dreamSearchBean.shouldRender1}"/>
</p:commandLink>
You could make use of EL parameters and call a single method on your bean. From that method, update whatever you want.
e.g.
#{dreamSearchBean.shouldRenderInit(false, true)}
In your bean:
public void shouldRenderInit(boolean one, boolean two) {
setShouldRender(one);
setShouldRender1(two);
}
I try with
<p:commandLink update=":dreamWebSearchFrm" value="#{bundle['dreamModify.search.link.TEXT']}" oncomplete="webSearchDlg.show()">
<f:setPropertyActionListener value="#{false}" target="#{dreamSearchBean.shouldRender}"/>
<f:setPropertyActionListener value="#{true}" target="#{dreamSearchBean.shouldRender1}"/>
</p:commandLink>
It is correct with JSF 1.2 and richfaces.
I use the following command to set property value
<f:setPropertyActionListener
target="#{facRwMappingListBean.facRwMapping.finalActionCdDesc}"
value="#{gridData.finalActionCdDesc}" />
Mine is working fine. Your code looks correct except the value="true" part. Try to pass boolean value in the following way.
value=#{"true"}
Related
We are upgrading from jsf 1.2 to jsf 2.
We are using apache myfaces 2.1 and rich faces 4.3.
Below is the xhtml code :
Prior to Migration :
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:support event="onclick" ajaxSingle="true" actionListener="#{bean.processInput}" reRender="compId">
<f:param name="name" value="paramValue"/>
</a4j:support>
</h:selectBooleanCheckbox>
We are passing one parameter with and accept the parameter in actionListener method as : (String)context.getExternalContext().getRequestParameterMap().get("name1");
After Migration :
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:ajax event="click" listener="#{bean.processInput}" execute="#this" render="compId"/>
</h:selectBooleanCheckbox>
I want to pass a parameter to bean.processInput method which has following signature :
public void processInput(AjaxBehaviorEvent event){
According to this post - Issues in passing parameter in f:ajax , we cannot use <f:param> (its not working
also) and we are not using EL 2.2 which rules out passing parameter in method signature.
Since we cannot use context.getApplication().evaluateExpressionGet due to constraints in our xhtml page only option available is
use <a4j:param name="" value="" assignTo=""/>.
But this needs to have one variable defined in bean requiring code change.
So my question is can we pass a parameter from UI to listener in second case and without changing the code.
You can use f:attribute like this :
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:ajax event="click" listener="#{bean.processInput}" execute="#this" render="compId"/>
<f:attribute name="name" value="paramValue" />
</h:selectBooleanCheckbox>
And use it in your bean :
public void processInput(AjaxBehaviorEvent event)
{
System.out.println(event.getComponent().getAttributes().get("name"));
}
Make sure that f:attribute component is not a child component of a4j:ajax.
it should be immediate child component of h:selectBooleanCheckBox, if not listener wont trigger.
I'm using this primafaces example http://www.primefaces.org/showcase/ui/pprSelect.jsf,
but I'm having problem when I put the first p:selectOneMenu as required true, it isn't clean the second p:selectOneMenu when I choose the first option again.
Regards
What happens here is that when you try to "unselect" the first p:selectOneMenu, you end up triggering a validation rule.
You can do what you want by using two remoteCommand tags and JavaScript.
<p:remoteCommand name="makeSelection" process="select" update="suburbs" />
<p:remoteCommand name="clearSelection" process="#this" update="suburbs" >
<f:setPropertyActionListener value="#{null}" target="#{pprBean.city}" />
</p:remoteCommand>
Now you can decide which one to call using a javascript funcion
<p:selectOneMenu id="city" required="true" value="#{pprBean.city}" onchange="selectFunction(this)">
...
function selectFunction(el){
//if el.value is empty you call clearSelection();
//else you call makeSelection();
}
Another common solution is using a commandButton that clears the selection calling something like:
<p:commandButton update="suburbs" (...)>
<f:setPropertyActionListener target="#{pprBean.city}" value="#{null}" />
</p:commandButton>
I have a datatable which consists of a list of names taken from database. These names are displayed using the commandlink. The code is shown below:
<h:form id="formp">
<p:dataTable id="listpat" var="p" value="#{loginBean.patient}">
<p:column>
<p:commandLink value="#{p.firstname} #{p.lastname}" action="# {loginBean.getPatientID(p.firstname)}" onclick="tabview.select(1);">
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
clicking the commandlink calls a method getPatientID(p.firstname) in the backing bean. I realised the name on the link i click on does not correspond to what is in the backing bean. (e.g. the name clicked on in the commandlink is not the same as the name gotten by passing into the backing bean). What could be the reason? How can i solve it?
public void getPatientID(String fname) {
System.out.println(fname);
}
<p:commandLink value="#{p.firstname} #{p.lastname}" action="#{loginBean.getPatientID(p.firstname)}" onclick="tabview.select(1);">
<f:setPropertyActionListener target="#{loginBean.patient.firstname}" value="#{p.firstname}"
</p:commandLink>
maybe this will work
Here I am again with a JSF problem, this time it is more about richfaces (4.2.1 final, JSF 2). I have an eytended DataTable and want to add new items. There ist the List of Journey-objects, every attribute have getter and setter. The table is created well (there are already some items in the list). And now I click the "add new item" button:
<a4j:commandButton ajax="true" value="Neue Fahrt hinzufügen"
actionListener="'{editorBean.prepareCreateJourney}" render="createJourneyPopupForm"
oncomplete="#{rich:component('createJourneyPopup')}.show()" />
The editorBean is SessionScoped, the method is properply called and create a new object of Journey called currentJourney. A popup comes up and should allow me to insert some input:
<rich:popupPanel id="createJourneyPopup" modal="true">
<h:panelGrid id="createJourneyPopupForm" columns="3">
<h:outputLabel for="currentId" value="ID" />
<h:inputText id="currentId"
value="#{editorBean.currentJourney.journeyNumber}" />
<rich:message for="currentId" />
[...and more...]
</h:panelGrid>
<a4j:commandButton value="Save"
execute="currentId currentTrainType operator">
<f:ajax event="click" listener="#{editorBean.doCreateJourney}"
render=":vmsEditorForm:resultTable" />
<rich:componentControl target="createJourneyPopup" operation="hide" />
</a4j:commandButton>
<a4j:commandButton value="Abbrechen"
onclick="#{rich:component('createJourneyPopup')}.hide();" />
</rich:popupPanel>
When i clicked the button, the method doCreateJourney is called, but the currentJourney is empty. It is the default Journey object after creating it. No setter was called, do a hint on the inputfields.
I checked the names twice, there are getters and setters for alle needed objects. I tried to change the scope, but no effect. Objects are the same, in the prepare method i created Journey(id=151) and in the save method it is still Journey(id=151).
What is going on here? I can't be this difficult to make some dialogs to create and edit data objects. Thank you for listening and for your help!
You need to wrap both your inputs and your commandButtons in a form in order to correctly submit the data.
<rich:popupPanel id="createJourneyPopup" modal="true">
<h:form>
... the content of your popupPanel
</h:form>
</rich:popupPanel>
Regards,
<h:commandLink action="#" value="some value">
<f:setPropertyActionListener target="#{someBean.id}" value="#{var.id}"/>
<rich:componentControl target="popup" operation="show" />
</h:commandLink>
Anybody has idea why this composition wont work. To be precise property action listener
does not do a job, and popup panel was shown. When I do something like this
<h:commandLink action="#{someBean.someAction}" value="some value">
<f:setPropertyActionListener target="#{someBean.id}" value="#{var.id}"/>
</h:commandLink>
property action listener works fine.
Any idea?
It will work fine if you use a4j:CommandButton and use oncomplete attribute of this tag and invoke
oncomplete=" #{rich:component('panelid')}.show();"