Cache / Avoid request to database for each page request

Forum rules
Please note that response time for technical support is within 3-5 business days.
vished
Posts: 479
Joined: 02 Feb 2014, 17:38

22 Apr 2020, 09:26

Hi,

I like this template really much, but currently I have the problem the page load it not really fast due to the following reasons:

Left menu:
- I have on the left side in the calendar e.g. p:repeat to load the last 20 meetings from my database

Topbar:
- Load notifications
- Load messages
- Load image from loggedin user

This means, it´s for each page request also everytime a request against to the database, which slow down the whole application.

Can you give me a few ideas, how I can improve this to avoid to have always a request against the database?
- E.g. caching?
- 20 Meetings (left menu) will be loaded (request to database) only if the user open the second icon (calendar) ? -> how is this possible? I think this can be managed with the new event in the menu?

Image

Any ideas?
PF 8.0

vished
Posts: 479
Joined: 02 Feb 2014, 17:38

06 Oct 2020, 12:17

any update regarding this?
PF 8.0

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

10 Oct 2020, 03:14

Hi,

So sorry for the delayed response!
I think this can be managed with the new event in the menu?
- Yes, a new event can be added for this issue. We can implement this with you next week ??

Best Regards,

vished
Posts: 479
Joined: 02 Feb 2014, 17:38

23 Mar 2021, 16:24

Did you implemented this?
PF 8.0

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

03 May 2021, 15:14

Hi,

Sorry for the delayed response. Yes, I added tabChange and tabContentLoad events for this. You can use tabContentLoad event to load dynamic content.

Code: Select all

<h:form>
      <pm:tabMenu id="tabMenu">
            <p:ajax event="tabContentLoad" listener="#{testView.loadContent}" update="tab1:tab1_menu" />
            <pm:tab id="tab1" icon="pi pi-folder-open" title="FEATURES">
                    <pm:menu id="tab1_menu" model="#{tabView.model}" widgetVar="MorpheusMenuWidget">
             </pm:tab>
      </pm:tabMenu>
</h:form>
...

public void loadContent(TabContentLoadEvent e) {
      Tab tab = e.getTab();
      if (tab.getTabIndex() == 0) {
           // add items to model
      }
}
Best Regards,

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

06 May 2021, 10:07

That´s great... Mabe it will fix my issue with p:cache...

Can you give an example how the backend bean should be looing like to create the model like:

Code: Select all

<pm:menu id="tab1_menu" model="#{tabView.model}" 
What is "model" ?
Primefaces 12.0, WildFly 21

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

06 May 2021, 10:18

Thanks a lot for your update! You can examine "Programmatic" section;
https://www.primefaces.org/showcase/ui/menu/menu.xhtml Or https://www.primefaces.org/showcase-v8/ ... menu.xhtml

Best Regards,

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

06 May 2021, 11:09

I´ve tried that:

Code: Select all

import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.morpheus.component.Menu;

@ViewScoped
@Named
public class LeftMenuController implements Serializable {

	private static final long serialVersionUID = 2815796004558360299L;
	private final Logger LOGGER = LoggerFactory.getLogger(LeftMenuController.class);

	private Menu model = new Menu();

	@PostConstruct
	public void init() {

		DefaultMenuItem item = DefaultMenuItem.builder()
				.value("External")
				.url("http://www.primefaces.org")
				.icon("pi pi-home")
				.build();

		model.getElements().add(item);

	}

Code: Select all

	<pm:tab  icon="fa fa fa-tachometer"
				title="TEST">
					<pm:menu model="#{leftMenuController.model}" />
			</pm:tab>
But it´s not working....

I short example would be great...

Also can I ?
a) Create the whole <pm:tabMenu based on backend bean? ( I will create pm:tab <pm:menu / p:submenu / p:menuitem from backend?
b) create only the menu items in a <pm:tab?
Primefaces 12.0, WildFly 21

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

06 May 2021, 11:49

Ok, I´ve created the menu, this works...

Code: Select all

	private MenuModel model = new DefaultMenuModel();

	@PostConstruct
	public void init() {

		DefaultMenuItem item = DefaultMenuItem.builder()
				.value("External")
				.url("http://www.primefaces.org")
				.icon("pi pi-home")
				.build();
		model.getElements().add(item);
		
		DefaultSeparator defaultSeparator = new DefaultSeparator();
		defaultSeparator.setStyleClass("layout-submenu-title");
		model.getElements().add(defaultSeparator);

	}
But it seems for: pm:tabMenu I cannot create a
model="#{myController.model}". Is this right?

If yes, would it be possible to add this also?
Primefaces 12.0, WildFly 21

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

07 May 2021, 08:17

Hi,

Yes, right! We'll work on it and get back to you.

Best Regards,

Post Reply

Return to “Morpheus - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests