<h:inputText> does not update [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 9 months ago.
I have a page with a form and an input text, that represents the value of a bean. On the bottom of the page, I have a navigation button to go to the next entry:
<h:form id="customerData">
...
<h:outputText value="#{customeredit.customer.name}" />
<br />
<h:inputText size="60" id="name" value="#{customeredit.customer.name}" />
...
</h:form>
<p:commandButton value="Next customer" action="customers" ajax="false" id="nextCustomer">
<f:param name="linkageAreaId" value="#{customeredit.nextCustomer.id}" />
</p:commandButton>
If I click on the button, the page reloads, a new customer object is loaded in the background and all the entries are updated EXCEPT the inputText. The outputText changes, but the inputText always keeps the value it has gotten when it was intialized. I also checked with the getters, the values return from the getters change with new customers, but the value displayed in the inputText always stays the same.

That can happen if you're nesting forms (which is illegal in HTML) and thus both the input and button ultimately end up in the same form. That button would then submit the input field as well. In any case, you should not be using <p:commandButton> for page-to-page navigation. Use <p:button> instead.
<p:button value="Next customer" outcome="customers" id="nextCustomer">
<f:param name="linkageAreaId" value="#{customeredit.nextCustomer.id}" />
</p:button>
Don't forget to fix the nested form problem as well.
See also:
How to navigate in JSF? How to make URL reflect current page (and not previous one)
Difference between h:button and h:commandButton

Related

Primefaces commandLink works but not commandButton [duplicate]

This question already has answers here:
Differences between action and actionListener
(4 answers)
Closed 6 years ago.
I have identical actions for commandLink and commandButton. However, commandLink works as expected. But with commandButton no action occurs. Am I missing syntax?
<p:commandLink value="Submit" action="#{beanController.getStr(strSearch)}" ajax="false"/>
<p:commandButton value="Submit" actionListener="#{beanController.getStr(strSearch)}" ajax="false"/>
If you intend for navigation to occur you should use action not actionListener in your commandButton, so:
<p:commandButton value="Submit" action="#{beanController.getStr(strSearch)}" ajax="false"/>
commandButton button generates a HTML <input type="submit"> element and the commandLink generates a HTML <a> and comandButton is using to submit the form whereas commandlink is used to submit a link,so your form is not submitting i'll suggest you to check if there is any nested form is present or not or if there is multiple forms in your code or any other issue which is causing in form submit, if you can then post your code.

The rerendered attribute not working on a4j:commandButton [duplicate]

This question already has an answer here:
Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?
(1 answer)
Closed 7 years ago.
I'm using JSF 1.2 and RichFaces in my project. I'm trying to implement a scenario which is as follows, I have two rich:panel in my page and their rendered attribute is set to a boolean variable in a bean and the default values of the variable is set to false, so the first time the page is loaded the panels do not get rendered. I have a a4j:commandButton in my page and on the action attribute of the button I am calling a method in my bean which sets the two flag variable but the panels are not getting rendered even after the variables are set, and I am also setting the rerendered attribute of the button, I don't think I am missing any steps.
If component is not rendred when page is loaded then it will not make any change even when you will change the value of boolean variable to true on some commanad button click as well. Your component should be in view to rendered on Button click . So put your component inside another component Please chek below code
Following will not work when #{bean.renderResult} defaults to false:
<h:form id="form">
<h:commandButton value="Submit" action="#{bean.toggleRenderResult}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:outputText id="result" value="#{bean.result}" rendered="#{bean.renderResult}" />
You need to ensure that the render ID points to a component which is already present in the JSF-generated HTML output.
Following will work:
<h:form id="form">
<h:commandButton value="Submit" action="#{bean.toggleRenderResult}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:panelGroup id="result">
<h:outputText value="#{bean.result}" rendered="#{bean.renderResult}" />
</h:panelGroup>
For more information check http://balusc.blogspot.in/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichIsByItselfConditionallyRendered

<h:outputText> rendered the old value even after ajax update [duplicate]

This question already has an answer here:
Ajax update/render does not work on a component which has rendered attribute
(1 answer)
Closed 8 years ago.
In below code, I click the Submit button. That change boolean result value to true in backing_home bean via a ajax call.
If I remove the rendered rendered="#{backing_home.result}", I see the updated output properly.
But with the below code it is false. I think it doesn't render the new value
<h:commandButton id="MySubmit" value="Submit" action="#{backing_home.toggleRenderResult}">
<f:ajax render=":AjaxGuess:result2"/>
</h:commandButton>
<h:outputText id="result2" value="#{backing_home.result}" rendered="#{backing_home.result}" />
What could be the reason?
I update the code as below based on Hatem Alimam's comment.
<h:commandButton id="MySubmit" value="Submit" action="#{backing_home.toggleRenderResult}">
<f:ajax render=":AjaxGuess:result2"/>
</h:commandButton>
<h:panelGroup id="result2">
<h:outputText value="#{backing_home.result}" rendered="#{backing_home.result}" />
</h:panelGroup>

a4j:commandButton's action is never triggered when it's inside a rich:panel with rendered tag [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 8 years ago.
Here is the simplified version of my xhtml code, I can't figure out why my save1 commandButton doesn't work while save2 works:
<rich:panel id="table_panel">
<h:form>
<rich:panel rendered="#{bean.showPanel}">
<a4j:commandButton id="save1" value="Save"
action="#{bean.executeAction()}">
</rich:panel>
<rich:panel>
<a4j:commandButton id="save2" value="Save2"
action="#{bean.executeAction()}">
</rich:panel>
</h:form>
</rich:panel>
When click a button, it will update showPanel value to true in backend and re-render *table_panel*,
then commandButton save1 will show up, but even if it show up, the action executeAction()
will never be invoked after click (never enter into my breakpoint in the method). However, the commandbutton save2 can always act normally.
The only difference for those two buttons is their wrapper rich:panel, one is always there while
another is displayed after some UI action as it has rendered="#{bean.showPanel}" attribute. I didn't see any javascript errors on firebug.
I would appreciate any ideas, thanks in advance!
Try putting execute="#this" explicitly in the commandButton.
Have you tried immediate="true", it might narrow down the issue in my opinion:
<a4j:commandButton id="save1" value="Save" immediate="true"
action="#{bean.executeAction()}">

JSF Delete entity on DataTable with p:dialog [duplicate]

This question already has answers here:
p:commandbutton action doesn't work inside p:dialog
(4 answers)
Closed 6 years ago.
I'm currently working on a CRUD form and is now working on the last part which should be the most easiest - delete. But I want to show a dialog before the user can do the actual deletion. And this is where I'm having problem with Primefaces 3.4. For some reason I cannot set the action in the button inside the p:dialog, ajax=false failed. So here's what I did:
<p:column headerText="#{msgs['action.delete']}"
styleClass="a-center">
<p:commandButton icon="ui-icon-trash"
oncomplete="confirmation.show()">
<f:setPropertyActionListener
target="#{marketingCodeBean.marketingCode}" value="#{code}"></f:setPropertyActionListener>
</p:commandButton>
</p:column>
The Dialog:
<p:confirmDialog id="confirmDialog"
message="#{msgs['message.marketingCode.confirmDelete']}"
header="#{msgs['common.confirmDelete']}" severity="alert"
widgetVar="confirmation">
<p:commandButton id="confirm" value="#{msgs['common.yes']}"
oncomplete="confirmation.hide()" update=":form:mktgCodeTable"
actionListener="#{marketingCodeBean.remove}" />
<p:commandButton id="decline" value="#{msgs['common.no']}"
onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
I'm aware that the actionListener should not be use for business action, but I can't think of a workaround given the datatable and the dialog. Any idea on how I can make ajax=false in p:commandButton inside p:confirmDialog?
Once rendered, the dialog's HTML output is by some onload JavaScript relocated to end of HTML <body> in order to achieve the best cross-browser compatible overlay/positioning. However, this thus means that if it was placed inside a <form>, it would not be in a <form> anymore and synchronous (non-ajax) requests would then not work anymore. This is not exactly an action vs actionListener issue.
The <p:dialog> (and <p:confirmDialog> as you seem to be actually using) should have its own <h:form> component.
<h:form>
<p:dataTable>
...
</p:dataTable>
</h:form>
...
<p:confirmDialog>
<h:form>
...
</h:form>
</p:confirmDialog>

Resources