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.
Related
I have written a button onClick to open popup window. The window has a table with a commandLink in each row. How to populate the parent page textbox on click of commandLink in child page?
You can give the commandLink an ajax tag, with whom you render your parent textbox.
Use something like this:
<h:inputText id="parentTextboxId" value="#{bean.text}" />
<rich:popupPanel domElementAttachment="form" show="#{bean.showPopup}" modal="true">
<h:commandLink value="My Link">
<f:ajax render=":mainForm:parentTextboxId" listener="#{bean.changeText}" />
</h:commandLink>
</rich:popupPanel>
In the bean method bean#changeText the value of the textbox will be changed, but you can also do it elsewhere, like in the action method of your commandLink
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 using Richfaces 4. I have a <rich:datatable /> with 4 columns. In that, first column is a <a4j:commandlink /> . I need to change the background color of the entire row when I click on the link. On click of the link I am calling action listener, and oncomplete I am rerendering the page. How do I change the color of the clicked row ?
Add on your link the onclick method :
<rich:column>
<a4j:commandlink onclick="changeBackground(this)" ...
</rich:column>
The Script (Using jQuery) to find the tr of the cell and apply style :
<script>
function changeBackground(element){
jQuery(element).parents('tr:first').addClass('backgroundRed');
}
</script>
and the css for example
.backgroundRed {
color: #555658;
background-color: red;
}
You can check this conversation to further information.
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.