You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by zelelbien <ka...@gmail.com> on 2014/02/25 15:16:52 UTC

Radiobutton with one choice that has Textfield

Hi!

I'm trying to make a RadioChoice, with the last choice "other" which has a
TextField to specify that "other".. 
I would like that the TextField will be just displayed in case the
"other"-choice is selected. 

Is that possible? If yes, could someone help me with the code? Here is what
I have now.. (Without the TextField): 

public BookExternalPanel(String id, IModel<BaseBook> model) {
		super(id, model);

    IModel<PackageObj> bookModel = Model.of(model.getObject()
				.getPackage());

bookSort = new RadioChoice<String>("sort", new
PropertyModel<String>(bookModel, "sort"), BOOK_SORTING_CHOICES);

add(packageMounting);

The "BOOK_SORTING_CHOICES" is just a String-List of predifined book sorts. 


Here is the MarkUp:

	<div class="field">
		Package Mounting
		     <div class="value">
			   
		     </div>
        </div>


Thanks for your help!! 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665.html
Sent from the Users forum 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: Radiobutton with one choice that has Textfield

Posted by zelelbien <ka...@gmail.com>.
thx a lot Marvin!! 

no exceptions anymore, but onConfigure() isn't being called.. ---> textfield
is always there!

another thing.. the selected choice will be saved in the database as string,
and if "other" is selected, and something is in that textfield, then i would
like that text (in that textfield) will be saved in the same column in my
database as string INSTEAD of one of the 3 other radiochoices.

Here is the actual code:

PackageRelatedExternalPanel:

public PackageRelatedExternalPanel(String id, IModel<Device> model) {
		super(id, model);
		 setOutputMarkupId(true); 

		final IModel<PackageObj> packageModel = Model.of(model.getObject()
				.getPackage());

...
.......
...

otherTextField = new TextArea<String>("other", new
PropertyModel<String>(packageModel, "mounting") {

			private static final long serialVersionUID = -7666109097677060257L;

			protected void onConfigure() {
				setVisible(MOUNTING_CHOICES.get(2).equals("other")); 
				logger.debug("HEEERE");
		      } 
		    }); 
		    add(otherTextField); 
		    
	    packageMounting = new RadioChoice<String>("mounting", new 
	    		PropertyModel<String>(packageModel, "mounting"), 
	    		MOUNTING_CHOICES); 
	    		    packageMounting.add(new AjaxFormChoiceComponentUpdatingBehavior()
{
	    		    	 					
						private static final long serialVersionUID = 1L;

					protected void onUpdate(AjaxRequestTarget target) { 
	    		        target.add(PackageRelatedExternalPanel.this); 
	    		      } 
	    		    }); 
	    		    add(packageMounting); 

.......
....
.........
}

HTML: 

......
...
.............

                                        <div class="field">
						Package Mounting
						<div class="value">
							
							<input type="text" wicket:id="other" /> 
						</div>
					</div>

.......
....
.........


PackageObj.java code:

.....
..........
..

@Transient
	private String mounting;	(not yet in the database.. thats why @Transient..
no getmethod yet)
............	
....

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664692.html
Sent from the Users forum 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: Radiobutton with one choice that has Textfield

Posted by "Richter, Marvin" <Ma...@jestadigital.com>.
You have to add an input field in your HTML markup

<input type="text" wicket:id="other" />

Marvin Richter

-----Original Message-----
From: zelelbien [mailto:karimbelkhiria@gmail.com] 
Sent: Wednesday, February 26, 2014 3:05 PM
To: users@wicket.apache.org
Subject: Re: Radiobutton with one choice that has Textfield

So.. I'm getting the whole time an exception! 

Here is my code: 

PackageRelatedExternalPanel:

.....

public PackageRelatedExternalPanel(String id, IModel<Device> model) {
		super(id, model);
		 setOutputMarkupId(true); 

final IModel<PackageObj> packageModel = Model.of(model.getObject()
				.getPackage());

otherTextField = new TextArea<String>("other", new PropertyModel<String>(packageModel, "mounting") {

			private static final long serialVersionUID = -7666109097677060257L;

			protected void onConfigure() {
				setVisible(MOUNTING_CHOICES.get(3).equals("other")); 
		      } 
		    }); 
		    add(otherTextField); 
		    
	    packageMounting = new RadioChoice<String>("mounting", new 
	    		PropertyModel<String>(packageModel, "package.mounting"), 
	    		MOUNTING_CHOICES); 
	    		    packageMounting.add(new AjaxFormChoiceComponentUpdatingBehavior()
{
	    		    	 					
						private static final long serialVersionUID = 1L;

					protected void onUpdate(AjaxRequestTarget target) { 
	    		        target.add(PackageRelatedExternalPanel.this); 
	    		      } 
	    		    }); 
	    		    add(packageMounting); 

.... 
} 

HTML of PackageRelatedExternalPanel:

............
.......
        <div class="field">
	     Mounting
             <div class="value">
		  
             </div>
	</div>
.....
..........

PackageObj.java:

....
...
@Transient
	private String mounting;	// because not yet in the database.. works for all
other components like that, even for the old version of mounting (normal radiochoice without the case of this "other" with textfield ....
..


ObjectCommonValues.java:

public static final List<String> MOUNTING_CHOICES = Arrays.asList(new String[] { "unknown", "sell", "hole", "other"});


And here is the Exception:

Unexpected Exception:
Last cause: The component(s) below failed to render. Possible reasons could be that: 1) you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered), 2) if your components were added in a parent container then make sure the markup for the child container includes them in <wicket:extend>.

