I need to execute a metod before a <p:contextMenu> is displayed I was looking in the properties of the component and found beforeShow I'm not sure if I don't understand pretty well how this attribute works, but I tried to call the method with this
beforeShow="#{repositController.validate(item)}
and nothing happens when I do right click in the area, but the method is called once in the loading of the page.
The variable item come from the tree selection element. (I´dont know if that matters)
My java method is
public void validate(String cat) {
this.name = cat;
}
PD the the context menu is working right I just have that problem to run a method after display it.
thanks in advance for your time and answers.
Related
I am currently working on a JSF 2.2 application. As per requirements, I have created custom view handler (using ViewHandlerWrapper) for my application. All the methods are just passing to default view handler except renderView which I am overriding as follows -
private viewHandler viewHandlerWrapped = null;
renderView(FacesContext facesContext, UIViewRoot viewToRender) {
String viewId = viewToRender.getViewId();
if (viewId == some condition) {
/* Do calculation to derive viewId */
}
UIViewRoot viewRoot = viewHandlerWrapped.createView(facesContext,viewId+"?faces-redirect=true");
facesContext.setViewRoot(viewRoot);
//now let system render the view
viewHandlerWrapped.renderView(facesContext,viewRoot);
}
The above is working fine and rendering & navigation is happening as expected. The only issue is faces-redirect=true is not working. The URL seems to be always one behind.
I have gone through many answers given in stackoverflow or internet. But nowhere I am able to find how to solve this.
I think I am doing something wrong e.g. ?faces-redirect=true might not be the correct way while creating view. But I am not sure what can be done to correct this.
Can someone please help me out with this?
After struggling with this for more than 4 weeks, I finally found a way to get the correct URL (instead of previous one). I am updating my answer here in case any one else falls into same problem -
"It looks like we can not use the faces-redirect=true the way I was using while creating and rendering the pages. It should be suffixed with form action. So I have changed my code as follows -
1) actions are returned on click of a button e.g.
public string doAction {
----
return "action?faces-redirect=true";
}
2) Code is updated to use implicit navigation wherever possible. With this, I didn't need to build my custom viewhandler as navigation is happening implicitly. So, I have scrapped the viewhandler.
With above two simple steps, the correct URL is being displayed on the browser now.
Can anyone please help me understand how to override OnPaint() for a dialog class derived from CDialog.
Here is the code:
ColorImageDlg *pDlg = NULL;
pDlg = new ColorImageDlg;
pDlg->DoModal();
delete pDlg;
I'm overriding OnInitDialog() and it's getting called.
But while overriding OnPaint() it is not getting called.
Can any one please help me fixing it?
First of all what is the point of creating the instance of the dialog on heap? You can simply do:
ColorImageDlg dlg;
dlg.DoModal();
You need to modify your message map like this:
BEGIN_MESSAGE_MAP(ColorImageDlg, CDialog)
ON_WM_PAINT()
END_MESSAGE_MAP()
Use VS Class Wizard to avoid problems like that.
If you can't use the ClassWizard then there is another way. Here is a resource about it:
(VS2015 version) https://msdn.microsoft.com/en-us/library/dey7ke4c.aspx
(VS2008 version) https://msdn.microsoft.com/en-us/library/dey7ke4c(v=vs.90).aspx)
But basically, once you have defined the dialog resource and attached it to a new class, make sure the Class View tab is selected:
Next, make sure your dialog class is selected in the class view:
Then, click on the Messages icon of the Properties panel:
Scroll down the list of messages and locate WM_PAINT. Then click the dropdown arrow and select the option to add it:
As you can see, it has inserted all the needed code:
Hope this helps.
I want to prevent the user that he will loose his changes in an EditView when changing the view to another.
I use MVP4G in my project and the project is divided as mvp's structure (one package for the template another one for views ..) is there any solution to detect the EditView in the eventBus. or detect the current View shown to user
Thanks in advance
Thanks to the Navigation Event feature in mvp4g, the presenter will get control before the view changes. At this point the presenter can decide if the navigation will be done or not. This is the correct place in a mvp4g application to save your data.
First zu have to mark all events in the eventbus that will change your view with:
#Event(..., navigationEvent = true)
void goToPage1();
Next your presenters have to implement the NavigationConfirmationInterface and the requires confirm-method:
public class Presenter extends ... implements NavigationConfirmationInterface {
public void confirm(NavigationEventCommand event) {
//pseudo method to verify if the view has changed
if (isViewModified(){
//Window shouldn't be used inside a presenter
//this is just to give a simple example
if (Window.confirm("Are you sure you want to leave?")){
event.fireEvent();
}
} else {
event.fireEvent();
}
}
}
And the last thing to do, is to set the presenter of the current view to the confirmation presenter by calling:
event.fireEvent(false);
This is usually done when the presenter gets control.
You will find the documentation here:
https://github.com/FrankHossfeld/mvp4g/wiki/03.-Defining-EventBus#navigation-event
Thanks to MVP4G's team including El Hoss who gives me a hint to check the MVP4G's blog.. I've solved my problem by following this example
http://mvp4g.blogspot.com/2011/06/navigation-control.html
I am trying to develope a component for my company wich should have an integrated dialog. Creating the component was easy until i hit the point with the Dialog. I want to use the com.ibm.xsp.extlib.component.dialog.UIDialog for my component because it has some nice features wich i want to use so creating my own dialog with a ClientSideDojo is not an option.
Normaly when adding a component to another i use component.getChildren().add(MyNewComp),but when i try this Code:
public class myComponentWithADialog extends UIComponentBase implements FacesComponent {
//...other Code...
public void buildContents(FacesContext context, FacesComponentBuilder builder)
throws FacesException {
UIDialog dialog = new UIDialog();
TypedUtil.getChildren(container).add(dialog);
dialog.setStyleClass("dlgUserPref");
dialog.setTitle("titelxyz");
dialog.setId("TagDialog");
UIPanelEx panel = new UIPanelEx();
panel.setTagName("div");
panel.setStyle("border:2px solid red;");
panel.setStyleClass("lotusList lotusTags lotusRelatedTags");
dialog.getChildren().add(panel);
this.getChildren.add(dialog);
}
//....
}
My Panel does not display inside the dialog when calling XSP.openDialog('dialogClientId') in my browser the dialog is shown but empty.
I already tried several other methods like dialog.getPopupContent.getChildren().add() but then i get the error: javax.faces.component.UIPanel incompatible with com.ibm.xsp.extlib.component.dialog.UIDialog$PopupContent.
Also i tried to find a solution on google but i only found a entry at openNTF from someone with the same problem but also without any solution.
Note: I also tried to 'inject' some content to a standard <xe:dialog> and to a <px:panel> inside the <xe:dialog> via a button with SSJS like keithstric does in his blog. Code:
var dialog:com.ibm.xsp.extlib.component.dialog.UIDialog =
getComponent('extlibdialog');
if(dialog.getChildren().size() > 0) {
dialog.getChildren().clear();
}
var TextField:com.ibm.xsp.component.xp.XspOutputText = new com.ibm.xsp.component.xp.XspOutputText();
TextField.setTitle("test");
TextField.setId("testTextField");
TextField.setValue("<p>This is the new Content</p>");
dialog.getChildren().add(TextField);
This code works fine for a standard <xp:panel> outside a dialog but not on the dialog itself or a panel inside it.
The dialogue is not pre - rendered when the page is loaded, but when you actually call for it in XSP.openDialog(...)
So you need to get your code run in that event (mobile now, can't check if it is exposed).
Plan B: do use a Dojo dialogue that is backed by a rest control, so you can transport whatever data you need back and forth.
A word of caution: popup dialogs are a UI concept transplanted from desktop apps. They are alien to Web apps and mostly not working in mobile. Consider and Inline form instead (or a wizard)
I changed my static menu file (header.xhtml) with a mega menu with a model.
Like this:
<p:megaMenu model="#{menuController.megaModel}" autoDisplay="false" styleClass="menu-bar" >
</p:megaMenu>
So far so good, its working great and building just like I expected.
The problem is, on my form pages, when validation fails for the secound time...
I get this error:
javax.faces.FacesException: Cannot remove the same component twice: j_idt15:j_id2 com.sun.faces.context.StateContext$AddRemoveListener.handleAddRemoveWithAutoPrune(StateContext.java:493)
com.sun.faces.context.StateContext$AddRemoveListener.handleRemove(StateContext.java:372)
Looking at the generated HTML I cant find this String "j_idt15:j_id2", but I can find:
<div id="j_idt14:j_idt15" class="ui-menu ui-menubar ui-megamenu ui-widget ui-widget-content ui-corner-all ui-helper-clearfix menu-bar" role="menubar">
and this:
So... I really don´t understand. My MenuController is a sessionBean:
#Component
#Scope("session")
public class MenuController implements Serializable {
#PostConstruct
public void init(){
todosModulos = moduloService.findAll();
modulosAcesso = extrairModulos();
createMegaMenu();
}
...So.. some notes:
I figured out that this error occurs on versions of Mojarra above 2.1.9.
(I am using 2.1.10). So one possible solution is changing the JSF imp to My Faces.
I Tried that, but it buged my structure (my composite components stoped working and dynaForm also).
I tried some workarounds but no sucess. This is what I tried:
Overriding AbstractMenu and Marlon Patrick's solution (PT-BR).
Simply doesn´t work =[
EDIT -> Creating the MenuItem
MenuItem anItem = new MenuItem();
anItem.setOutcome(item.getOutcome());
anItem.setValue(item.getRotulo());
anItem.setIcon(item.getIcone());
From what I saw you already tried my two workarounds: overwrite AbstractMenu and put PhaseListener.
Well, what I realize is that the component that was the problem I had MenuBar and what you are trying to use is the MegaMenu, perhaps the solutions that I do not work for MegaMenu, although I believe that should work yes.
What I would say to you is to check the following:
1 - When you override the class AbstractMenu you are sure the PrimeFaces started to use it? To make sure it puts a break point there and if he sees to the execution flow. If you do not stop, because PrimeFaces is still using its own class.
2 - When attempting to use the solution with PhaseListener, which I prefer and use today, you noted that you need to replace a piece of code with your own code? Basically you'll have to remove only the actions of menu items that are links, because they are causing this problem. The menu items are actions that should remain. In my case, I knew what actions were or links by ID, then you will have to differentiate somehow believe that by also id. Also, put a break point to make sure that your PhaseListener was duly registered and that is intercepting the flow of execution.