This question already has answers here:
Why my jsf <h:inputText> dont set the value in bean class?
(2 answers)
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 4 years ago.
I have no idea why my setters are not invoked while processing form. I see in network browser tool, that POST request is fired with correct (updated) data. But it doesn't affects my binded bean.
<p:commandButton value="Action"
immediate="true"
action="#{beanView.actionForString('5/13/015')}"
oncomplete="PF('some_widget').show()"
update="some_widget_update"/>
<p:dialog id="some_widget_update" widgetVar="some_widget" width="800">
<ui:include src="/view.xhtml" />
</p:dialog>
Template form:
<h:form id="contentForm"
prependId="false"
enctype="multipart/form-data">
<p:messages autoUpdate="true"
globalOnly="true"
showDetail="true"
for="formMessages"
closable="true" />
<div id="starterDiv"
class="ui-fluid">
<ui:insert name="formAsd" />
</div>
</h:form>
And view.xhtml:
<ui:define name="formAsd">
<h:panelGroup rendered="#{beanView.payment!= null}">
<c:set var="payment" value="#{beanView.payment}" />
<div class="ui-g with_background">
<div class="ui-g-2">Payment Id:</div>
<div class="ui-g-2">
<p:inputText value="#{payment.id}"/>
</div>
</div>
<p:commandButton value="Save"
immediate="true"
process="contentForm"
action="#{beanView.save()}" style="width: 150px"/>
</h:panelGroup>
</ui:define>
The bean view looks like that:
#ManagedBean
#ViewScoped
#Data
#FieldDefaults(level = AccessLevel.PRIVATE)
public class BeanView implements Serializable {
Payment payment;
#Setter(onMethod=#__({#Autowired}))
transient PaymentService paymentService;
public void save() {
paymentService.registerPayment(payment); // here It's unchanged!!
}
public void actionForString(String asd) {
payment= paymentService.takeForString(asd)
}
}
Getter works fine, I can see values which service returns in my view.xhtml. Then as I said above, after changing the input value and clicking save button, my debugger shows old value (from intialization in actionFroString) method. Why it is happening?
I believe your problem is immediate="true" on your Command Button. That command immediate="true" tells JSF to skip the validation and binding phase which is why your setters are not being called. This detailed explanation explains why: https://dzone.com/articles/jsf-and-immediate-attribute
Related
InputText field in the following dialog retains previous value even though I set it to blank before calling show(). The inputText field is only displayed blank when show() is called for the first time. My bean is session scoped.
<p:dialog id="dlgId" widgetVar="dlgVar" dynamic="true">
<h:form>
<h:panelGrid columns="1">
<h:outputLabel for="nametext" value="Name" />
<p:inputText id="nametext" value="#{myBean.name}" />
</h:panelGrid>
<p:commandButton value="Save" actionListener="#{myBean.saveAction}" />
</h:form>
public void add(TreeNode selectedTreeNode) {
setName("");
RequestContext.getCurrentInstance().execute("PF('dlgVar').show()");
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
How can I get the inputTEext field to display the value I set before calling show() rather then the value previously entered by the user?
The thing is: you need to update your form. To make it, you can use one of these solutions.
Solution 1 : update it from your xhtml
<h:form id="form">
<h:panelGrid columns="1">
<h:outputLabel for="nametext" value="Name" />
<p:inputText id="nametext" value="#{myBean.name}" />
</h:panelGrid>
<p:commandButton value="Save" actionListener="#{myBean.saveAction}" update=":form" />
</h:form>
Solution 2 : update it from your managedBean
YourXhtml
<h:form id="form">
...
</h:form>
YourManagedBean
public void saveAction() {
...
name = "";
RequestContext.getCurrentInstance().update(":form");
}
You can also read this post Can I update a JSF component from a JSF backing bean method?.
Solution 3 : update it using an Ajax event
You can also add an ajax event
<p:commandButton value="Save" type="button" >
<p:ajax event="click" listener="#{myBean.saveAction}" update=":form"/>
</p:commandButton>
This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 5 years ago.
I have a jsf page where I have this form :
<h:commandButton id="submit" value="Submit">
<h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" ></h:inputText>
<f:ajax event="click" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
<label for="lat">Latitude</label>
<h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>
<label for ="lng">Longitude</label>
<h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>
<f:actionListener binding="#{historicCtrl.insertSearch(2)}"/>
</h:commandButton >
The problem is that the line :
< f:actionListener binding="#{historicCtrl.insertSearch(2)}"/>
Is ignored and I don't know why.
I tried a easier version of the code :
<h:form>
<h:outputText value="Lieu"/>
<h:inputText id="login" value="#{historicCtrl.historic.search}" required="true"></h:inputText>
<br/>
<h:commandButton value="Search">
<h:outputText id ="textToInsertId" value="#{historicCtrl.insertSearch(2)}"/>
</h:commandButton>
</h:form>
This one is working, I can see the trace that the method is supposed to print on the console and I have the insertion in my database.
On the opposite the first code that I wrote in the message isn't working as expected. Indeed, all is working naturally except the f;actionListener as I explain above.
Why is this instruction ingnored ?
Your code is really confusing, but I'll concentrate on the question and provide an example of how your code should propably look like.
If you want to bind an actionListener you have to bind it to an object that implements ActionListener-Interface and not to a method, for example:
facelet
<f:actionListener binding="#{historicCtrl}" />
ActionListener
#ManagedBean
#ViewScoped
public class HistoricCtrl implements Serializable, ActionListener {
private static final long serialVersionUID = 6307961450435094233L;
#Override
public void processAction(ActionEvent e) throws AbortProcessingException {
// TODO implement
}
}
If you use binding you can't pass an argument to your actionListener. The better approach is to use actionListener attribute of h:commandButton. In this case your code should look like this:
<h:form id="form">
<h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" />
<br />
<h:outputLabel for="lat" value="Latitude" />
<h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>
<br />
<h:outputLabel for="lng" value="Longitude" />
<h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>
<br />
<h:commandButton id="submit" value="Submit" actionListener="#{historicCtrl.insertSearch(2)}">
<f:ajax execute="form" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
</h:commandButton>
</h:form>
This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 6 years ago.
I have a form with serveral Dialog, one of them call a function with parameter, but I don't know why is not working. Other dialog are working perfectly. The dialog with parameters:
<p:dialog widgetVar="windowsConfirmOperation" position="center middle" resizable="false"
header="¡Warning!" closable="false" showEffect="fade" hideEffect="fade"
id="idWindowsConfirmOperation" modal="true">
<p:panel>
<div class="DispBlock Responsive100">
<p:outputLabel value="Are you sure?"
escape="false"/>
</div>
</p:panel>
<div class="DispBlock ui-contenedor-botones-accion Fright">
<p:commandButton value="YES"
oncomplete="PF('windowsConfirmOperation').hide();"
update="#form" process="#form"
action="#{queryView.confirmOperation('true')}">
</p:commandButton>
<p:commandButton value="NO"
oncomplete="PF('windowsConfirmOperation').hide();"
update="#form" process="#form"
action="#{queryView.confirmOperation('false')}">
</p:commandButton>
</div>
</p:dialog>
And my view class called QueryView:
#SessionScoped
#ManagedBean
public class QueryView {
....
public void confirmOperation(String confirm) {
if ("true".equals(confirm)) {
doSomeThing();
}
}
}
I debug but the dialog never call the function. I changed parameters of Boolean to String but not working. What am I doing wrong?
Regards.
Finally I modified my logic and now the code works.
<p:dialog widgetVar="windowsConfirmOperation" position="center middle" resizable="false"
header="¡Warning!" closable="false" showEffect="fade" hideEffect="fade"
id="idWindowsConfirmOperation" modal="true">
<p:panel>
<div class="DispBlock Responsive100">
<p:outputLabel value="Are you sure?"
escape="false"/>
</div>
</p:panel>
<div class="DispBlock ui-contenedor-botones-accion Fright">
<p:commandButton value="YES"
oncomplete="PF('windowsConfirmOperation').hide();" process="#this"
action="#{queryView.confirmOperation}">
</p:commandButton>
<p:commandButton value="NO"
onclick="PF('windowsConfirmOperation').hide();"
>
</p:commandButton>
</div>
</p:dialog>
I have changed the param process="#form" for process="#this". I only process the button not all form.
How NO button only close the dialog I changed it. Now only use onclick function.
How only the YES button use the function, now I don't need parameters. So my function changed to:
public void confirmOperation() {
doSomeThing();
}
Edit:
If I pass a Boolean works too.
action="#{queryView.confirmOperation('true'}">
and java file
public void confirmOperation(Boolean something) {
doSomeThing();
}
With these changes my code works fine.
Regards
This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 1 year ago.
I checked a dozen of answers on similar question to this one, but none helped me solve the issue.
Here is the body .xhtml file, where logout button does not work. This page is shown after login, if that is relevant.
<body>
<h:form id="newTaskForm">
<center>
<p:commandButton value="Logout" action="#{LogoutController.logout}"/>
</center>
<p:panel id="panel" header="New task" style="margin-bottom:20px">
<h:panelGrid id="grid" cellpadding="5" columns="3" style="margin-bottom:10px">
<f:facet name="header">
<p:messages id="msgs" />
</f:facet>
form stuff, this is ok
<p:commandButton action="#{createNewTaskController.saveTask}"
value="Spremi zadatak" update="newTaskForm" />
</h:panelGrid>
</p:panel>
</h:form>
and here is a bean:
#SessionScoped
#ManagedBean
public class LogoutController {
public String logout() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(true);
session.invalidate();
return "/createNewTask.xhtml?faces-redirect=true";
}
}
I've seen a list of possible reasons why it could not work, but I can't really tell what an actual reason is, so I'd be grateful for any help
I had the same problem and tried everything but when I gave the CommandButton an id it was resolved
This question already has answers here:
Can I update a JSF component from a JSF backing bean method?
(5 answers)
Closed 7 years ago.
actually I got a inputText and some ajax Request to render a datatable when a keyup event appears.
mypage.xhmtl:
<h:form id="form">
<h:inputText id="number_in" value="#{bean.number}" redisplay="false" >
<f:ajax event="keyup" render=":form:dataTable" />
</h:inputText>
<h:dataTable id="dataTable" ...>
...
</h:dataTable>
<h:form>
I don't want to render the dataTable from the jsf page anymore. I want to render the dataTable in a MangedBean by FacesContext when a listener method is invoked.
mypage.xhtml:
<h:form id="form">
<h:inputText id="number_in" value="#{bean.number}" redisplay="false" >
<f:ajax event="keyup" listener="#{bean.onKeyup}" />
</h:inputText>
<h:dataTable id="dataTable" ...>
...
</h:dataTable>
mybean.java:
#ManagedBean(name="bean")
#SessionScoped
public class Bean {
...
public void onKeyUp(AjaxBehaviorEvent event) {
//Here I want to render the dataTable
}
...
}
How can I achieve that?
You can programmatically add render IDs to PartialViewContext#getRenderIds().
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("form:dataTable");
Note that this can contain only absolute client IDs and should not be prefixed with :.
FacesContext.getCurrentInstance().getPartialViewContext().setRenderAll(true);