1. [TextArea [Component id = other]]



Thankyou for your help!! 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664690.html
Sent from the Users forum 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


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


Re: Radiobutton with one choice that has Textfield

Posted by zelelbien <ka...@gmail.com>.
So.. I'm getting the whole time an exception! 

Here is my code: 

PackageRelatedExternalPanel:

.....

public PackageRelatedExternalPanel(String id, IModel<Device> model) {
		super(id, model);
		 setOutputMarkupId(true); 

final IModel<PackageObj> packageModel = Model.of(model.getObject()
				.getPackage());

otherTextField = new TextArea<String>("other", new
PropertyModel<String>(packageModel, "mounting") {

			private static final long serialVersionUID = -7666109097677060257L;

			protected void onConfigure() {
				setVisible(MOUNTING_CHOICES.get(3).equals("other")); 
		      } 
		    }); 
		    add(otherTextField); 
		    
	    packageMounting = new RadioChoice<String>("mounting", new 
	    		PropertyModel<String>(packageModel, "package.mounting"), 
	    		MOUNTING_CHOICES); 
	    		    packageMounting.add(new AjaxFormChoiceComponentUpdatingBehavior()
{
	    		    	 					
						private static final long serialVersionUID = 1L;

					protected void onUpdate(AjaxRequestTarget target) { 
	    		        target.add(PackageRelatedExternalPanel.this); 
	    		      } 
	    		    }); 
	    		    add(packageMounting); 

.... 
} 

HTML of PackageRelatedExternalPanel:

............
.......
        <div class="field">
	     Mounting
             <div class="value">
		  
             </div>
	</div>
.....
..........

PackageObj.java:

....
...
@Transient
	private String mounting;	// because not yet in the database.. works for all
other components like that, even for the old version of mounting (normal
radiochoice without the case of this "other" with textfield
....
..


ObjectCommonValues.java:

public static final List<String> MOUNTING_CHOICES = Arrays.asList(new
String[] { "unknown", "sell", "hole", "other"});


And here is the Exception:

Unexpected Exception:
Last cause: The component(s) below failed to render. Possible reasons could
be that: 1) you have added a component in code but forgot to reference it in
the markup (thus the component will never be rendered), 2) if your
components were added in a parent container then make sure the markup for
the child container includes them in <wicket:extend>.

1. [TextArea [Component id = other]]



Thankyou for your help!! 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664690.html
Sent from the Users forum 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: Radiobutton with one choice that has Textfield

Posted by Sven Meier <sv...@meiers.net>.
BOOK_SORTING_OTHER would be the one choice in BOOK_SORTING_CHOICES, 
which requires input through an additional textField.

Sven

