Announcement Announcement Module
No announcement yet.
Checkbox problem + if and else? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checkbox problem + if and else?

    Hello guys,

    two questions:

    when I create a checkbox in a view:

    <p><g:checkBox name="cb_prob" checked="false"
    <g:message code="page2.prob" />

    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" />

    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)

    and the second question:

    I have a view with an checkbox. Then I want the following:

    When the checkbox is checked, and i click on the submit button, on 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 when I take a look at the grails page:

    Hope someone can help me.
    Thank you.

  • #2

    1. Try this:
    <g:checkBox name="cb_prob" checked="${mineInstance?.cb_prob}"/>
    <g:message code="page2.prob" />

    2. Try:
    <g:if test="${mineInstance?.cb_prob}">Show it</g:if>
    <g:else>don't show it</g:else>