You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by BatiB80 <se...@torexretail.de> on 2007/11/09 20:33:28 UTC

Show and hide panel with radio-choice

Hi together,

I have in my page two panels and one choice input. If the user select the
first option, the first panel should be shown, if the user selects the
second option, the second panel should be shown. Does anybody knows how this
could work?

I tried it with:
      choice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
          if (panel1.isVisible()) {
            panel1.setVisible(false);
            panel2.setVisible(true);
          } else {
            panel1.setVisible(true);
            panel2.setVisible(false);
          }
        }
but it isn't working... :-(
-- 
View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13673554
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by BatiB80 <se...@torexretail.de>.
Hi,

sorry, but it's me again. I still do not understand this stuff...
No the switch between the panels is working, but everytime the panel is
changed, all the already entered form-values are lost. Here is a snipplet
out of the source:

private final class RegisterForm extends Form {
    private final ValueMap properties = new ValueMap();
    private RequiredTextField username = null;
    private PasswordTextField password = null;
    private RadioChoice registrationType = null;
    private final RegisterUserSinglePersonPanel singlePersonPanel;
    private final RegisterUserCompanyPanel companyPanel;

public RegisterForm(final String id) {
      super(id);
      AttributeModifier highlightAttributeModifier =
          new AttributeModifier("class", true, new AbstractReadOnlyModel() {
              public Object getObject(Component component) {
                  if (component.hasErrorMessage())
                      return "inputNormalMissing";
                  return null;
              }
          });

      username = new RequiredTextField("username", new
PropertyModel(properties, "username"));
      username.add(StringValidator.minimumLength(5));
      username.add(highlightAttributeModifier);

      password = new PasswordTextField("password", new
PropertyModel(properties, "password"));
      password.add(StringValidator.minimumLength(5));
      password.add(highlightAttributeModifier);

      registrationType = new RadioChoice("registrationType", new
PropertyModel(properties, "registrationType"), TYPES).setSuffix("");

      singlePersonPanel = new
RegisterUserSinglePersonPanel("registerSinglePersonPanel");
      singlePersonPanel.setVisible(true);

      companyPanel = new RegisterUserCompanyPanel("registerCompanyPanel");
      companyPanel.setVisible(false);

      registrationType.add(new AjaxFormComponentUpdatingBehavior("onchange")
{
        protected void onUpdate(AjaxRequestTarget target) {
          singlePersonPanel.setVisible(!singlePersonPanel.isVisible());
          companyPanel.setVisible(!companyPanel.isVisible());
          target.addComponent(singlePersonPanel.getParent());
        }
      });

      add(username);
      add(password);
      add(registrationType);
      add(singlePersonPanel);
      add(companyPanel);
    }
}

