commandLink in dataTable not invoked [duplicate] - jsf

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 7 years ago.
I have problems with invoking commandLink action in dataTable.
<h:body>
<h:dataTable value="#{manageStaffAccountBean.accounts}" var="staff">
<h:column>
#{staff.surname}
</h:column>
<h:column>
<h:form>
<h:commandButton value="Change status"
action="#{manageStaffAccountBean.changeActivity(staff)}" />
</h:form>
</h:column>
</h:dataTable>
</h:body>
By click on "Change status" i need to invoke changeActivity() method in bean
Managed Bean code:
#Named
#Scope("request")
public class ManageStaffAccountBean implements Serializable {
private List<Staff> accounts = null;
public String changeActivity(Staff staff){
System.out.println(staff.getId());
return "manageStaffAccounts";
}
public void updateAccountsList(){
accounts = staffService.findAll();
}
// ...
}
However, it is not invoked. Can you help me to find the problem?

I found the solution. If we use h:commandButton inside h:dataTable, our manage bean should have scope "session", or button wouldn't work. Just JSF magic

Related

JSF <h:selectOneMenu> doesn't save my choose [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?
(2 answers)
Closed 2 years ago.
I'm working with JSF and want to save a choose from a dropdown, but it doesn't save it, what can I do?
xhtml:
<h:form>
<h:selectOneMenu value="#{spielController.ausgewaehlteKategorie}" >
<f:selectItems value="#{spielController.alleKategorien}"/>
</h:selectOneMenu>
</h:form>
<br/>
<h:form>
<h:commandButton action="#{spielController.ladeFrage()}" value="Spielen"/>
</h:form>
BackingBean:
#Named(value = "spielController")
#SessionScoped
public class SpielController implements Serializable {
private String ausgewaehlteKategorie;
private ArrayList<String> alleKategorien = new ArrayList<>();
public SpielController() throws SQLException {
for (String kategorie : kdao.getKategorien()) {
alleKategorien.add(kategorie);
}
}
public String getAusgewaehlteKategorie() {
return ausgewaehlteKategorie;
}
public void setAusgewaehlteKategorie(String ausgewaehlteKategorie) {
this.ausgewaehlteKategorie = ausgewaehlteKategorie;
}
public ArrayList<String> getAlleKategorien() {
return alleKategorien;
}
public void setAlleKategorien(ArrayList<String> alleKategorien) {
this.alleKategorien = alleKategorien;
}
}
I get the things from a DAO-class and it works, but when I press the button, it doesn't work because the choose I made above wasn't saved
Move
<h:commandButton action="#{spielController.ladeFrage()}" value="Spielen"/>
to h:form
<h:form>
<h:selectOneMenu value="#{spielController.ausgewaehlteKategorie}" >
<f:selectItems value="#{spielController.alleKategorien}"/>
</h:selectOneMenu>
<br/>
<h:commandButton action="#{spielController.ladeFrage()}" value="Spielen"/>
</h:form>
This is the reason why your setter not invoked.

How can set value with selectBooleanCheckbox and Delete? [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?
(2 answers)
Closed 3 years ago.
I am doing a mini jsf project that is created by using jpa. I have listed costumers and I can remove them one by one, but if I want to remove selected costumers I cannot do it.
This part is from Costumer class
#Transient
private Boolean selection = false;
And this part is from CostumerBean
Costumer costumer = new Costumer();
private List<Costumer> costumerList = new ArrayList<>();
//(getters and setters)
public void removeSelected() {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
for (Costumer cos : costumerList) {
if (cos.getSelection()) {
em.remove(em.contains(costumer) ? customer : em.merge(costumer));
}
}
em.getTransaction().commit();
musteri = new Musteri();
}
And finally here is the xhtml page :
<h:form id="firstForm">
<p:commandButton action="#{customerBean.removeSelection}" value="Remove"
update="customerForm">
</p:commandButton>
</h:form id="firstForm">
<h:form id="customerForm">
<p:dataTable value="#{customerBean.customerList}" var="cst"
id="cstTable">
<p:column>
<f:facet name="header">Select</f:facet>
<p:selectBooleanCheckbox value="#{cst.selection}" />
</p:column>
<p:column>
<f:facet name="header">Name</f:facet>
#{cst.name}
</p:column>
</h:form id="customerForm">
I reckon actual problem is I cannot make selection field in Costumer.java true. No action I see.?

JSF setters not get invoked [duplicate]

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

A p:commandLink inside a p:dataTable does not work [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 7 years ago.
I am using PrimeFaces 5.2 and at a place in my web app. I am displaying a data table is which corresponding to each row. I am giving an edit link (<p:commandLink>) to edit the the fields of corresponding entity on next page but the link is not working at all. Here is the XHTML content.
<p:dataTable id="tickets" var="ticket"
value="#{ticketController.ticketModels}" paginator="true" rows="10"
filteredValue="#{ticketController.filteredTickets}">
<p:column headerText="Ticket Id" sortBy="#{ticket.ticketId}">
<p:commandLink action="viewDetailedTicket">
<h:outputText value=" #{ticket.ticketId}"></h:outputText>
</p:commandLink>
</p:column>
<p:column headerText="Summary" filterBy="#{ticket.summary}"
filterMatchMode="contains" sortBy="#{ticket.summary}">
<h:outputText value="#{ticket.summary}" />
</p:column>
<p:column headerText="Priority">
<h:outputText value="#{ticket.priority}" />
</p:column>
.
...............................
</p:dataTable>
The following is my backing bean:
#ManagedBean
public class TicketController {
#ManagedProperty(value = "#{ticketpojo}")
private Ticket ticket;
private TicketDao tDao;
private TicketModel ticketModel;
public TicketModel getTicketModel() {
return ticketModel;
}
public void setTicketModel(TicketModel ticketModel) {
this.ticketModel = ticketModel;
}
public TicketController() {
tDao = new TicketDao();
}
public String viewDetailedTicket() {
ticketModel = tDao.getTicket(ticketId);
return "viewDetailedTicket";
}
}
When I hover, over the link , the tooltip at the bottom of the browser shows http://localhost:8080/JSF_1/view/viewTicket.xhtml# , a '#' is appended to the end of the current page URL. When clicked it remains on the same page.
I have tried putting the link outside the data-table that also didn't work .
A commandLink or any action that you'd like to do with JSF/primefaces must be inside a form. Otherwise no HTTP Post can be performed. I suggest to use one form for the whole datatable. Otherwise there will be a lot of forms for the multiple rows.

Partial rendering via FacesContext [duplicate]

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);

Resources