DelegateCommand<object> is not beeing invoked - winrt-xaml

I am using Template10.
I am utilizing a ListView.
The ViewModel needs to know the SelectedItems.
The SelectedItems should be passed as a parameter with a converter.
EventTriggerBehavior EventName="SelectionChanged" is tested working.
The converter is tested working.
DelegateCommand> SelectionChangedCommand is NOT working.
DelegateCommand of anything is NOT working (no string, no int - no nothing).
DelegateCommand SelectionChangedCommand is tested working.
Only DelegateCommands without parameter are working when
ListView -> EventTriggerBehavior -> InvokeCommandAction
Any ideas?

I think I found the solution.
I changed the converter, so that it is returning a List<string> instead of IList<object>. It Looks like that the DelegateCommand<T> in the ViewModel did not match the <T> coming from the the converter/ListView although ListView.SelectedItems is IList<object>. Furthermore I changed the concept, now the Delete Buttons gets the list of selected items which saves some Code, Events and doubled lists.

Related

faces-redirect=true not working while creating and rendering view

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.

Primefaces autocomplete enter key behavior

when we type into autoComplete, primefaces automatically highlighted first shown item. so when we press enter key that item will be selected. how can i change the behavior of enter key, so when it pressed, just entered text be submitted in backing bean property.
I know we can hit ESC button then continue but but user don't like it.
I am using primefaces 5.0 & jsf 2.1.11
What helped me to solve the same issue where the answers here and here. Basically, you have to override 2 different behaviours.
First one is the default selection of the first result, that can be achieved adding this to your autocomplete (as stated by the accepted answer in the first link, available in primefaces for versions 5.1.5, 5.0.14 and 5.2):
autoHighlight="false"
The second thing you want to override is the behaviour when Enter is pressed, as you want the form that contains the autocomplete to be submitted. For doing so, just add this code to either the containing form or the autocomplete:
onkeyup="if (event.keyCode == 13) {
document.getElementById('[searchFormId]:[submitButtonId]').click();
return false; }"
Change the ids between square brackets for your own ones and it's done.
PS: I know this is a rather old question but it still applies to the current version of primefaces (6.1 when this question was answered). And I also think it can help to have both changes combined in one answer.
Truth be told, this feels like a bug. Richfaces do that implicitly (submit on enter while suggesting). I haven't found an official fix so I did some research and turns out the simplest way is to override the JS function that resolves key presses. The whole autocomplete js is here. You just need to override the bindKeyEvents function so you declare it likewise:
PrimeFaces.widget.AutoComplete.prototype.bindKeyEvents = function () {
Then add the rest of the code for this specific function from the JS I mentioned before. I've omitted that code so it's more readable. Then you want to find a switch that resolves different keys that have some behavior mapped to them. And under the code:
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
Add something like:
if (highlightedItem.length == 0) {
document.getElementById("<your_form_id>").click();
_self.hide();
} else {
highlightedItem.click();
}
Also, make sure that you got forceSelection and the autohighlight off on the autocomplete component.
The problem in the JS is that even though you haven't selected any item from the suggestions it still triggers the event that tries to click the item... which doesn't even exist.
This is the simplest way as I said... you can also create your own autocomplete implementation and override the behavior there. But that's a lot of work and if you only need this one feature I suggest overriding the JS function.
In order to override the original JS with your custom one you need to make sure yours is loaded after the original one. To do that you can either use h:outputScript or simply just load the javascript like you're used to... but in the body (not the head).
Also there's probably a fancier way than having to specify the form id. But I just wasted too much time searching for a solution that I had to get it done real fast.

How to make JavaFX TableView cells editable?

There are a lot of tutorials, And a lot of suggestions to achieve this by extending JavaFX cells to make them editable. A good one is this stackoverflow question.
But the official tutorials uses a method call to create the callback without writing all that code, By calling
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
However when I do this in my code (FormTokens is my "model"):
// At beginning of class declaration
#FXML private TableColumn<FormTokens, String> valuColumn;
// Later at initialization
valuColumn.setCellFactory(TextFieldTableCell.forTableColumn());
Compiler says:
The method
setCellFactory(
Callback<TableColumn<FormTokens,String>,TableCell<FormTokens,String>>)
in the type TableColumn<FormTokens,String>
is not applicable for the arguments
(Callback<TableColumn<Object,String>,TableCell<Object,String>>)
If I remove the method call mentioned above everything works well except that TableView cells are not editable. What am I doing wrong?
edit: I just found this: Javafx TableView can not be edited But there are no solutions. How do I cast Callback<TableColumn<Object,... to Callback<TableColumn<FormTokens,...?
Specify the exact type explicitly for generic parameter as
valuColumn.setCellFactory(TextFieldTableCell.<FormTokens>forTableColumn());

MvvmCross indexed property bind not getting changes from view

I have a list on my view model that contains an object and property that I am trying to bind to from the main view.
var field = new UITextField();
Add(field);
this.AddBindings(
new Dictionary<object, string>()
{
{ field, "Text Names[0].Value" }
}
);
This will load fine and display the initial value from the view model but won't receive any values back when UITextField.Text is modified. It seems like it is not 2 way. Value is not a notification property but could be made into one if that is what this setup requires.
I also tried the following but that does work at all:
set.Bind(field).To(vm => vm.Names[0].Value);
Using MvvmCross 3.0.9. Xamarin.iOS 6.3.7
I've just tested this using 3.0.9 with a ViewModel which has an ObservableCollection of non-INPC Thing objects and this two way binding seems to work OK for me - both when the ObservableCollection changes and when the UITextField value changes because of user action.
Can you provide any more of your ViewModel nad list object code? (If not, can you reproduce the error in a simple sample?)
Can you provide any error trace you are seeing (in debug|output)? (This may need enabling - see MvvmCross Mvx.Trace usage)
Can you provide any more information on the form that "does work at all" - this might be a clue about what is going wrong.

Primefaces Dynamic Mega Menu - Cannot remove the same component twice

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.

Resources