On 02/26/2014 12:27 PM, zelelbien wrote:
> hi Sven,
>
> Thanks a lot for your answer!
>
> Did you mean my "BOOK_SORTING_CHOICES" (where the 4 radiobutton choices as
> strings are) with BOOK_SORTING_OTHER in
> BOOK_SORTING_OTHER.equals(model.getObject().getPackage().getSort() ??
>
> if not, what should be BOOK_SORTING_OTHER? A new list or what?
>
>
> Thanksyou!
> Karim
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664685.html
> Sent from the Users forum 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
>


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


Re: Radiobutton with one choice that has Textfield

Posted by zelelbien <ka...@gmail.com>.
hi Sven,

Thanks a lot for your answer! 

Did you mean my "BOOK_SORTING_CHOICES" (where the 4 radiobutton choices as
strings are) with BOOK_SORTING_OTHER in
BOOK_SORTING_OTHER.equals(model.getObject().getPackage().getSort() ??

if not, what should be BOOK_SORTING_OTHER? A new list or what?


Thanksyou!
Karim

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664685.html
Sent from the Users forum 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: Radiobutton with one choice that has Textfield

Posted by Sven Meier <sv...@meiers.net>.
public BookExternalPanel(String id, final IModel<BaseBook> model) {
    super(id, model);
    setOutputMarkupId(true);

    otherTextField = new TextField<String>("other", new 
PropertyModel<String>(model,
               "package.other") {
      protected void onConfigure() {
setVisible(BOOK_SORTING_OTHER.equals(model.getObject().getPackage().getSort()));
      }
    };
    add(otherTextField);

    bookSort = new RadioChoice<String>("sort", new 
PropertyModel<String>(model, "package.sort"),
BOOK_SORTING_CHOICES);
    bookSort.add(new AjaxFormChoiceUpdatingBehavior() {
      protected void onUpdate(AjaxRequestTarget target) {
        target.add(BookExternalPanel.this);
      }
    });
    add(bookSort);
}

On 02/25/2014 04:43 PM, zelelbien wrote:
> Hi Sven,
>
> thanks for your fast answer! it helps surely!
>
> I just didnt understood you exactly. The containing panel you mean the
> RadioChoice "bookSort" or the TextField or the Panel i'm adding the whole
> fields (in my case "BookExternalPanel") ? And how will it know that the new
> TextField should be just for the radiochoice "other" ? my RadioChoices are
> saved in the List BOOK_SORTING_CHOICES as you can see in my first post.
>
> Could you paste here the code?
>
> Here is what i did till now, when trying to follow your instruction.. is it
> right? im pretty sure it isnt! that's why im asking another time for the
> code.. pretty confused!
>
> bookSort.add(new AjaxFormChoiceComponentUpdatingBehavior() {
> 			
> 			
> 			private static final long serialVersionUID = 5740866285381867529L;
>
> 			@Override
> 			protected void onUpdate(AjaxRequestTarget target) {
> 				target.add(new TextArea<>("sortOther", new PropertyModel<String>(
> 				packageModel, "bookSort")));
> 				
> 			}
> 	});
>
> Thanks for your help!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664671.html
> Sent from the Users forum 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
>


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


Re: Radiobutton with one choice that has Textfield

Posted by zelelbien <ka...@gmail.com>.
Hi Sven,

thanks for your fast answer! it helps surely! 

I just didnt understood you exactly. The containing panel you mean the
RadioChoice "bookSort" or the TextField or the Panel i'm adding the whole
fields (in my case "BookExternalPanel") ? And how will it know that the new
TextField should be just for the radiochoice "other" ? my RadioChoices are
saved in the List BOOK_SORTING_CHOICES as you can see in my first post.

Could you paste here the code?  

Here is what i did till now, when trying to follow your instruction.. is it
right? im pretty sure it isnt! that's why im asking another time for the
code.. pretty confused! 

bookSort.add(new AjaxFormChoiceComponentUpdatingBehavior() {
			
			
			private static final long serialVersionUID = 5740866285381867529L;

			@Override
			protected void onUpdate(AjaxRequestTarget target) {
				target.add(new TextArea<>("sortOther", new PropertyModel<String>(
				packageModel, "bookSort")));
				
			}
	});

Thanks for your help!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665p4664671.html
Sent from the Users forum 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: Radiobutton with one choice that has Textfield

Posted by Sven Meier <sv...@meiers.net>.
Hi,

you just add an AjaxFormChoiceComponentUpdatingBehavior to the 
RadioChoice, in #onUpdate() you add the containing panel to the 
AjaxRequestTarget for update.
Your textField overrides #onConfigure() to set its visibility depending 
on the currently selected choice.

Hope this helps
Sven

On 02/25/2014 03:16 PM, zelelbien wrote:
> Hi!
>
> I'm trying to make a RadioChoice, with the last choice "other" which has a
> TextField to specify that "other"..
> I would like that the TextField will be just displayed in case the
> "other"-choice is selected.
>
> Is that possible? If yes, could someone help me with the code? Here is what
> I have now.. (Without the TextField):
>
> public BookExternalPanel(String id, IModel<BaseBook> model) {
> 		super(id, model);
>
>      IModel<PackageObj> bookModel = Model.of(model.getObject()
> 				.getPackage());
>
> bookSort = new RadioChoice<String>("sort", new
> PropertyModel<String>(bookModel, "sort"), BOOK_SORTING_CHOICES);
>
> add(packageMounting);
>
> The "BOOK_SORTING_CHOICES" is just a String-List of predifined book sorts.
>
>
> Here is the MarkUp:
>
> 	<div class="field">
> 		Package Mounting
> 		     <div class="value">
> 			
> 		     </div>
>          </div>
>
>
> Thanks for your help!!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Radiobutton-with-one-choice-that-has-Textfield-tp4664665.html
> Sent from the Users forum 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
>


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