Grails datepicker looses setting - grails

I've noticed that datepicker is reset to default value after the request has been done and the page reloaded.
Although I ensured that parameters are saved for use in pagination
...
<g:paginate total="${totalCount}" id="${params.id}"
params="[
startDate : params.startDate,
startDate_year : params.startDate_year,
startDate_month: params.startDate_month,
startDate_day : params.startDate_day]
/>
...
and it works as expected, the UI component itself shows default value. I'm afraid that it may irritate users. What should be done to make datepicker display the last value set by user and not the default one?

Your <g:paginate> tag is using the params appropriately, but your <g:datePicker> tag likely does not use a value attribute set to whatever was submitted.

Related

Grails : Using select tag of grails with disabled property set to true ignores the value

I need to disable a select element in grails depending on its value. The problem is when I started to add the disable property something is quite wrong with the code.
An example is when the form is sent to the backend, its as if there is no value for that select element and the value sent is null. But, when I checked the DOM, there is a selected attribute in the element. I tried to remove that disabled property because I have a feeling that it has something to do with the bug that I'm encountering and I was right because after removing it, everything worked correctly again.
this is the select tag
<g:select name="detail-entryNameId"
value="${journalEntryName.savingId}"
from="${journalEntryNameInstanceList}"
optionKey="savingId"
optionValue="displayName"
readonly="${journalEntryInstance.paymentMade}"
/>
One more thing about this element is that it can occur as many as possible, which means I have a table and in every row, that element exist so I cannot simply manipulate it.
I've also read in this post how can i make a textfield read only in grails? that "If you use disabled="true" the value will not actually be submitted in the form, so the <g:field/> tag should be used." which proves that disable attribute affects the value of the element.
How can I disable the select element and at the same time, still get its value correctly?
The problem is that in HTML the mere existence of the disabled attribute disables the tag. The value of the attribute (true/false) is ignored.
In such cases the solution is to use an <g:if> to create the tag with or without the disabled attribute according to a condition.
In your case, since you want the value even when the tag is disabled you can add a <g:hiddenField> with the same name and value as the disabled select.

How to get the values true or false depending on a list of checkbox checked or not in Grails

I have check boxes in a list
HTML Code
<g:checkBox id="isBookable_${index}" class=" isBookable" style = "width :auto" name='isBookable' value='${careProviderScheduleExceptionInstance?.isBookable}' />
Problem
When I get the list of this checkbox i.e isBookable in params, the values for only the checkboxes that are checked comes in the list and the value comes as on and not true.
I want the values should come as true or false based on if the checkbox is checked or not.
Thanks in advance.
Grails g:checkbox does some shenanigans for the binding magic to work correctly when you do something like:
def schedule = new Schedule(params)
So that schedule.bookable would get populated correctly. I've never been a big fan of how it works but it is what it is and at the end of the day, it does work for typical use cases.
You have to remember that per the HTML spec, you're not going to get unchecked checkboxes passed in on a form submit. So looking for false is a moot point. What you would have to do is take the ones that do get checked (and submitted) and compare that against a list of possible bookable 'schedules'.
A work around would be to use Javascript to submit your form and pass in all the checkbox's with whatever value you want mapped to the correct instance.

ASP.Net MVC Getting hidden field value in javasccript

I have asked this same basic question before several times without a response, but let me try one more time, breaking it down as simple as possible.
I have a strongly-typed view with a hidden field on it.
When the view renders server-side, I am setting the value of the hidden field to a property of the model.
When the view renders client-side, I want to get the value of the hidden field (that was set during the server-side render) and display it in a java script alert box.
This should be a simple thing to do and yet I am unable to make it work. I have set a break-point in the view and I can see that the hidden field is being set to the correct value. But the javascript will not display that value.
The page/view being rendering has been gone to before. At the time I want to display this alert, I am going back to that page and now I want to see the alert.
It is as if the page is being cached, so instead of using the new value for the hidden field it is using the old value (from the first time the page was visited). If the DOM is being cached, how I can prevent that so that each time I visit the page I get the updated values of the page and not the cached ones? What am I doing wrong??
#<input type="hidden" id="hdnShowMsg" value="#Model.ShowMsg" />
<script>
alert($('#hdnShowMsg').val());
</script>
Your script may be firing before your document is fully rendered. Use the jQuery document ready function.
http://api.jquery.com/ready/
<script>
$(function() {
alert($('#hdnShowMsg').val());
});
</script>
Also note that document ready is not supported within a jQuery Mobile document and you may run into problems depending on what part of the DOM you are trying to manipulate.
Use $(document).bind("pageinit", function() {}) instead.
http://jquerymobile.com/demos/1.2.1/docs/api/events.html

How to set focus of ICEFaces component after initial rendering?

I have a complex ICEFaces XHTML page that renders certain components conditionally, based on flags set as the user enters data on the page. What I'd like to do is direct focus to a certain field as soon as it appears, which may not be during the initial render of the page.
The ICEFaces documentation suggests that I can do this using the focus attribute of the outputBody component. Specifically:
If you setting the initial focus, the focused component must be rendered on first render call, if not then set the focus attribute only when the component gets rendered.
This seems to suggest that I can manipulate the value of the focus attribute at the time that my conditional component gets rendered. However, I don't see any attributes of the inputText component that allow me to change a value at the time the component is rendered.
Am I misreading the documentation? When and where can I alter the value of the focus attribute of outputBody so that my conditionally-rendered field gets the input focus when it appears? Or am I using the wrong tool to solve this problem?
Maybe you can use this
JavascriptContext.applicationFocus(FacesContext.getCurrentInstance(), "form:fieldM");
You can use some Javascript to set focus on an element.
Here's the Java snippet required to do this:
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(),
"document.getElementById('myForm:myTxtBox').focus();");
myTxtBox is the ID of your form element, and myForm is the ID of your form.
You can use this wherever you are changing certain variables' values to render/hide fields.
Due to the fact that I'm using both Seam and ICEFaces, I was not able to invoke Javascript reliably from my server-side Java code. I was, however, able to add the necessary Javascript in-line in my XHTML, within the ui:component that was being conditionally rendered, close to the input field I needed the focus to go to. The relevant section of my XHTML looks like this:
<ice:panelGroup id="textPanelInput" >
<ice:form id="textInputForm" partialSubmit="true" style="vertical-align:middle;">
<ice:inputText id="textInput" valueChangeListener="#{appField.valueChangeListener}"
size="#{appField.fieldDefLengthAsInt}"
value="#{appField.value}"
styleClass="fieldStyle" rendered="#{appField!=null}"
>
</ice:inputText>
<ice:message id="jo" for="textInput" />
</ice:form>
</ice:panelGroup>
<script type="text/javascript">document.getElementById('panelsFields:0:textInputForm:textInput').focus();</script>
The Javascript line at the bottom is the line I added to solve my problem. All of the code above is in a ui:component block that may or may not be rendered, based on other conditions. When this ui:component block is rendered, my Javascript goes with it, and sets the input focus to my desired input field.
ICEfaces supports javascript api which has setting focus function. Thus you may use it like in the next excerpt:
<script type="text/javascript">
jQuery(document).ready(function () {
ice.applyFocus(elementId);
});
</script>
elementId is jsf component clientId.
ICEFaces javascript Api

How to pass disabled textbox value in Rails?

How may i pass disabled textbox value on controller side ?
Right now i am getting nil value for the disabled textbox.
This is an http thing, if you disable a form element it does not get sent over the wire. You can either set the readonly='true' attribute with javascript and style it to appear disabled, or use javascript to copy the value to a hidden field. unfortunately, you there is no way to just tell it to send.

Resources