You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by extraquoo <ex...@gmail.com> on 2017/07/21 19:46:21 UTC

how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

here i have an AjaxFallbackButton to dynamically add  new models of phone
information
My issue is that I want to hide this button if the models are added three
times ( three phone number panels)

here is my code. 

final PropertyModel<List&lt;ContactPhone>> contactPhoneList = new
PropertyModel<List&lt;ContactPhone>>(mc216.getSection1(),
"newContactPhone");
		
		 final PartialUpdateListView<ContactPhone> phoneListView = new
PartialUpdateListView<ContactPhone>(
				"newContactPhone", contactPhoneList ,ContactPhone.class){

			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<ContactPhone> item) {

				final FormComponent<?>[] allFields = new FormComponent[3];

				allFields[0] = new ReferenceTableDropDownChoice("contactPhone.type", new
Model<Long>(), new Model<String>(), DOCUMENT_CATEGORY);
				allFields[1] = new
FormTextField<String>("contactPhone.Number").setRequired(true).add(new
PhoneValidator());
				allFields[2] = new FormTextField<String>("contactTime");
				item.add(allFields);

				item.add(getPartialRefreshDeleteButton("delete", item));
				item.add(new StyledFeedback("feedback", item));

			
			}
			@Override
			public boolean hideAddButton() {
				if(contactPhoneList.getObject().size()	> 2	)								
				{	
				//TODO : hide the button	
				return true;
				}
				else{
			    return false;
				}
			}
			
		};
			
		newPhone.add(phoneListView.setReuseItems(true));
		
		newPhone.add(phoneListView.getPartialRefreshAddButton("addNewPhone"));
		newPhone.add(phoneListView);
		s1Border.add(newPhone);



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-number-of-Models-is-larger-than-a-specific-integer-tp4678266.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: how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

Posted by extraquoo <ex...@gmail.com>.
Hi ,

Thanks for you reply. I remove my method  hideAddButton()  from
phoneListView 

then I create a new ajaxcallbackbutton method to carry your code like below 

public Button getLimitedPartialRefreshAddButton(String id, final int
limited) {
		return new AjaxFallbackButton(id, null) {

			/** Default serial id */
			private static final long serialVersionUID = 1L;
			
			@Override
			public boolean isVisible() {
				return isEnabledInHierarchy();
			}
			
			@Override protected void onConfigure () { 
				  super.onConfigure(); 

				  setVisible (getList().size() < limited); 
				} 

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

				List<T> targetList = PartialUpdateListView.this.getModelObject();
				targetList.add(createNewItem());

				if (target != null) {
					setResponsePage(getPage());
				}
				
			}
		}.setDefaultFormProcessing(false);
	}

then add this button in the phoneViewList :

newPhone.add(phoneListView.getLimitedPartialRefreshAddButton("addNewPhone",
ADD_MORE_LIMIT_TWO));

the button is not hidden when I add phone panel twice.

any suggestion ?
<http://apache-wicket.1842946.n4.nabble.com/file/n4678274/2017-07-24_10_52_35-Los_Angeles_Department_of_Public_Social_Services_YourBenefitsNow.png> 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-number-of-Models-is-larger-than-a-specific-integer-tp4678266p4678274.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: how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

Posted by extraquoo <ex...@gmail.com>.
 the onConfigure is working fine now . previous code overrides the
onBeforeRender method and I am not aware of that. for the wicket lifecyle ,
onConfigure is executed before onBeforeRender method.

Thank you for your help.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-number-of-Models-is-larger-than-a-specific-integer-tp4678266p4678277.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: how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

Posted by Martin Grigorov <mg...@apache.org>.
You should repaint the button on every add/remove of a phone so that it's
onConfigure() is called

I am not even sure onConfigure() is available in 1.4.1.
You should upgrade to something newer!

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Jul 24, 2017 at 8:44 PM, extraquoo <ex...@gmail.com> wrote:

> by the way, the project uses 1.4.1 wicket version~~~
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-
> number-of-Models-is-larger-than-a-specific-integer-tp4678266p4678275.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: how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

Posted by extraquoo <ex...@gmail.com>.
by the way, the project uses 1.4.1 wicket version~~~

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-number-of-Models-is-larger-than-a-specific-integer-tp4678266p4678275.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: how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

Posted by Martin Grigorov <mg...@apache.org>.
Hi,



On Jul 21, 2017 11:11 PM, "extraquoo" <ex...@gmail.com> wrote:

here i have an AjaxFallbackButton to dynamically add  new models of phone
information
My issue is that I want to hide this button if the models are added three
times ( three phone number panels)

here is my code.

final PropertyModel<List&lt;ContactPhone>> contactPhoneList = new
PropertyModel<List&lt;ContactPhone>>(mc216.getSection1(),
"newContactPhone");

                 final PartialUpdateListView<ContactPhone> phoneListView =
new
PartialUpdateListView<ContactPhone>(
                                "newContactPhone", contactPhoneList
,ContactPhone.class){

                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void populateItem(ListItem<ContactPhone>
item) {

                                final FormComponent<?>[] allFields = new
FormComponent[3];

                                allFields[0] = new
ReferenceTableDropDownChoice("contactPhone.type", new
Model<Long>(), new Model<String>(), DOCUMENT_CATEGORY);
                                allFields[1] = new
FormTextField<String>("contactPhone.Number").setRequired(true).add(new
PhoneValidator());
                                allFields[2] = new FormTextField<String>("
contactTime");
                                item.add(allFields);


item.add(getPartialRefreshDeleteButton("delete",
item));
                                item.add(new StyledFeedback("feedback",
item));


                        }
                        @Override
                        public boolean hideAddButton() {


I'm not sure what this method is but if you replace it with

@Override protected void onConfigure () {
  super.onConfigure();

  setVisible (getList().size() > 2);
}

And if you repaont the listview after adding and removing a phone then I
guess it should work.

                                if(contactPhoneList.getObject().size()  >
2     )
                                {
                                //TODO : hide the button
                                return true;
                                }
                                else{
                            return false;
                                }
                        }

                };

                newPhone.add(phoneListView.setReuseItems(true));

                newPhone.add(phoneListView.getPartialRefreshAddButton("
addNewPhone"));
                newPhone.add(phoneListView);
                s1Border.add(newPhone);



--
View this message in context: http://apache-wicket.1842946.
n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-
number-of-Models-is-larger-than-a-specific-integer-tp4678266.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: how to hide the AjaxFallbackButton when the number of Models is larger than a specific integer

Posted by extraquoo <ex...@gmail.com>.
here is the screenshot of the page
<http://apache-wicket.1842946.n4.nabble.com/file/n4678267/2017-07-21_13_01_45-Los_Angeles_Department_of_Public_Social_Services_YourBenefitsNow.png> 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-hide-the-AjaxFallbackButton-when-the-number-of-Models-is-larger-than-a-specific-integer-tp4678266p4678267.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