Does anybody knows what I'm doing wrong? In case I type some value into
username and afterwards select something in my radio-button, the panels
(singleUser and company) are switched (thats OK) but my value in username is
lost... :-(
-- 
View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13681821
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by Korbinian Bachl <ko...@whiskyworld.de>.
you are not manipulating the AjaxRequestTarger target,
you need to add it to the target:

target.add(panel1);
target.add(panel2);

have look at the wicket-examples/ajax also: 
http://www.wicketstuff.org/wicket13/

Best,

Korbinian

BatiB80 schrieb:
> Hi together,
> 
> I have in my page two panels and one choice input. If the user select the
> first option, the first panel should be shown, if the user selects the
> second option, the second panel should be shown. Does anybody knows how this
> could work?
> 
> I tried it with:
>       choice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
>         protected void onUpdate(AjaxRequestTarget target) {
>           if (panel1.isVisible()) {
>             panel1.setVisible(false);
>             panel2.setVisible(true);
>           } else {
>             panel1.setVisible(true);
>             panel2.setVisible(false);
>           }
>         }
> but it isn't working... :-(

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by BatiB80 <se...@torexretail.de>.
What do you mean?

I tried: 
          target.addComponent(singlePerson);
          target.addComponent(company);
But it is'nt working....

-- 
View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13674510
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by Martijn Dashorst <ma...@gmail.com>.
And search the list and the wiki for "Ajax visibility change".

Martijn

On 11/9/07, Gwyn Evans <gw...@gmail.com> wrote:
> If an Ajax call, in which case target will be non-null, you'll need to
> add the changed components (or an enclosing component) to it!
>
> /Gwyn
>
> On 09/11/2007, BatiB80 <se...@torexretail.de> wrote:
> >
> > one additional information:
> >
> > when I change the choice nothing happens. But it seems, that internally the
> > state of the component is beeing changed, when I reload the page the panels
> > will be swapped. So it seems, that there must be some "re-render" request???
> >
> > Does anybody has an idea?
> > --
> > View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13674117
> > Sent from the Wicket - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> --
> Download Wicket 1.2.6 now! - http://wicketframework.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta4/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by Gwyn Evans <gw...@gmail.com>.
If an Ajax call, in which case target will be non-null, you'll need to
add the changed components (or an enclosing component) to it!

/Gwyn

On 09/11/2007, BatiB80 <se...@torexretail.de> wrote:
>
> one additional information:
>
> when I change the choice nothing happens. But it seems, that internally the
> state of the component is beeing changed, when I reload the page the panels
> will be swapped. So it seems, that there must be some "re-render" request???
>
> Does anybody has an idea?
> --
> View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13674117
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Download Wicket 1.2.6 now! - http://wicketframework.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by BatiB80 <se...@torexretail.de>.
one additional information:

when I change the choice nothing happens. But it seems, that internally the
state of the component is beeing changed, when I reload the page the panels
will be swapped. So it seems, that there must be some "re-render" request???

Does anybody has an idea?
-- 
View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13674117
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by Igor Vaynberg <ig...@gmail.com>.
use a div instead, span cannot contain any block elements...

-igor


On Nov 10, 2007 12:09 PM, Gwyn Evans <gw...@gmail.com> wrote:
> Sure - what you need to do is have an enclosing <span> tag, and use
> that as the target, so at the moment you have
>
> Page
>  +-> Form
>       +-> Username
>       +-> Panel1
>       +-> Panel2
>
> Instead, you need to have
> Page
>  +-> Form
>       +-> Username
>            +-> Span
>                 +-> Panel1
>                 +-> Panel2
> with the <span> being a WebMarkupContainer.
>
> Then you add the panels to the span, rather than the form, and use the
> span as the target to refresh, but this way the form doesn't get
> refreshed, which is why you lost the 'username' value.
>
> /Gwyn
>
> On 10/11/2007, BatiB80 <se...@torexretail.de> wrote:
> >
>
> > Hmm.... - I think this method is new in version 1.3, but I use version 1.2.
> > And I think it's not included there...
> >
> > Do you know how to solve the problem with this version?
> >
> > Thanks!
> > --
> > View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13684798
> > Sent from the Wicket - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> --
> Download Wicket 1.2.6 now! - http://wicketframework.org
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by Gwyn Evans <gw...@gmail.com>.
Sure - what you need to do is have an enclosing <span> tag, and use
that as the target, so at the moment you have

Page
 +-> Form
      +-> Username
      +-> Panel1
      +-> Panel2

Instead, you need to have
Page
 +-> Form
      +-> Username
           +-> Span
                +-> Panel1
                +-> Panel2
with the <span> being a WebMarkupContainer.

Then you add the panels to the span, rather than the form, and use the
span as the target to refresh, but this way the form doesn't get
refreshed, which is why you lost the 'username' value.

/Gwyn

On 10/11/2007, BatiB80 <se...@torexretail.de> wrote:
>
> Hmm.... - I think this method is new in version 1.3, but I use version 1.2.
> And I think it's not included there...
>
> Do you know how to solve the problem with this version?
>
> Thanks!
> --
> View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13684798
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Download Wicket 1.2.6 now! - http://wicketframework.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by BatiB80 <se...@torexretail.de>.
Hmm.... - I think this method is new in version 1.3, but I use version 1.2.
And I think it's not included there...

Do you know how to solve the problem with this version?

Thanks!
-- 
View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13684798
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by Gwyn Evans <gw...@gmail.com>.
Instead of using setOutputMarkupId() for the panels, use
setOutputMarkupPlaceholderTag() - See the javadoc, but this will both
call setOutputMarkupId() and set things so that even not visible,
there's be a placeholder component you can use as the Ajax target.

/Gwyn

On 10/11/2007, BatiB80 <se...@torexretail.de> wrote:
>
> One more information:
>
> when I change the source to:
>           target.addComponent(singlePersonPanel);
>           target.addComponent(companyPanel);
> (that means I add the panels instead of the form) I get the following error
> in ajax debug view:
>
> ERROR: Component with id [[registerForm_registerCompanyPanel]] a was not
> found while trying to perform markup update. Make sure you called
> component.setOutputMarkupId(true) on the component whose markup you are
> trying to update.
> ERROR: Component with id [[registerForm_registerSinglePersonPanel]] a was
> not found while trying to perform markup update. Make sure you called
> component.setOutputMarkupId(true) on the component whose markup you are
> trying to update.
>
> Seems to be clear, but I also added:
>      singlePersonPanel.setOutputMarkupId(true);
>      companyPanel.setOutputMarkupId(true);
>
> If I had a look into the sourcecode I can find the component id's:
>
> span wicket:id="registerSinglePersonPanel"
> id="registerForm_registerSinglePersonPanel"
>   wicket:panel
>     ...
>   /wicket:panel
> /span
>
> span wicket:id="registerCompanyPanel" id="registerForm_registerCompanyPanel"
>   wicket:panel>
>     ...
>   /wicket:panel
> /span
>
> any ideas???
>
> --
> View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13682081
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Download Wicket 1.2.6 now! - http://wicketframework.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Show and hide panel with radio-choice

Posted by BatiB80 <se...@torexretail.de>.
One more information:

when I change the source to:
          target.addComponent(singlePersonPanel);
          target.addComponent(companyPanel);
(that means I add the panels instead of the form) I get the following error
in ajax debug view:

ERROR: Component with id [[registerForm_registerCompanyPanel]] a was not
found while trying to perform markup update. Make sure you called
component.setOutputMarkupId(true) on the component whose markup you are
trying to update.
ERROR: Component with id [[registerForm_registerSinglePersonPanel]] a was
not found while trying to perform markup update. Make sure you called
component.setOutputMarkupId(true) on the component whose markup you are
trying to update.

Seems to be clear, but I also added:
     singlePersonPanel.setOutputMarkupId(true);
     companyPanel.setOutputMarkupId(true);

If I had a look into the sourcecode I can find the component id's:

span wicket:id="registerSinglePersonPanel"
id="registerForm_registerSinglePersonPanel"
  wicket:panel
    ...
  /wicket:panel
/span

span wicket:id="registerCompanyPanel" id="registerForm_registerCompanyPanel"
  wicket:panel>
    ...
  /wicket:panel
/span

any ideas???

-- 
View this message in context: http://www.nabble.com/Show-and-hide-panel-with-radio-choice-tf4779601.html#a13682081
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org