I have two commandButtons and when I hit enter the first one submits. I really only want to submit the second button if the user hits enter. Any ideas?
I realize that the question is old, but maybe it is still interessing for someone to see a different solution.
You can use the Primefaces defaultCommand and adding an id to your prefered Button to define what happens when the Enter key is pressed. That's all.
<p:commandButton value="button1" action="#{bean.action1}"/>
<p:commandButton value="button2" id="btn_to_enter" action="#{bean.action2}"/>
<p:defaultCommand target="btn_to_enter" />
You have to swap the position of those two buttons thats all.
Your current code should be.
<p:commandButton value="button1" action="#{bean.action1}"/>
<p:commandButton value="button2" action="#{bean.action2}"/>
By default the button1 action will be triggered. You can present the user an alternative view, by adding style="float:right" to the button1.
<p:commandButton value="button1" style="float: right" action="#{bean.action2}"/>
<p:commandButton value="button2" action="#{bean.action1}"/>
Using the above the button1 will appear after the button2, and perform the action of button2, whenever the Enter is pressed.
Related
I got a <h:commandbutton> like
<h:commandButton value="Neuer Abschnitt"
styleClass="btn btn-primary btn-info"
action="#{beitragBearbeitenBean.erstelleAbschnitt}" />
Well, I click onto the button, the method is called and after that, the page is jumping to the top (provied you are not at the top!)
Interestingly, a
<f:ajax execute="#form" />
does offer a little jump up.
How can I avoid a jump, generally?
an <h:commandButton> doess a full post of the page, no ajax stuff. So it is normal to jump back to the top of the same page (assuming your action returns null or is void). The <f:ajax> makes it refresh the form and most likely jumps to the top of the form (if the button you use is also in that form). Updating parts of the form (e.g. a panel inside the form) and not update the button since it can stay ourtside the panel most likely will cause that you stay at the same spot. But if the size of the panel changes, it might not (but then you can e.g. make your pannel scrollable so the button will not move).
I have a form using JSF with rich faces. In the form there are two radio buttons: "Yes" and "No". The default selection is "Yes". When clicked "No" a text area should appear below. But it doesn't. Instead It appears in the second click; I first click "No" (Default was "Yes") nothing happens and then I click "Yes", now it works, the text area below appears but it automatically chooses "No".
Here is the code:
<h:outputLabel for="cheapest">Cheapest Flight?</h:outputLabel>
<h:selectOneRadio id="cheapest" value="#{myController.selectedItem.cheapest}" disabled="#{myController.showMode}">
<f:selectItems value="#{yesNoTypeItems.items}" />
<a4j:ajax event="change" render="#form" execute="#form" />
</h:selectOneRadio>
<h:outputLabel for="newArea" rendered="#{myController.selectedItem.cheapest == false}">New Text Area</h:outputLabel>
<h:inputTextarea id="newArea" rendered="#{myController.selectedItem.cheapest == false}" disabled="#{myController.showMode}"
value="#{myController.selectedItem.newArea}" style="width:300px;height:100px;">
</h:inputTextarea>
onchange - Javascript code executed when this element loses focus and its value has been modified since gaining focus. (docs)
Perhaps unfortunately named the change event doesn't fire when you expect it to. Use the click event and check if the value is actually being changed if you need to.
In my application I placed a <p:panel> in a <h:form>. Now in this panel I have some <p:inputText> and at the end of panel I have two button one is Submit another is
Reset. Reset button works properly if it is pressed before submit the form. But if Once I submit the form and some text fields fails to validate
then that fields are containing the previous entered data. Now if I press Reset button to clear all the fields then it is not working.
My Reset button's code :
<p:commandButton value="#{Bundle['resetButton']}" process="#this" update="addCustomerPanel" immediate="true" />
The form is like :
<h:form id="customerForm">
<p:panel id="addCustomerPanel">
.......text fields and two buttons placed here
</p:panel>
<h:form>
Update
I have solved this problem by navigate to the same page on reset button click.
I am trying to print multiple tabs but want to exclude some.
I tried the following:
<p:printer target="tabs:tab0,tabs:tab2" />
and
<p:printer target="tabs:tab0" />
<p:printer target="tabs:tab2" />
Neither worked.
I played somewhat around it and it works only for a specific tab if the tab is visible. You can thus definitely not specify multiple tabs. You might want to post an issue report about that to PrimeFaces, although solving that would be relatively hard.
As of now, to get it to work for a specific tab, you'd need to toggle the desired tab visible in the button's onclick handler before print action is performed. You can use the select() function of the <p:tabView> widget for this wherein you pass the zero-based tab index.
Here's a kickoff example.
<h:form id="form">
<p:tabView id="tabs" widgetVar="tabs">
<p:tab id="tab1" title="tab1">tab1</p:tab>
<p:tab id="tab2" title="tab2">tab2</p:tab>
<p:tab id="tab3" title="tab3">tab3</p:tab>
</p:tabView>
<p:commandButton type="button" icon="ui-icon-print" value="Print tab2" onclick="tabs.select(1)">
<p:printer target="tabs:tab2" />
</p:commandButton>
</h:form>
There are a <p:inputText> and a <p:commandButton>. I want to click the button to open a dialog with a table. When I select one row and press OK, I would like set the value of the selected row in the <p:inputText>.
In the dialog, I use an <iframe> and call a JS function to set the src of <iframe> and show the dialog. But I have no idea to update the <p:inputText> from an <iframe>.
Main page:
<h:form id="dialogForm">
<p:inputText id="tarText" value="" />
<p:commandButton value="master file" oncomplete="showDialog('#{request.contextPath}')" />
<p:dialog widgetVar="lookupDialog" header="Lookup">
<iframe id="myiframe"></iframe>
</h:form>
JS:
function showDialog(contextPath) {
var myiframe = document.getElementById("myiframe");
myiframe.src = contextPath + "/pages/lookup.xhtml";
lookupDialog.show();
}
Edit----
#BalusC but how can I refresh a special area of this page by pressing a button? The more important thing is, the different button pressed, the different content shown out. And I don't wanna refresh the page sync.