|
Hi,
when I create a checkbox in a view: <p><g:checkBox name="cb_prob" checked="false" value="${true}"/> <g:message code="page2.prob" /> </p> and then click in the view on de Save button, everything is fine, the box which I checked is set to 'on' in the Oracle Database. But when I want to edit the view, the checkbox is empty, but the textfields are not empty, so they are saved. For example a textfield: <g:textField name="electr_storm" value="${fieldValue(bean: mineInstance, field: 'electr_storm')}" /> that works fine, when you fill this field out and click on save it is in the DB and also appears when I want to edit the view or better the formular. when I try this with the checkbox from above: <p><g:checkBox name="cb_prob" checked="false" "${fieldValue(bean: mineInstance, field: 'cb_prob')}"/> <g:message code="page2.prob" /> </p> Then I have the problem, that the Oracle DB does not recognize that it was checked. So there is no 'on' in the DB. So how can i fix that, the checkbox is checked in the editing file? (remember as default it has to be unchecked) Greetings |
|
Please, sorry for pushing, but can noone help me?
It would be glad to have the solution till saturday :$ :/ |
|
Hi.
What's your environment please? I use grails 2.0.2 and use it like: <g:checkBox name="cb_prob" value="${mineInstance?.cb_prob}" /> I think maybe you forgot the key value? <g:checkBox name="cb_prob" checked="false" <b>value="${fieldValue(bean: mineInstance, field: 'cb_prob')}"/>
Xunitc
|
|
In reply to this post by DrunkeN
I think what you want is something like this
<g:checkBox name="cb_prob" value="${fieldValue(bean: mineInstance, field: 'cb_prob')}"/> Cheers Joel On 5/9/2012 9:20 AM, DrunkeN wrote: > Please, sorry for pushing, but can noone help me? > > It would be glad to have the solution till saturday :$ :/ > > -- > View this message in context: http://grails.1312388.n4.nabble.com/checkbox-problem-tp4617655p4620411.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
After playing with it, the correct usage is
value="${fieldValue(bean: mineInstance, field: 'cb_prob')=='true'}" or value="${mineInstance.cb_prob}" Cheers Joel On 5/9/2012 11:22 AM, Joel Richon wrote: > I think what you want is something like this > > <g:checkBox name="cb_prob" value="${fieldValue(bean: mineInstance, > field: 'cb_prob')}"/> > > Cheers > Joel > > On 5/9/2012 9:20 AM, DrunkeN wrote: >> Please, sorry for pushing, but can noone help me? >> >> It would be glad to have the solution till saturday :$ :/ >> >> -- >> View this message in context: >> http://grails.1312388.n4.nabble.com/checkbox-problem-tp4617655p4620411.html >> Sent from the Grails - user mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by DrunkeN
can you post the controller code which handles the binding and saving of the data? Op 9 mei 2012 17:02 schreef "DrunkeN" <[hidden email]> het volgende:
Please, sorry for pushing, but can noone help me? |
|
In reply to this post by DrunkeN
What doesn't look right to me is that you're hardcoding a...
checked="false" ...while at the same time setting a value value="${true}" Maybe you've got a special-case but that's the first thing that jumps out at me. What's your domain object look like? Is the checkbox representing a property on a domain object? Or is it a checkbox that independent of a particular domain object property? - Gary On May 8, 2012, at 7:34 AM, DrunkeN wrote: > Hi, > > when I create a checkbox in a view: > > <p><g:checkBox name="cb_prob" checked="false" > value="${true}"/> > <g:message code="page2.prob" /> > </p> > > and then click in the view on de Save button, everything is fine, the box > which I checked is set to 'on' in the Oracle Database. But when I want to > edit the view, the checkbox is empty, but the textfields are not empty, so > they are saved. > > For example a textfield: > > <g:textField name="electr_storm" > value="${fieldValue(bean: mineInstance, > field: 'electr_storm')}" /> > > that works fine, when you fill this field out and click on save it is in the > DB and also appears when I want to edit the view or better the formular. > > when I try this with the checkbox from above: > > <p><g:checkBox name="cb_prob" checked="false" > "${fieldValue(bean: mineInstance, > field: 'cb_prob')}"/> > <g:message code="page2.prob" /> > </p> > > Then I have the problem, that the Oracle DB does not recognize that it was > checked. So there is no 'on' in the DB. > > So how can i fix that, the checkbox is checked in the editing file? > (remember as default it has to be unchecked) > > Greetings > > -- > View this message in context: http://grails.1312388.n4.nabble.com/checkbox-problem-tp4617655.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by xunitc
Thank you guys! It is working!!! ;)
but at least two questions: I haven't found this mineInstance?.cb_prob in the Grails tutorial, what does the question mark stand for or what is the difference between mineInstance?.cb_prob and "${fieldValue(bean: mineInstance, field: 'cb_prob')}" And the second question is: I have a view with an checkbox. Then I want the following: When the checkbox is checked, and i click on the forward button, to go to the next page, the view should have an additional form, textfield, ... whatever. If it is not checked, than the additional form should not be on the next page. How can i make that? I thout with <g:if (checkbox checked)>show it</g:if> <g:else>don't show it</g:else> but that does not work, because if else is a weird function in Grails (so it seems to me :D) when I take a look at the grails page: http://grails.org/doc/latest/ref/Tags/if.html Hope someone can help me. Thank you. |
|
Hi.
The second: Is the forward button hit a grails-collection? If that, maybe you will push an object to the view let it has the checked properties, or use <g:if test="${params.checkboxname}">show it</g:if>. The first I think I asked before: http://grails.1312388.n4.nabble.com/Is-there-some-difference-of-the-three-way-to-get-value-in-gsp-td4479883.html#a4480596 Good Luck. :)
Xunitc
|
|
In reply to this post by DrunkeN
On May 10, 2012, at 3:10 AM, DrunkeN wrote: > Thank you guys! It is working!!! ;) > > but at least two questions: > > I haven't found this mineInstance?.cb_prob in the Grails tutorial, what does > the question mark stand for That one I can answer. The ? mark is the "safe navigation" operator in groovy. Read about it here: http://groovy.codehaus.org/Operators Note that the Groovy docs simply indicate that this operator shields you from NPE's when traversing through and object tree just like you'd want. But I've noticed that for domain-class associations in grails, it's use is more of a requirement than an option. If you have a domain instance with a valid association this can still fail... domain.assocation.property ...while this will succeed for the *exact* same instance... domain?.association.property My guess is that the safe-navigation operator triggers some lazy loading or something. Would love it if someone can clarify. For my part, I always use the safe-navigation operator when traversing domain-object associations. - Gary --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by DrunkeN
On May 10, 2012, at 3:10 AM, DrunkeN wrote: > When the checkbox is checked, and i click on the forward button, to go to > the next page, the view should have an additional form, textfield, ... > whatever. If it is not checked, than the additional form should not be on > the next page. > > How can i make that? I thout with > <g:if (checkbox checked)>show it</g:if> > <g:else>don't show it</g:else> A couple of things to look at... Make sure that when you construct your "forward" link that you include the params from the current page. That'll make sure that the checkbox value gets passed on to the next page... <a href="${ createLink(action: 'forward', params: params) }">Forward</a> (I use the createLink() form of the createLink tag in the example above because it was a quick copy/paste from my source code. You'll probably want to construct your links with <g:link> instead. But same idea applies, make sure the link is including the params.) The params will flow up to your controller and then back down into the next view. In your next view you should be able to do something as simple as... <g:if test="${params.showIt}"> your HTML for the show-it case </g:if> <g:else> your HTML for the don't show-it case </g:else> (That assumes your checkbox is named "showIt" on your the first page). Note that there is a subtlety here that doesn't apply to your example but that might bite you. When the checkbox is left unchecked on the first page, you get *no* param called showIt in the next form (you probably expect to get a params.showIt = false. You dont. So you can really check to see if the checkbox was unchecked using this technique. If you need to read both check AND unchecked states, be sure to use a <g:checkbox> and understand how it generates a hidden _showIt field that can be used to figure out the unchecked state. That's usually all handled behind the scenes when you data-binding to a domain or command object, but if you're inspecting the params directly (like above) and you need to monitor unchecked-ness, you'll have to do the extra work yourself. For your example you don't need to monitor unchecked-ness so probably no worries. But i figured I'd mention it. - Gary --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Thank you xuntic and Gary! ;)
Damn I always forget the params... Can someone tell me for what the "test" is standing in the if statement? Finaly it works, but when I am on my second page, and i press the <Back> button to get on the first page, the fields and checkboxes are empty again? When I press the forward button to got to page 2 it now looks like this: <g:actionSubmit class="button" action="page2" value="${message(code: 'org.button.forward', default: 'Forward')}" /> my back button from page2.gsp to create.gsp: <g:actionSubmit class="button" action="create" value="${message(code: 'org.button.back', default: 'Back')}" /> But I think actionSubmit saves it automaticly? For sure, I am wrong here?! Regards;) |
|
This post was updated on .
Hi.
If you want the page2 back to page1 and can have the checkedbox value in page1, let the params goback too, and in page1 use it. I see you use g:actionSubmit and I think the action maybe hit the controller, so, please try like this: [page1.gsp]: <g:checkBox name="myCheckbox" value="${params.checked}" /> <g:actionSubmit action="page2" value="Go" /> [PageOneController]: def page2() { redirect(url: '/page2' , params: [checked: params.myCheckbox]) } [page2.gsp]: <g:checkBox name="myCheckbox" value="${params.checked}" /> <g:actionSubmit action="create" value="Back" /> [PageTwoController]: def create() { redirect(url: 'page1' , params: [checked: params.myCheckbox]) } I am not sure if you want the flash-scope, if that, please see the doc here: http://grails.org/doc/latest/ref/Controllers/flash.html Good Luck. :)
Xunitc
|
|
In reply to this post by DrunkeN
On May 11, 2012, at 1:15 AM, DrunkeN wrote: > Thank you xuntic and Gary! ;) > > Damn I always forget the params... Can someone tell me for what the "test" > is standing in the if statement? The test is the expression portion of a "normal" if statement. In other words, this groovy code... if(params.myParam == 'foo') // do something cool Translates to this as a <g:if> tag... <g:if test="${params.myParam == 'foo'}"> <!-- do something cool --> </g:if> > Finaly it works, but when I am on my second page, and i press the <Back> > button to get on the first page, the fields and checkboxes are empty again? > When I press the forward button to got to page 2 it now looks like this: > > > <g:actionSubmit class="button" action="page2" value="${message(code: > 'org.button.forward', default: 'Forward')}" /> > > > my back button from page2.gsp to create.gsp: > > > <g:actionSubmit class="button" action="create" value="${message(code: > 'org.button.back', default: 'Back')}" /> > But I think actionSubmit saves it automaticly? For sure, I am wrong here?! actionSubmit does not automatically "save" anything. It just collects up the form-data and sends it (via params) to the action that's in your controller. What you *do* with it in the controller's action is going to determine if it's saved to the database. To determine the action (in the controller) that's getting called, look at the form's action="" directive. If you're using <g:form> read the docs, I vaguely remember that if you don't declare a form action="" it uses a sensible default. Now, as for browser-button forward/back that's tougher. particularly if you're using form-posts to navigate between pages. My experience is that the forward/back button navigation is inconsistent or difficult to figure out, particularly when navigating from page to page via form posts. I can't help much more other than to say, do some googling about page-navigation, browser-button forward/back functionality, and form submissions. Those issues are not Grails specific, they're just normal complications when developing a webapp. - Gary --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by xunitc
Hy, thanks again to both ;) I will read it Gary.
xunitc, are you sure, that this should work? Because I tried it and when I press (in your case) the "Go" Button on my first page the second page won't load. It's loading and loading and the green bar on the bottom of STS goes from 1 to 100 % but it does not load the 2nd page? The only thing i did is this: def page2 = { redirect(action: "page2" , params: [checked: params.cb_storm]) } of course I cannot make url: "/page2" because I have it in the same controller and then he would not find the page. But why it is loading so long? And after the loading time nothing happens? |
|
Hi.
I think you can not redirect to an action in the action self. It will call the action time and time again. Let me make an assumption, you have one controller and two actions and two pages. You want click button in page1 let it goto page2, then click button in page2 let it goto page1. In these, keep the checkbox's state. Is it? In this you only need a key-value in render-model. class PageController { def page1() { render(view: 'page1', model: [checked: params.myCheckbox]); } def page2() { render(view: 'page2', model: [checked: params.myCheckbox]); } } [page1] <g:form> <g:checkBox name="myCheckbox" value="${checked}" /> <g:actionSubmit action="page2" value="Go" /> </g:form> [page2] <g:form> <g:checkBox name="myCheckbox" value="${checked}" /> <g:actionSubmit action="page1" value="Back" /> </g:form> I am not sure my guess is what you want.
Xunitc
|
|
Yeah, that works. Why I cannot take the action command. Weird.
THANKS! :) But is there no command to save all things, textfield, checkboxes, radio btns? Or do I have to write all checkboxes and textfields into def page1 and def page2? |
|
Hm, or i have another better idea?! But again doesn't work.. (what a wonder)
As said in the first post, I have a Oracle DB, how do you think about that: When I click on the page2 button, the content of the textfields and checkboxes will be stored in the DB, and when I am on page to and click the Back button to get to page1, which is calling a "def load(){} action -> this action loads the content in the textfield. Is this possible or am I talking bullshit? I hope you know what i mean. :/ Regards :) |
| Powered by Nabble | Edit this page |
