I have a jsf page where I have a selectOneMenu and , I want to open a dialog box on selectOneMenu changes.
As a example if user selects a value ="passive" from jsf selectOneMenu it
should open a dialog box or a light box on same page where I want to
display a small jsf form like as here done.(please click on that small image(yes, like this dialog box I want to open after selecting particular
value in selectOneMenu)
)
http://www.primefaces.org/showcase-labs/ui/dialogLogin.jsf
and I also want save that submitted data in my backing bean somewhere so I can store it in to database later.
I dont know how to open a dialog box or light box from backing bean in same window,as we will identify value change using valueChangeListener event or by using ajax event.
I am able to identify which value is selected from selectOneMenu(DropdownMenu), but dont know how to open a dialog box on selecting particular value.
<h:outputLabel
value="* Country: "/>
<h:selectOneMenu
id="someSelect"
value="#{testController.countryName}"
required="true">
<f:selectItem
itemLabel="Select Country"
itemValue=""/>
<f:selectItems
value="#{testController.countryNamesSelectItems}"/>
</h:selectOneMenu>
Supoose we have 2 options in selectItems as India and Austrlia, then If a user choose India
a dialog box should open on same page where a user need to fill some information and need to submit
if he is from india (like here in example http://www.primefaces.org/showcase-labs/ui/dialogLogin.jsf (please click on that small image(yes, like this dialog box I want to open after selecting particular
value in selectOneMenu)
)user will put his username and password and submits data)
Hope this helps
how can we check in primefaces , selected value of selectOneMenu using
java script(jquery) like done here for richfaces
t:selectOneMenu how to get selected value using java script??
You could use the onchange attribute of h:selectOneMenu to open the dialog:
<h:selectOneMenu
id="someSelect"
value="#{testController.countryName}"
required="true"
onchange="dlg.show()">
With dlg as value of the widgetVar attribute of the p:dialog. This will open the dialog before the server is hit.
If you want to open the dialog after completion of an ajax request you can use p:ajax with the oncomplete attribute:
<p:ajax update=".." process=".." oncomplete="dlg.show()"/>
Or if you want to make opening the dialog dependent on the selected value you could use a wrapper function:
function showDialog() {
if($('#IdOfYourSelectOneMenu').val() == 'India') {
dlg.show();
}
}
with:
<p:ajax update=".." process=".." oncomplete="showDialog()"/>
Related
I have created specific code that allow a user to load a dialog to specify some search criterias.
The code that call the dialog is
<i class="fa fa-fw fa-dot-circle-o"
onclick="PF('LoadLabelHomoVectoDialog').show();"
/>
<p:inputText
id="CertificationCodeId"
value="#{vC.postLabellingSearchCriteria.certificationCode}"
readonly="true"
/>
The user click on icon and dialogbox is displayed.
The user make some action in dialog, click on OK button and CertificationCodeId inputText widget is filled directly using Javascript. I can see specific value in it.
Then on main page (not more in dialog), I click on SEARCH button to start a new search using criteria value found in CertificationCodeId inputText widget.
If readonly attribute equal "false", the widget value is correctly transmitted to ViewController on server.
If readonly attribute equal "true", the widget value is NOT transmitted to ViewController on server.
I thought that readonly attribute is only to prohibit user input, but not to prohibit value to be transmitted to server.
What do I wrong ?
Is that a Primefaces issue ?
There exists a answer to my problem to Validate readonly components anyway on form submit that is disctinct from what is proposed !!! What is proposed is a duplicate of the link I propose :-)
JSF and PrimeFaces do not process values when inputs are disabled or readOnly for security purposes. So even a hacker enables the input and submits the form, JSF-PrimeFaces checks the component. So it is standard behavior. You need to enable it on server side.
Found here: https://forum.primefaces.org/viewtopic.php?t=15632
Because I will that visible inputText is READ-ONLY, the only solution is to duplicate READ-ONLY inputText like this ...
<i class="fa fa-fw fa-dot-circle-o"
onclick="PF('LoadLabelHomoVectoDialog').show();"
/>
<p:inputText
id="CertificationCodeId"
value="#{vC.postLabellingSearchCriteria.certificationCode}"
readonly="true"
/>
<p:inputText
id="CertificationCodeIdBecauseJSFdontSentReadOnlyWidgetValueToServer"
value="#{vC.postLabellingSearchCriteria.certificationCode}"
style="display:none"
/>
The value of second widget is sent to server because it is not disabled or read-only.
In Javascript code, I must assign the two widget.
JSF and PrimeFaces do not process values when inputs are disabled or
readOnly for security purposes. So even a hacker enables the input and
submits the form, JSF-PrimeFaces checks the component.
I think now, that issue that JSF/Primefaces want to avoid, is always there because an hacker can change content of the hidden widget.
The only thing I see is that the code is more complex and less readable :-)
Why to do simple when it is possible to do complex ?
Trying to submit an HTML form / clicking a button from this web page: https://www.vegvesen.no/kjoretoy/Eie+og+vedlikeholde/skilt/personlig-bilskilt/sok-om-personlig-bilskilt
I've tried to use both .submit() and .click() with no success
webView.evaluateJavaScript("document.getElementById('personlig-kjennemerke').click();", completionHandler: nil)
So what I try to do is to fill in the text field with "REGNR" I then try to click the orange button to submit the form and access the information I am looking for.
I am able to fill in the textfield by using:
webView.evaluateJavaScript("document.getElementById('tegnkombinasjon').val ue='\(plateNumber)'") { (value, error) in
}
Picture of the button I want to press and the text field I try to fill in
But since I'm not able to click the button programmatically I've tried to actually click it in a subview. The page then tells me I have to fill in the text field first even though I have programmatically.
So not only am I unable to click the button, but I'm also wondering how I can make the web page understand that the text field actually already contains text.
Try this:
webView.evaluateJavaScript("document.getElementsByName(\"sjekkreg\")[0].elements[2].click()")
Why by name? Because that form doesn't have an id.
Also I see your form has custom function to send that form:
pkCtrl.submit(mineFelt,sjekkreg)
Use case: I have a value in the edit form which is very important and should not be changed very often. I have decided to have it read only and have button "Change" on the side. After clicking on this button dialog with warning is dispalyed to the user and this readonly field is enabled for changing. (it is a selectOneMenu)
First attempt:
<p:selectOneMenu
id="integrationCombo"
value="#{backendBean.integration.backend}"
widgetVar="backendIntegrationCombo"
disabled="true">
<f:selectItems
value="#{backendBean.backends}"
var="backend" itemValue="#{backend}"
itemLabel="#{backend.name}" />
</p:selectOneMenu>
<p:commandButton type="button"
styleClass="inlineTableCellButton"
onclick="backendIntegrationCombo.enable()"
value="#{msg['button.change']}" />
This enables the combo box, but his value is not send to the server (this is due to disabled=true as i found)
My second attempt was to have editable boolean on the view scoped bean and
disable="#{!bean.editable}" and calling setEditable(true) with command button. This worked well, but for unknown reason now the save action on command button that submits the form stopped working.
Third attempt: render h:outputText with name and combobox (with hidden class) and after change button is clicked switch their hidden classes.
function changeBackend() {
$("#backendName").addClass("hidden");
$("#integrationCombo_input").parent().parent().removeClass("hidden");
}
That works fine too except one thing: after save is done - nothing is rendered (neither ouputText nor combo box)
in one page I have a datatable that contains all users, each line contains two additional columns "edit" and "delete", the problem is on the botton delete
when the user click on "delete" button I show him a confirmation dialog with component primefaces and if he clickon "ok" I run a method that delete user from database
but the problem is in the button :
<p:column>
<p:commandButton actionListener="#{utilisateursController.supprimerUser()}" value="Supprimer" onclick="confirmation.show()" type="button" >
<f:setPropertyActionListener id="jesusi" value="#{car}" target="#{utilisateursController.u1}" />
</p:commandButton>
</p:column>
to delete the user it must be affected to utilisateursController.u1
but when I click in this button the code below
<f:setPropertyActionListener id="jesusi" value="#{car}" target="#{utilisateursController.u1}" />
doesn't be executed
then, the utilisateursController.u1 remains null
do you have any idea
thank you in advance
it doesn't execute because you added type="button". Remove that part. Also, you should be opening the dialog with oncomplete instead of onclick, so that by the time the dialog is opened, the selected row is already in utilisateursController.u1. That way you can include attributes (like name) in the confirmation dialog (you'll have to update dialog from button if you want to do this).
i have a jsp page on which i have a image, on click of that image i am opening a modal winwdow having radio buttons with corresponding value(another jsp)...
what i am trying to achieve is on selection of a radio button,assign it's value to a textbox which is on parent page...
Let me tell you that i am not submitting any form ...i just want to close this window and assign it's value to textbox on parent jsp, on selection of radio button
i tried to do it with session but couldn't figure out exact way...
any suggestions or inputs will be highly appriciated.
Thanks
Assume that in the parent window this is the text box that needs to be updated.
<input type="text" id="txtBoxDisplay" value=""/>
In parent window create a function to update the textbod with the new text
<script>
....
....
....
function updateTextBox(theTextString)
{
$("#txtBoxDisplay").val(theTextString); //assuming you are using jquery
document.getElementById('txtBoxDisplay').value = theTextString; // if not using jquery
}
</script>
In the child page/modal window use the following code to access the parent jsp function
window.opener.updateTextBox("Display this text in the parent text box");
You can also use
parent.updateTextBox("Display this text in the parent text box");
For more details see the following links
http://chiragrdarji.wordpress.com/2007/03/10/call-parent-windows-javascript-function-from-child-window-or-passing-data-from-child-window-to-parent-window-in-javascript/
http://www.rgagnon.com/jsdetails/js-0066.html
If you're not submitting any form, then the server obviously doesn't know anything about the selection you made in the modal window.
Use JavaScript to initialize the text field in the parent window with the selected radio. Since I gues you're using JQuery to open the dialog, then you shouldn't have any problem calling a JavaScript function defined in the parent window from the modal dialog.