I am working on a MvvmCross based android app. The app contains (among other things) a large number of ToggleButton(s). The buttons are added in .axml files. Their Checked property and Click event are bound to view-model properties. Since the Checked property of the each ToggleButton should reflect the state of some property on a application server, I don't want their checked state to be changed when the user clicks them, but only when the bound property on the view-model is changed. An example how this "special" toggle button should work: When the user clicks it, the "Checked" property of the button does not change only the ICommand to which the click event is bound to is invoked. The method invoked by the command in turn changes the value of the property on the view-model(if executed successfully). Extending a ToggleButton in WPF or Windows Forms to described functionality is easy but I don't know how to do that in android. Any ideas will appreciated.
Uroš
I found the solution to my problem. It seems it had to do something with the way I set up the bindings for my ToggleButton
MyToggleButton was implemented as:
public sealed class MyToggleButton : ToggleButton, View.IOnClickListener
{
public MyToggleButton(Context context, IAttributeSet attrs)
: base(context, attrs)
{
SetOnClickListener(this);
}
public void OnClick(View v)
{
Checked = !Checked;
}
}
As you can see I just set the Checked property back to previous value when ever the user clicks the button. In the asmx I use the following block to add the button.
<controls.MyToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Checked Value;Click ClickCommand" />
As it turns out the problem with described solution is that the OnClick(View v) method is not executed when the user clicks the button as long as the .axms file contains binding to Click event. I have no idea why that is so I would love any explanation. The workaround I used is to define custom event in the derived class, raise the custom event in the OnClick event handler and than bind to that event.
Uros
Related
I want to add a check to the click event of a button, when check failed, I want to cancel the super call, how to do it?
I have tried to use FormControlCancelableSuperEventArgs and FormControlCancelEventArgs in event handler of clicking event, but both of them return null.
Below is my test code.
[FormControlEventHandler(formControlStr(LedgerJournalTable, Approve), FormControlEventType::Clicking)]
public static void Approve_OnClicking(FormControl sender, FormControlEventArgs e)
{
FormControlCancelEventArgs ce1 = e as FormControlCancelEventArgs; // ce1 returns null
FormControlCancelableSuperEventArgs ce2 = e as FormControlCancelableSuperEventArgs; // ce2 returns null too
}
I know I can complete it by throw exception, but I think it is not a official way.
So how can I cancel the super call by a official way?
I don't think it's possible to achieve what you want to. The super() call in the Approve button on the LedgerJournalTable form is doing nothing outside of the frameworks form management such as screen refresh and other tasks that won't affect the logic (because it is a regular button and NOT a menu item button). The button is creating a new menu function in code and calling it explicitly, but is not actually calling the menu item in the super() call.
I would create another approve button in an extension, hide the out-of-the-box button, and in your extension button's OnClicked event copy the logic from the original button, and then modify it in any way that you need, such as skipping the menu function call based on certain logic/conditions that your requirements dictate.
I am maintaining a JSF2 Ajax application and we are heavily using h:commandLinks and f:ajax tags for all actions - always only rerendering what is needed.
This does of course break the expected behaviour for the user when performing a right click on the links and choosing "Open Link in New Tab" etc.
I understand that f:ajax forces the href atribute of the resulting a element to be # and does all the magic post request trickery in the onclick function - I now want to provide fallback support for the "Open Link..." action by putting some meaningful link in the href attribute of the resulting <a> tag.
This would not break the "normal" onclick behaviour as the generated javascript always finishes with return false; but would allow me to send my users to some page using a normal GET request in case they want to open the link in a new window.
Is there a build in way to do this? Or could somebody point me in the right direction on where in the JSF lifecycle I would have to jump in to do this maybe using a phase listener?
Simplest would be to extend com.sun.faces.renderkit.html_basic.CommandLinkRenderer and override the renderAsActive() method accordingly. Mojarra is open source, just copy the method and edit the line where it says writer.write("href", "#", "href"). Replace the "#" string accordingly to your insight.
public class MyCommandLinkRenderer extends CommandLinkRenderer {
#Override
protected void renderAsActive(FacesContext context, UIComponent command) throws IOException {
// ...
}
}
To get it to run, register it as follows in faces-config.xml:
<render-kit>
<renderer>
<component-family>javax.faces.Command</component-family>
<renderer-type>javax.faces.Link</renderer-type>
<renderer-class>com.example.MyCommandLinkRenderer</renderer-class>
</renderer>
</render-kit>
Note that this tight couples your renderer to Mojarra. To be JSF implementation independent, you'd need to create a whole new renderer instead of extending a Mojarra specific renderer class.
Unrelated to the concrete problem, consider reading When should I use h:outputLink instead of h:commandLink?
I'm working with Silverlight, how can I force all my textboxes to trim all leading and trailing whitespaces from their Text property in one place, say App.xaml or something else?
I don't want to be setting an event handler for the GotFocus event every time I use a TextBox.
And I want to keep the ability to fully use xaml, for instance, If I create a new control that inherits from TextBox, then I'll loose the xaml ability to set things declaratively.
It could be with behaviors, a global setter, or whatever action that allows me to keep using xaml and affect all textboxes.
You could create a behavior, but if I were you, I would create a new control that inherits from TextBox. You will not "lose xaml ability".
public class DerrivedTextBox : TextBox
{
public DerrivedTextBox() : base()
{
this.TextChanged += DerrivedTextBox_TextChanged;
}
void DerrivedTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
//TODO: Edit text here
}
}
I am working on a JSF application.
I have recently faced a problem, that how to hide any attribute at the start-up of the application.
For Example -
I have a h:panelGrid attribute for displaying table, but I want to show this table only when a checkbox is clicked, Here I am able to made it working for show/hide but only from second time onwards.
What I want is to hide this table using h:panelGrid when application loads this view, the later part as I told I have achieved.
It would be grateful if somebody cite it for general hide at start-up.
Thanks.
Create a boolean attribute in the ManagedBean which this page uses and set it to false (for example in PostConstruct method). Then use it as a rendered attribute of your <h:panelGrid> and it's going to be defaultly hidden.
let's say
#ManagedBean
#RequestScoped
public class Bean {
private boolean visible = false;
//setters and getters
}
//later on page
<h:panelGrid rendered="#{bean.visible} />
I got it...somehow like this
in panelGrid set style="visibility:hidden"
and in checkBox, call javascript function and in there set
if (show)
{
obj.style.display = "block";
obj.style.visibility="visible";
}
else
{
obj.style.display = "none";
}
It does the trick.
Thanks Petr for help.
I'm new to Blackberry Development and i have to implement a search functionality. It is supposed to be like when i input something in the search field and press the search button it should pass that string to a url as a parameter. Can anyone put me in right direction so as i can understand how to implement it.
If you want the searching to be done on a remote server, and just want the user to be able to enter a search term, then you'll first want a manger with two fields, such as a BasicEditField and a ButtonField. Then you'll want to hook up the button field to submit a request when it is clicked (I assume from your description that is http, but it could be anything). If your button field is stored in a buttonField variable, and your edit field is stored in your editField variable, and you have a method named sendRequest that takes a parameter and sends a request to the url, then you might have:
buttonField.setChangeListener(new FieldChangeListener() {
public void fieldChanged (Field field, int context) {
(new Thread() {
public void run() {
sendRequest(editField.getText());
}
}).start();
}
});
This might look a little complicated, but it breaks down pretty easily:
By calling setChangeListener, we ensure that the fieldChanged method will be called whenever the button is pressed
When fieldChanged is called, we will be in the UI thread. We don't want to lock the UI while we make the request, so you should send the request in a new thread.
getText gets the current text that the user has entered, and passes it to your sendRequest method
The sendRequest method should send the request to the url you mentioned. This will differ depending on how old devices you need to support - BlackBerry introduced a new networking API in 5.0 and expanded on it in 6.0, that simplifies network communications significantly.
I'm assuming you'll be parsing some sort of response that holds the search results. In this case, you'll also want a manager (such as a VerticalFieldManager) to store those results. Then you would add a field for every result that you wanted to show. You'll need to be careful to be holding the UI event lock when doing this, however, since it will probably be executing in a background thread. For example, you might have:
public void addResult(String result) {
synchronized(Application.getEventLock()) {
searchResults.add(new LabelField(result));
}
}
This would just show results in a label field, but you could obviously have more complex fields if you wanted more complicated behavior or more complicated UI.